聊天:添加屏蔽
This commit is contained in:
@@ -1,17 +1,27 @@
|
||||
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, get37Md5Sign, getVidObjSign } from "./sdkUtil";
|
||||
import { checkVidObjSign, get37CheckChatMd5Sign, get37Md5Sign, getVidObjSign } from "./sdkUtil";
|
||||
import { STATUS } from '../consts'
|
||||
import { resResult } from "./util";
|
||||
|
||||
// 通用,请求http
|
||||
export async function httpRequest(url: string, method: string, headers: any, body: any) {
|
||||
export async function httpRequest(url: string, method: string, body: any, headers?: any, timeout = 150) {
|
||||
console.log(`httpRequest*********: ${url}, ${method}, ${JSON.stringify(headers)}, ${JSON.stringify(body)}`)
|
||||
|
||||
if(!headers) {
|
||||
headers = {
|
||||
'content-type': 'application/json;charset=utf-8',
|
||||
}
|
||||
}
|
||||
|
||||
let options = {
|
||||
url,
|
||||
method,
|
||||
headers,
|
||||
body,
|
||||
json: true
|
||||
json: true,
|
||||
timeout
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -20,8 +30,13 @@ export async function httpRequest(url: string, method: string, headers: any, bod
|
||||
console.log(JSON.stringify(res));
|
||||
return res;
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return false
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,4 +120,14 @@ export async function request37(url: string, body: any, key: string) {
|
||||
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);
|
||||
|
||||
let result = await httpRequest(url, HTTP_METHOD.GET, {}, body, 3 * 60 * 1000);
|
||||
if(result != 1 && result.code != STATUS.REQUEST_TIME_OUT.code) {
|
||||
return false
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user