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
+2 -60
View File
@@ -1,6 +1,6 @@
import * as request from "request-promise";
import * as crypto from 'crypto'
import { BANTU_VID_ADDR, BANTU_VID_APP_KEY, HTTP_METHOD } from '../consts';
import { checkVidObjSign, get37Md5Sign, getVidObjSign } from "./sdkUtil";
// 通用,请求http
export async function httpRequest(url: string, method: string, headers: any, body: any) {
@@ -25,38 +25,6 @@ export async function httpRequest(url: string, method: string, headers: any, bod
}
}
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;
}
/************** 厚土防沉迷接口 **************/
/**
* 在线报告 暂时不使用
@@ -129,36 +97,10 @@ export async function vidHttpRequest(addr: string, body: any) {
}
}
function getVidObjSign(body: any) {
return getMd5ObjSign(body, '', treatVid);
}
function checkVidObjSign(obj: any) {
return checkMd5Sign(obj, treatVid);
}
function treatVid(str) {
return 'vId' + str;
}
// 37sdk请求
function get37ObjSign(body: any, key: string) {
return getMd5ObjSign(body, '&', (str) => `${str}&${key}`);
}
export async function request37(url: string, body: any, key: string) {
// body = {
// clientid: 'abscddsssssss',
// pid: '37h5',
// game_id: 30,
// pst: 'MWNmY2pweWZ6dFRhZmdnZ1k4aHhINVUyZnFra1',
// time: 1583821808,
// c_game_id: 'com.a.test'
// }
// key = 'FkM619)t,P7E3yK#44q85)!Sm5cv8j'
body['sign'] = get37ObjSign(body, key);
body['sign'] = get37Md5Sign(body, key);
let result = await httpRequest(url, HTTP_METHOD.POST, {}, body);
console.log('******result', result)
+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;
}