wechat.js 1.1 KB

1234567891011121314151617181920212223242526272829
  1. 'use strict'
  2. module.exports = {
  3. checkSignature:function(){
  4. let signature = this.GET['signature'],
  5. timestamp = this.GET['timestamp'],
  6. nonce = this.GET['nonce'],
  7. echostr = this.GET['echostr'];
  8. if(signature && timestamp && nonce && echostr){
  9. if(Wechat.checkSignature(signature,timestamp,nonce)){
  10. this.end(echostr);
  11. return;
  12. }
  13. }
  14. this.end('Error');
  15. },
  16. getAccessToken:function(){
  17. Wechat.getAccessToken.call(this,function(err,accessToken){
  18. this.end(accessToken);
  19. });
  20. },
  21. getSignature:function(){
  22. if(!this.GET['url'] || !this.GET['url'].match(/(https?):\/\/[-A-Za-z0-9+&@#\/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]/gi)) return this.endAPI(-1,'Please send a current url address');
  23. Wechat.getSignature.call(this,this.GET['url'],function(err,signatureObj){
  24. if(err) return this.endAPI(-1,'getSignature error!');
  25. signatureObj.appId = Config.Wechat.appId;
  26. this.endAPI(0,signatureObj);
  27. });
  28. }
  29. }