sdk:37sdk发起支付接口
This commit is contained in:
@@ -104,9 +104,10 @@ export enum FIRST_GIFT_STATE {
|
||||
*/
|
||||
export enum PAY_TYPE {
|
||||
TEST = 0, // 测试
|
||||
WX = 1, // 微信
|
||||
ALI = 2, // 阿里
|
||||
APPLE = 3, // 苹果
|
||||
THREE_SEVEN = 1, // 37
|
||||
WX = 2, // 微信
|
||||
ALI = 3, // 阿里
|
||||
APPLE = 4, // 苹果
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -445,5 +445,6 @@ export const STATUS = {
|
||||
ACTIVITY_NO_PRODUCT: { code: 70011, simStr: '活动数据错误' },
|
||||
ERROR_TYPE: { code: 70012, simStr: '未知活动类型' },
|
||||
ORDER_PARAM_ERROR: { code: 70013, simStr: '订单参数错误' },
|
||||
CHANNEL_INFO_NOT_FOUND: { code: 70014, simStr: '未找到玩家渠道数据' },
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -259,7 +259,7 @@ export default class User extends BaseModel {
|
||||
}
|
||||
|
||||
public static async findUserByUid(uid: number) {
|
||||
const user: UserType = await UserModel.findOne({ uid }).select('uid tel').lean({ getters: true });
|
||||
const user: UserType = await UserModel.findOne({ uid }).select('uid tel channelInfo').lean({ getters: true });
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user