Authored by 于良

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

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