起名:添加屏蔽词检测
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
import * as request from "request-promise";
|
||||
import { RequestError } from "request-promise/errors";
|
||||
import { BANTU_VID_ADDR, BANTU_VID_APP_KEY, HTTP_METHOD } from '../consts';
|
||||
import { checkVidObjSign, get37CheckChatMd5Sign, get37Md5Sign, getVidObjSign } from "./sdkUtil";
|
||||
import { checkVidObjSign, get37CheckChatMd5Sign, get37Md5Sign, get37PostMd5Sign, getVidObjSign } from "./sdkUtil";
|
||||
import { STATUS } from '../consts'
|
||||
import { resResult } from "./util";
|
||||
import { Chat37Params, CheckGuild37Params, CheckName37Params } from "../domain/sdk";
|
||||
|
||||
// 通用,请求http
|
||||
export async function httpRequest(url: string, method: string, body: any, headers?: any, timeout = 150) {
|
||||
@@ -20,8 +21,8 @@ export async function httpRequest(url: string, method: string, body: any, header
|
||||
method,
|
||||
headers,
|
||||
body,
|
||||
json: true,
|
||||
timeout
|
||||
timeout,
|
||||
JSON: true
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -30,11 +31,41 @@ export async function httpRequest(url: string, method: string, body: any, header
|
||||
console.log(JSON.stringify(res));
|
||||
return res;
|
||||
} catch (e) {
|
||||
let code = (<RequestError>e).cause.code;
|
||||
console.error('******', e);
|
||||
let code = (<RequestError>e).cause?.code;
|
||||
if(code == 'ESOCKETTIMEDOUT') {
|
||||
return resResult(STATUS.REQUEST_TIME_OUT);
|
||||
} else {
|
||||
return resResult(STATUS.REQUEST_TIME_OUT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function httpRequestForm(url: string, method: string, form: any, timeout = 150) {
|
||||
console.log(`httpRequest*********: ${url}, ${method}, ${JSON.stringify(form)}`)
|
||||
|
||||
let options = {
|
||||
url,
|
||||
method,
|
||||
headers: {
|
||||
'content-type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
form,
|
||||
timeout,
|
||||
JSON: true
|
||||
}
|
||||
|
||||
try {
|
||||
let res = await request(options);
|
||||
console.log('*****request result*****');
|
||||
console.log(JSON.stringify(res));
|
||||
return res;
|
||||
} catch (e) {
|
||||
console.error('******', e);
|
||||
let code = (<RequestError>e).cause?.code;
|
||||
if(code == 'ESOCKETTIMEDOUT') {
|
||||
return resResult(STATUS.REQUEST_TIME_OUT);
|
||||
} else {
|
||||
console.error(e);
|
||||
return resResult(STATUS.REQUEST_TIME_OUT);
|
||||
}
|
||||
}
|
||||
@@ -117,15 +148,26 @@ export async function vidHttpRequest(addr: string, body: any) {
|
||||
export async function request37(url: string, body: any, key: string) {
|
||||
body['sign'] = get37Md5Sign(body, key);
|
||||
|
||||
let result = await httpRequest(url, HTTP_METHOD.POST, {}, body);
|
||||
let result = await httpRequest(url, HTTP_METHOD.POST, body, {});
|
||||
console.log('******result', result)
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function request37CheckChat(url: string, body: any, key: string) {
|
||||
body['sign'] = get37CheckChatMd5Sign(body, key);
|
||||
export async function request37CheckChat(url: string, body: Chat37Params, key: string) {
|
||||
body.setSign(get37CheckChatMd5Sign(body, key));
|
||||
|
||||
let result = await httpRequest(url, HTTP_METHOD.GET, {}, body, 3 * 60 * 1000);
|
||||
let result = await httpRequestForm(url, HTTP_METHOD.GET, body, 3 * 60 * 1000);
|
||||
if(result != 1 && result.code != STATUS.REQUEST_TIME_OUT.code) {
|
||||
return false
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export async function request37Post(url: string, body: CheckName37Params|CheckGuild37Params, key: string) {
|
||||
body.setSign(get37PostMd5Sign(body.getBody(), key));
|
||||
|
||||
let result = await httpRequestForm(url, HTTP_METHOD.POST, body, 1 * 60 * 1000);
|
||||
console.log('*******', result != 1, result.code != STATUS.REQUEST_TIME_OUT.code)
|
||||
if(result != 1 && result.code != STATUS.REQUEST_TIME_OUT.code) {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -50,6 +50,10 @@ export function get37CheckChatMd5Sign(body: Chat37Params, key: string) {
|
||||
return md5(str);
|
||||
}
|
||||
|
||||
export function get37PostMd5Sign(body: any, key: string) {
|
||||
return getMd5ObjSign(body, '', (str) => `${str}${key}`);
|
||||
}
|
||||
|
||||
export async function loginValidate37(clientId: string, pst: string, platformAppid: string, childGameId: number) {
|
||||
let result: LoginValidataReturn37 = await request37(SDK_37_ADDR.LOGIN, {
|
||||
clientid: clientId,
|
||||
|
||||
Reference in New Issue
Block a user