Revert "Revert "✨ feat(消息): 添加推送消息sdk""
This reverts commit 918cc3415f.
This commit is contained in:
@@ -1,10 +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, get37Md5SignA, get37Md5SignB, getVidObjSign } from "./sdkUtil";
|
||||
import { checkVidObjSign, get37CheckChatMd5Sign, get37Md5SignA, get37Md5SignB, get37PushMsgMd5Sign, getVidObjSign } from "./sdkUtil";
|
||||
import { STATUS } from '../consts'
|
||||
import { resResult } from "./util";
|
||||
import { Chat37Params, CheckGuild37Params, CheckName37Params, GetWordParam } from "../domain/sdk";
|
||||
import { Chat37Params, CheckGuild37Params, CheckName37Params, GetWordParam, PushMsg37Param } from "../domain/sdk";
|
||||
|
||||
// 通用,请求http
|
||||
export async function httpRequest(url: string, method: string, body: any, headers?: any, timeout = 150) {
|
||||
@@ -77,6 +77,42 @@ export async function httpRequestForm(url: string, method: string, form: any, ti
|
||||
}
|
||||
}
|
||||
|
||||
export async function httpRequestFormData(url: string, method: string, form: any, timeout = 150, printRes = true) {
|
||||
console.log(`httpRequest*********: ${url}, ${method}, ${JSON.stringify(form)}`)
|
||||
|
||||
let options = {
|
||||
url,
|
||||
method,
|
||||
headers: {
|
||||
'content-type': 'multipart/form-data;charset=utf-8'
|
||||
},
|
||||
timeout,
|
||||
JSON: true
|
||||
}
|
||||
if(method == HTTP_METHOD.GET) {
|
||||
options['qs'] = form;
|
||||
} else if (method == HTTP_METHOD.POST) {
|
||||
options['form'] = form;
|
||||
}
|
||||
|
||||
try {
|
||||
let res = await request(options);
|
||||
console.log('*****request result*****');
|
||||
if (printRes) {
|
||||
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 {
|
||||
return resResult(STATUS.REQUEST_TIME_OUT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/************** 厚土防沉迷接口 **************/
|
||||
/**
|
||||
* 在线报告 暂时不使用
|
||||
@@ -189,3 +225,13 @@ export async function request37GetWord(url: string, body: GetWordParam, key: str
|
||||
let result = await httpRequestForm(url, HTTP_METHOD.GET, body, 5 * 60 * 1000, false);
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function request37PushMessage(url: string, body: PushMsg37Param, key: string) {
|
||||
body.setSign(get37PushMsgMd5Sign(body, key));
|
||||
|
||||
let result = await httpRequestFormData(url, HTTP_METHOD.POST, 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