Showing
1 changed file
with
8 additions
and
15 deletions
@@ -6,7 +6,7 @@ | @@ -6,7 +6,7 @@ | ||
6 | 6 | ||
7 | 'use strict'; | 7 | 'use strict'; |
8 | 8 | ||
9 | -const _ = require('lodash'); | 9 | +const qs = require('querystring'); |
10 | const md5 = require('md5'); | 10 | const md5 = require('md5'); |
11 | 11 | ||
12 | const privateKey = { | 12 | const privateKey = { |
@@ -24,7 +24,7 @@ const privateKey = { | @@ -24,7 +24,7 @@ const privateKey = { | ||
24 | * @return {Object} 排序之后的参数对象 | 24 | * @return {Object} 排序之后的参数对象 |
25 | */ | 25 | */ |
26 | const packageSort = argument => { | 26 | const packageSort = argument => { |
27 | - var newObj = {}; | 27 | + let newObj = {}; |
28 | 28 | ||
29 | for (let k of Object.keys(argument).sort()) { | 29 | for (let k of Object.keys(argument).sort()) { |
30 | newObj[k] = argument[k]; | 30 | newObj[k] = argument[k]; |
@@ -39,18 +39,11 @@ const packageSort = argument => { | @@ -39,18 +39,11 @@ const packageSort = argument => { | ||
39 | * @return {string} 生成的签名字符串 | 39 | * @return {string} 生成的签名字符串 |
40 | */ | 40 | */ |
41 | const makeSign = argument => { | 41 | const makeSign = argument => { |
42 | - var qs = []; | ||
43 | - | ||
44 | - _.forEach(argument, function(value, key) { | ||
45 | - qs.push(key + '=' + _.trim(value)); | ||
46 | - }); | ||
47 | - | ||
48 | - return md5(qs.join('&')).toLowerCase(); | 42 | + return md5(qs.stringify(argument)).toLowerCase(); |
49 | }; | 43 | }; |
50 | 44 | ||
51 | // 生成API签名,调用后端接口的时候有私钥校验 | 45 | // 生成API签名,调用后端接口的时候有私钥校验 |
52 | exports.apiSign = (params) => { | 46 | exports.apiSign = (params) => { |
53 | - | ||
54 | /* eslint-disable */ | 47 | /* eslint-disable */ |
55 | var sign = packageSort(Object.assign({ | 48 | var sign = packageSort(Object.assign({ |
56 | client_type: 'h5', | 49 | client_type: 'h5', |
@@ -60,18 +53,18 @@ exports.apiSign = (params) => { | @@ -60,18 +53,18 @@ exports.apiSign = (params) => { | ||
60 | screen_size: '720x1280', | 53 | screen_size: '720x1280', |
61 | v: '7' | 54 | v: '7' |
62 | }, params)); | 55 | }, params)); |
63 | - | ||
64 | /* eslint-enable */ | 56 | /* eslint-enable */ |
65 | 57 | ||
66 | - return Object.assign(sign, { | ||
67 | - | 58 | + sign = Object.assign(sign, { |
68 | client_secret: makeSign(sign) // eslint-disable-line camelcase | 59 | client_secret: makeSign(sign) // eslint-disable-line camelcase |
69 | }); | 60 | }); |
61 | + delete sign.private_key; | ||
62 | + return sign; | ||
70 | }; | 63 | }; |
71 | 64 | ||
72 | // 检查签名,APP 访问 H5 页面的时候需要检查 | 65 | // 检查签名,APP 访问 H5 页面的时候需要检查 |
73 | exports.checkSign = (params) => { | 66 | exports.checkSign = (params) => { |
74 | - var clientSecret = params.client_secret, // eslint-disable-line camelcase | 67 | + let clientSecret = params.client_secret, // eslint-disable-line camelcase |
75 | sortedParams; | 68 | sortedParams; |
76 | 69 | ||
77 | // 忽略部分参数 | 70 | // 忽略部分参数 |
@@ -88,7 +81,7 @@ exports.checkSign = (params) => { | @@ -88,7 +81,7 @@ exports.checkSign = (params) => { | ||
88 | 81 | ||
89 | // 检查签名,APP 访问 H5 页面的时候需要检查, 有可能不同于上边的签名方式 | 82 | // 检查签名,APP 访问 H5 页面的时候需要检查, 有可能不同于上边的签名方式 |
90 | exports.webSign = (params) => { | 83 | exports.webSign = (params) => { |
91 | - var webPrivateKey = 'yohobuyapp'; | 84 | + const webPrivateKey = 'yohobuyapp'; |
92 | 85 | ||
93 | return params.key === md5(md5(webPrivateKey) + params.uid); | 86 | return params.key === md5(md5(webPrivateKey) + params.uid); |
94 | }; | 87 | }; |
-
Please register or login to post a comment