lrf402788946 4 years ago
parent
commit
b14b123469
2 changed files with 3 additions and 1 deletions
  1. 2 1
      app/service/weixin.js
  2. 1 0
      package.json

+ 2 - 1
app/service/weixin.js

@@ -5,6 +5,7 @@ const uuid = require('uuid');
 const random = require('string-random');
 const crypto = require('crypto');
 const _ = require('lodash');
+const moment = require('moment');
 const { BusinessError, ErrorCode } = require('naf-core').Error;
 const jwt = require('jsonwebtoken');
 const { AxiosService } = require('naf-framework-mongoose/lib/service');
@@ -94,7 +95,7 @@ class WeixinAuthService extends AxiosService {
       await this.app.redis.set(this.jsapiKey, jsapi_ticket, 'EX', expiresIn);
     }
     const noncestr = random(16).toLowerCase();
-    const timestamp = new Date().getTime();
+    const timestamp = moment().unix();
     const signStr = `jsapi_ticket=${jsapi_ticket}&noncestr=${noncestr}&timestamp=${timestamp}&url=${url}`;
     console.log(signStr);
     const sign = crypto.createHash('sha1').update(signStr).digest('hex');

+ 1 - 0
package.json

@@ -14,6 +14,7 @@
     "egg-view-nunjucks": "^2.2.0",
     "jsonwebtoken": "^8.5.1",
     "lodash": "^4.17.15",
+    "moment": "^2.29.1",
     "naf-framework-mongoose": "^0.6.11",
     "raml2html": "^6.1.0",
     "silly-datetime": "^0.1.2",