...
|
...
|
@@ -2,7 +2,6 @@ import getPrivateKey from './getPrivateKey' |
|
|
import config from '../../config.js'
|
|
|
import trimObject from './utils/trimObject.js'
|
|
|
import queryString from './utils/query-string/query-string.js'
|
|
|
import objectAssign from './utils/query-string/object-assign.js'
|
|
|
const crypto = require('./utils/cryptojs/cryptojs.js');
|
|
|
import MD5 from './utils/md5/md5.js'
|
|
|
|
...
|
...
|
@@ -109,10 +108,9 @@ const _signParam = (params, encode = false) => { |
|
|
const _signResultParams = (params, encode = false) => {
|
|
|
let allParams = trimObject(params); // 去除首尾空格
|
|
|
let paramsPair = queryString.stringify(allParams, { encode: false });
|
|
|
console.log(paramsPair);
|
|
|
let client_secret = MD5(paramsPair);
|
|
|
delete allParams.private_key;
|
|
|
const resultParams = objectAssign(allParams, { client_secret });
|
|
|
const resultParams = Object.assign(allParams, { client_secret });
|
|
|
return resultParams;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -125,7 +123,10 @@ const handleHeader = (options, newParams) => { |
|
|
p2SecretKey = getYHStorageSync("p2SecretKey", 'request')
|
|
|
}
|
|
|
let param = _signParam(newParams, false);
|
|
|
let resultString = crypto.HMAC(crypto.SHA256, param, p2SecretKey, "")
|
|
|
let resultString = ''
|
|
|
if (p2SecretKey) {
|
|
|
resultString = crypto.HMAC(crypto.SHA256, param, p2SecretKey, "")
|
|
|
}
|
|
|
const session_key = newParams.session_key ? newParams.session_key : '';
|
|
|
let header = {
|
|
|
'x-yoho-verify': resultString,
|
...
|
...
|
@@ -158,11 +159,10 @@ const sendRequest = (resolve, reject, options) => { |
|
|
const statusCode = res.statusCode;
|
|
|
const errMsg = res.errMsg;
|
|
|
const data = res.data;
|
|
|
|
|
|
if (statusCode == 200) {
|
|
|
resolve(data);
|
|
|
if (data && data.code == 200 && data.data) {
|
|
|
resolve(data.data);
|
|
|
} else {
|
|
|
const code = statusCode;
|
|
|
const code = res.statusCode;
|
|
|
const message = res.errMsg ? res.errMsg : '';
|
|
|
reject({ code, message });
|
|
|
}
|
...
|
...
|
|