签章流程
This commit is contained in:
@@ -24,30 +24,51 @@ pubFun.test = function(path) {
|
||||
}
|
||||
}
|
||||
|
||||
const url = 'http://test.api.fabigbig.com:8888/api/'
|
||||
const url = 'http://test.api.fabigbig.com:8888/api'
|
||||
const app_id = 405942
|
||||
const app_secret = 'ODDW0vm9FvDj2RYQRmoryVnH'
|
||||
|
||||
const getFadadaSign = function(params, timestamp) {
|
||||
const getFadadaSign = function(api, params, timestamp) {
|
||||
const copyParams = {
|
||||
...params
|
||||
}
|
||||
//1. A.将参与摘要计算的业务参数按字典升序排列
|
||||
var sortedParams = Object.keys(params).sort().reduce((acc, curr, index) => {
|
||||
let computeKeys = Object.keys(params)
|
||||
|
||||
var sortedParams = computeKeys.sort().reduce((acc, curr, index) => {
|
||||
acc += params[curr];
|
||||
return acc;
|
||||
}, '');
|
||||
|
||||
// 1.B.将 app_secret 附加到字符串串前
|
||||
const str1 = app_secret + sortedParams
|
||||
let str1 = app_secret + sortedParams
|
||||
console.log('sortedParams: ',sortedParams);
|
||||
if (api == 'generate_contract.api') {
|
||||
str1 = app_secret + params.template_id + params.contract_id
|
||||
} else if (api == 'uploaddocs.api') {
|
||||
str1 = app_secret + params.contract_id
|
||||
} else if (api == 'extsign.api') {
|
||||
str1 = app_secret + params.customer_id
|
||||
}
|
||||
|
||||
|
||||
// 步骤 2.对得到的字符串进⾏SHA1 加密
|
||||
const sha1_1 = CryptoJS.SHA1(str1).toString().toUpperCase()
|
||||
console.log('sha1_1: ', sha1_1);
|
||||
// 步骤 3.计算 timestamp的MD5值,并和app_id,步骤 2 中得到的字符串拼接得到新的字符串
|
||||
const timestampMd5 = CryptoJS.MD5(timestamp).toString().toUpperCase()
|
||||
const str2 = app_id + timestampMd5 + sha1_1
|
||||
let timestampMd5 = ''
|
||||
if (api == 'extsign.api') {
|
||||
timestampMd5 = CryptoJS.MD5(params.transaction_id + timestamp).toString().toUpperCase()
|
||||
} else {
|
||||
timestampMd5 = CryptoJS.MD5(timestamp).toString().toUpperCase()
|
||||
}
|
||||
|
||||
let str2 = app_id + timestampMd5 + sha1_1
|
||||
if (api == 'generate_contract.api') {
|
||||
str2 += params.parameter_map
|
||||
} else if (api == 'extsign.api') {
|
||||
|
||||
}
|
||||
|
||||
// 步骤 4.对步骤3中得到的字符串进行SHA1 加密
|
||||
const str3 = CryptoJS.SHA1(str2).toString().toUpperCase()
|
||||
@@ -71,11 +92,10 @@ pubFun.fadada = async function(api, params) {
|
||||
|
||||
|
||||
const timestamp = vk.pubfn.timeFormat(new Date(), "yyyyMMddhhmmss");
|
||||
|
||||
const msg_digest = getFadadaSign(params, timestamp)
|
||||
const msg_digest = getFadadaSign(api, params, timestamp)
|
||||
|
||||
const res = await vk.request({
|
||||
url: url + api,
|
||||
url: url + '/' + api,
|
||||
method: "POST",
|
||||
header: {
|
||||
"content-type": "application/x-www-form-urlencoded;charset=UTF-8",
|
||||
@@ -88,8 +108,51 @@ pubFun.fadada = async function(api, params) {
|
||||
...params
|
||||
}
|
||||
});
|
||||
|
||||
console.log('res: ', res);
|
||||
return res;
|
||||
}
|
||||
|
||||
function buildQueryString(params) {
|
||||
let queryString = '';
|
||||
for (const key in params) {
|
||||
if (params.hasOwnProperty(key)) {
|
||||
if (queryString.length > 0) {
|
||||
queryString += '&';
|
||||
}
|
||||
queryString += `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`;
|
||||
}
|
||||
}
|
||||
return queryString;
|
||||
}
|
||||
|
||||
/**
|
||||
* 给法大大发请求
|
||||
|
||||
* @param {Object} api
|
||||
* @param {Object} params
|
||||
*/
|
||||
pubFun.fadadaUrl = function(api, params) {
|
||||
|
||||
|
||||
|
||||
const timestamp = vk.pubfn.timeFormat(new Date(), "yyyyMMddhhmmss");
|
||||
const msg_digest = getFadadaSign(api, params, timestamp)
|
||||
|
||||
const queryParams = buildQueryString({
|
||||
app_id: app_id,
|
||||
timestamp,
|
||||
v: '2.0',
|
||||
msg_digest,
|
||||
...params
|
||||
});
|
||||
const fullUrl = `${url}/${api}?${queryParams}`;
|
||||
|
||||
|
||||
return fullUrl;
|
||||
}
|
||||
|
||||
pubFun.base64ToFile = function(base64, fileName) {
|
||||
|
||||
}
|
||||
|
||||
module.exports = pubFun;
|
||||
Reference in New Issue
Block a user