Authored by 于良

接口签名时去除参数首尾空格 review by yewanwan

... ... @@ -6,6 +6,7 @@ import DeviceInfo from 'react-native-device-info';
import queryString from 'query-string';
import md5 from 'md5';
import timeoutPromise from '../utils/timeoutPromise';
import trimObject from '../utils/trimObject';
import RNNativeConfig from './RNNativeConfig';
export default class Request {
... ... @@ -186,6 +187,9 @@ export default class Request {
...params,
private_key
}
allParams = trimObject(allParams); // 去除首尾空格
let paramsPair = queryString.stringify(allParams)
let client_secret = md5(paramsPair);
... ...
'use strict'
export default function trimObject(obj) {
if (!Array.isArray(obj) && typeof obj != 'object') {
return obj;
}
return Object.keys(obj).reduce(function(acc, key) {
acc[key.trim()] = typeof obj[key] == 'string' ? obj[key].trim() : trimObj(obj[key]);
return acc;
}, Array.isArray(obj) ? [] : {});
}
... ...