Authored by QC-L

修改请求时 URL 地址的获取方式 review by 黄敬囿

... ... @@ -38,6 +38,6 @@ export default {
// MINI_APP_DOMAIN: 'miniapp.yohobuy.com',
appid: 'wx084ab813d88c594b',
business_line: 'yohobuy', // 业务线
// mini_app_type: 4,
mini_app_type: '62',
}
}[process.env.NODE_ENV];
... ...
... ... @@ -51,9 +51,11 @@ const handleParam = (params) => {
const publicParams = _publicParams();
let newParams = {
...params,
session_key,
...publicParams,
};
if (session_key) {
newParams.session_key = session_key;
}
return newParams;
}
... ... @@ -61,10 +63,12 @@ const getUdid = (params) => {
const globalData = getGlobalData();
if (params && !params.hasOwnProperty('udid')) {
let udid = globalData.udid ? globalData.udid : "";
if (udid.length == 0) {
if (udid.length === 0) {
udid = getYHStorageSync('udid', 'request');
}
params.udid = udid;
if (udid.length !== 0) {
params.udid = udid;
}
}
}
... ... @@ -73,7 +77,9 @@ const getUid = (params) => {
if (params && !params.hasOwnProperty('uid')) {
// 判断 globalData 是否包含 uid
let uid = globalData.userInfo && globalData.userInfo.uid ? globalData.userInfo.uid : 0;
params.uid = uid;
if (uid !== 0) {
params.uid = uid;
}
}
}
... ... @@ -103,6 +109,7 @@ 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 });
... ... @@ -119,9 +126,10 @@ const handleHeader = (options, newParams) => {
}
let param = _signParam(newParams, false);
let resultString = crypto.HMAC(crypto.SHA256, param, p2SecretKey, "")
const session_key = newParams.session_key ? newParams.session_key : '';
let header = {
'x-yoho-verify': resultString,
'Cookies': 'JSESSIONID=' + newParams.session_key,
'Cookies': 'JSESSIONID=' + session_key,
}
return header;
}
... ...
... ... @@ -9,12 +9,22 @@ export default class BaseService {
}
}
yohoApi() {
this.url = config.domains.yohoApi;
return this;
}
defaultApi() {
this.url = config.domains.api;
return this;
}
async GET(params, options) {
return await GET({
url: this.url,
path: options.path ? options.path: '',
path: options && options.path ? options.path: '',
params: params,
complete: options.complete
complete: options && options.complete ? options.complete: null
}).then(data => {
return data;
}).catch(error => {
... ...