20261008
This commit is contained in:
+20
-18
@@ -40,17 +40,17 @@ class OpenSdk {
|
||||
* @return {string} 请求字符串
|
||||
*/
|
||||
generateSignature(params) {
|
||||
if (!AuthorizationType[params.authorization]) {
|
||||
if (params.authorization !== 'OPEN-FORM-PARAM' && !AuthorizationType[params.authorization]) {
|
||||
params.authorization = AuthorizationType['OPEN-BODY-SIG'];
|
||||
}
|
||||
let content = JSON.stringify(params.content);
|
||||
if (params.authorization === AuthorizationType['OPEN-FORM-PARAM']) {
|
||||
if (params.authorization === AuthorizationType['OPEN-FORM-PARAM'] || params.authorization === 'OPEN-FORM-PARAM') {
|
||||
let contentHash = CryptoJS.SHA256(content).toString();
|
||||
let signStr = this.config.appId + params.timestamp + params.nonce + contentHash;
|
||||
let signature = CryptoJS.HmacSHA256(signStr, this.config.appKey);
|
||||
let signatureStr = CryptoJS.enc.Base64.stringify(signature);
|
||||
let signatureEncode = encodeURIComponent(signatureStr);
|
||||
let str = `?authorization=${params.authorization}&appId=${this.config.appId}×tamp=${params.timestamp}&nonce=${params.nonce}&content=${content}&signature=${signatureEncode}`;
|
||||
let str = `?authorization=${params.authorization}&appId=${this.config.appId}×tamp=${params.timestamp}&nonce=${params.nonce}&content=${encodeURIComponent(content)}&signature=${signatureEncode}`;
|
||||
return str;
|
||||
}
|
||||
if (params.authorization === AuthorizationType['OPEN-BODY-SIG']) {
|
||||
@@ -84,21 +84,23 @@ class OpenSdk {
|
||||
}
|
||||
const str = this.generateSignature(params);
|
||||
const config = this.config;
|
||||
if (params.authorization === AuthorizationType['OPEN-FORM-PARAM']) {
|
||||
const Url = params.queryUrl + encodeURIComponent(str);
|
||||
return new Promise((resolve, reject) => {
|
||||
request(Url, (error, _response, body) => {
|
||||
if (!error) {
|
||||
if (typeof (body) === 'object') {
|
||||
resolve(JSON.parse(body));
|
||||
}
|
||||
else {
|
||||
resolve(body);
|
||||
}
|
||||
}
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
// console.log('test', params.authorization === AuthorizationType['OPEN-FORM-PARAM'] || params.authorization === 'OPEN-FORM-PARAM', params.authorization === AuthorizationType['OPEN-FORM-PARAM'] , params.authorization === 'OPEN-FORM-PARAM')
|
||||
if (params.authorization === AuthorizationType['OPEN-FORM-PARAM'] || params.authorization === 'OPEN-FORM-PARAM') {
|
||||
// const Url = params.queryUrl + encodeURIComponent(str);
|
||||
return params.queryUrl + str;
|
||||
// return new Promise((resolve, reject) => {
|
||||
// request(Url, (error, _response, body) => {
|
||||
// if (!error) {
|
||||
// if (typeof (body) === 'object') {
|
||||
// resolve(JSON.parse(body));
|
||||
// }
|
||||
// else {
|
||||
// resolve(body);
|
||||
// }
|
||||
// }
|
||||
// reject(error);
|
||||
// });
|
||||
// });
|
||||
}
|
||||
if (params.authorization === AuthorizationType['OPEN-BODY-SIG']) {
|
||||
const Url = params.queryUrl;
|
||||
|
||||
Reference in New Issue
Block a user