Browse Source

optimize router && add Wechat api

HonorLee 5 years ago
parent
commit
85e4a09e84

+ 2 - 1
system/core.js

@@ -149,4 +149,5 @@ CACHE.Handlers = [];
 for(let i in HandlerFiles){
     let path = HandlerFiles[i]['path'];
     CACHE.Handlers.push(path.replace(Core.Path.Handler,''));
-}
+}
+CACHE.HandlersString = CACHE.Handlers.join('|');

+ 1 - 1
system/lib/core/router.js

@@ -44,7 +44,7 @@ var Router ={
             methodMark[handlerFile] = method;
         }
         
-        match = new RegExp(expArr.join('|')).exec(CACHE.Handlers.join('|'));
+        match = new RegExp(expArr.join('|')).exec(CACHE.HandlersString);
         if(!match) return Router._error('No such handler ['+handlerFile+']',res);
         
         method = methodMark[match];

+ 1 - 1
system/lib/extra/wechat/handler/wechat.js

@@ -19,7 +19,7 @@ module.exports = {
         });
     },
     getSignature:function(){
-        if(!this.GET['url'] || !this.GET['url'].match(/(https?|ftp|file):\/\/[-A-Za-z0-9+&@#\/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]/gi)) return this.endAPI(-1,'Please send a current url address');
+        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');
         Wechat.getSignature.call(this,this.GET['url'],function(err,signatureObj){
             if(err) return this.endAPI(-1,'getSignature error!');
             signatureObj.appId = Config.Wechat.appId;

+ 3 - 4
system/lib/extra/wechat/wechat.js

@@ -61,7 +61,6 @@ let Wechat = {
                                 callback.call(_this,new Error('Wechat getJsApiTicket error!'),null);
                                 return;
                             }
-                            console.log(body);
                             if(body.errcode){
                                 callback(_this,errcode,errcode[body.errcode]);
                             }
@@ -92,7 +91,7 @@ let Wechat = {
             }
             let combineStr = `jsapi_ticket=${ticket}&noncestr=${noncestr}&timestamp=${timestamp}&url=${url}`;
             let signature = sha1(combineStr);
-            callback.call(_this,null,{noncestr:noncestr,timestamp:timestamp,signature:signature});
+            callback.call(_this,null,{nonceStr:noncestr,timestamp:timestamp,signature:signature});
         });
     }
 }
@@ -135,7 +134,7 @@ function setTokenToCahe(token,expires){
         })
         return;
     }
-    let expiresTime = Moment().valueOf() + expires;
+    let expiresTime = Math.floor(Moment().valueOf()/1000) + expires;
     FILE.writeFileSync(tmpTokenFile,JSON.stringify({token:token,expires:expiresTime}),'UTF-8');
 }
 
@@ -175,6 +174,6 @@ function setTicketToCahe(ticket,expires){
         })
         return;
     }
-    let expiresTime = Moment().valueOf() + expires;
+    let expiresTime = Math.floor(Moment().valueOf()/1000) + expires;
     FILE.writeFileSync(tmpTicketFile,JSON.stringify({ticket:ticket,expires:expiresTime}),'UTF-8');
 }