...
|
...
|
@@ -6,7 +6,7 @@ |
|
|
|
|
|
'use strict';
|
|
|
|
|
|
const _ = require('lodash');
|
|
|
const qs = require('querystring');
|
|
|
const md5 = require('md5');
|
|
|
|
|
|
const privateKey = {
|
...
|
...
|
@@ -24,7 +24,7 @@ const privateKey = { |
|
|
* @return {Object} 排序之后的参数对象
|
|
|
*/
|
|
|
const packageSort = argument => {
|
|
|
var newObj = {};
|
|
|
let newObj = {};
|
|
|
|
|
|
for (let k of Object.keys(argument).sort()) {
|
|
|
newObj[k] = argument[k];
|
...
|
...
|
@@ -39,18 +39,11 @@ const packageSort = argument => { |
|
|
* @return {string} 生成的签名字符串
|
|
|
*/
|
|
|
const makeSign = argument => {
|
|
|
var qs = [];
|
|
|
|
|
|
_.forEach(argument, function(value, key) {
|
|
|
qs.push(key + '=' + _.trim(value));
|
|
|
});
|
|
|
|
|
|
return md5(qs.join('&')).toLowerCase();
|
|
|
return md5(qs.stringify(argument)).toLowerCase();
|
|
|
};
|
|
|
|
|
|
// 生成API签名,调用后端接口的时候有私钥校验
|
|
|
exports.apiSign = (params) => {
|
|
|
|
|
|
/* eslint-disable */
|
|
|
var sign = packageSort(Object.assign({
|
|
|
client_type: 'h5',
|
...
|
...
|
@@ -60,18 +53,18 @@ exports.apiSign = (params) => { |
|
|
screen_size: '720x1280',
|
|
|
v: '7'
|
|
|
}, params));
|
|
|
|
|
|
/* eslint-enable */
|
|
|
|
|
|
return Object.assign(sign, {
|
|
|
|
|
|
sign = Object.assign(sign, {
|
|
|
client_secret: makeSign(sign) // eslint-disable-line camelcase
|
|
|
});
|
|
|
delete sign.private_key;
|
|
|
return sign;
|
|
|
};
|
|
|
|
|
|
// 检查签名,APP 访问 H5 页面的时候需要检查
|
|
|
exports.checkSign = (params) => {
|
|
|
var clientSecret = params.client_secret, // eslint-disable-line camelcase
|
|
|
let clientSecret = params.client_secret, // eslint-disable-line camelcase
|
|
|
sortedParams;
|
|
|
|
|
|
// 忽略部分参数
|
...
|
...
|
@@ -88,7 +81,7 @@ exports.checkSign = (params) => { |
|
|
|
|
|
// 检查签名,APP 访问 H5 页面的时候需要检查, 有可能不同于上边的签名方式
|
|
|
exports.webSign = (params) => {
|
|
|
var webPrivateKey = 'yohobuyapp';
|
|
|
const webPrivateKey = 'yohobuyapp';
|
|
|
|
|
|
return params.key === md5(md5(webPrivateKey) + params.uid);
|
|
|
}; |
...
|
...
|
|