sdk:37sdk发起支付接口

This commit is contained in:
luying
2021-11-09 11:53:00 +08:00
parent fc653b37e6
commit 173481a60c
9 changed files with 129 additions and 70 deletions
+54
View File
@@ -2,9 +2,47 @@ import { SDK_37_ADDR, SDK_37_CONST } from '../consts';
import { request37 } from './httpUtil';
import { nowSeconds } from './timeUtil';
import { LoginValidataReturn37 } from '../domain/sdk';
import * as crypto from 'crypto'
// 通用加密方法
export function md5(str: string, treatStr?: (str: string) => string) {
if(treatStr) str = treatStr(str);
console.log('*****str', str)
return crypto.createHash('md5').update(str, 'utf8').digest("hex");
};
export function getMd5ObjSign(obj: any, joinMark: string, treatStr?: (str: string) => string) {
const str = [];
Object.keys(obj).sort().forEach((key) => {
if (key == 'sign') {
} else {
str.push(key + '=' + obj[key]);
}
});
if (str.length == 0) {
console.error('check obj', obj);
}
var strs = str.join(joinMark);
return md5(strs, treatStr);
}
export async function checkMd5Sign(obj: any, treatStr?: (str: string) => string) {
if (getMd5ObjSign(obj, '', treatStr) === obj.sign) {
return true;
}
console.warn('correct sign:', getMd5ObjSign(obj, '', treatStr), obj.sign);
return false;
}
/************** 37sdk **************/
export function get37Md5Sign(body: any, key: string) {
return getMd5ObjSign(body, '&', (str) => `${str}&${key}`);
}
export async function loginValidate37(clientId: string, pst: string) {
let result: LoginValidataReturn37 = await request37(SDK_37_ADDR.LOGIN, {
clientid: clientId,
@@ -31,4 +69,20 @@ export async function loginValidata(channelType: string, clientId: string, pst:
export function getChannelId(channelType: string, uid: number|string) {
return `${channelType}: ${uid}`;
}
/********* 厚土防沉迷 *********/
export function getVidObjSign(body: any) {
return getMd5ObjSign(body, '', treatVid);
}
export function checkVidObjSign(obj: any) {
return checkMd5Sign(obj, treatVid);
}
function treatVid(str) {
return 'vId' + str;
}