wechat.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  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. getCode2Session:function(){
  30. if(!this.GET['code']) return this.endAPI(-1,'JsCode Can Be Empty');
  31. Wechat.getCode2Session.call(this,this.GET['code'],function(err,body){
  32. if(err) return this.endAPI(-1,'getCode2Session error!');
  33. this.endAPI(0,body);
  34. });
  35. }
  36. }