✨ feat(消息): 添加推送消息sdk
This commit is contained in:
@@ -135,6 +135,7 @@ import { DicGVGVestigeLeagueRank, dicGVGVestigeLeagueRank, loadGVGVestigeLeagueR
|
||||
import { DicGVGVestigePlayerRank, dicGVGVestigePlayerRank, loadGVGVestigePlayerRank } from "./dictionary/DicGVGVestigePlayerRank";
|
||||
import { dicGVGAreaPoint, loadGVGAreaPoint, dicGVGPointsByAreaId } from "./dictionary/DicGVGAreaPoint";
|
||||
import { DicGVGBattleRankReward, dicGVGBattleRankReward, loadGVGBattleRankReward } from './dictionary/DicGVGBattleRankReward';
|
||||
import { dicPushMessage, loadPushMessage } from './dictionary/DicPushMessage';
|
||||
|
||||
export const gameData = {
|
||||
daily: dicDaily,
|
||||
@@ -343,6 +344,7 @@ export const gameData = {
|
||||
gvgTeamDurability: new Map<number, number>(),
|
||||
gvgPointByAreaId: dicGVGPointsByAreaId,
|
||||
gvgReviveGold: new Map<number|'max', number>(),
|
||||
dicPushMessage: dicPushMessage
|
||||
};
|
||||
|
||||
// 在此提供一些原先在gamedata中提供的方法,以便更方便获取gameData数据
|
||||
@@ -1486,6 +1488,7 @@ function loadDatas() {
|
||||
loadGVGVestigePlayerRank();
|
||||
loadGVGAreaPoint();
|
||||
loadGVGBattleRankReward();
|
||||
loadPushMessage();
|
||||
}
|
||||
|
||||
// 重载dicParam
|
||||
|
||||
24
shared/pubUtils/dictionary/DicPushMessage.ts
Normal file
24
shared/pubUtils/dictionary/DicPushMessage.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { readFileAndParse } from '../util'
|
||||
import { FILENAME } from '../../consts'
|
||||
|
||||
export interface DicPushMessage {
|
||||
id: number;
|
||||
pushMsgType: string; // 推送类型标签,PUSH_MSG_TYPE
|
||||
title: string; // 推送标题,30字以内
|
||||
description: string; // 推送正文,100字以内,其他同上
|
||||
playerType: number; // 推送玩家的类型,PLAYER_TYPE
|
||||
clickType: string; // 点击通知之后的后续动作
|
||||
url: string; // 玩家点击通知之后,如果clickType选了url填写网址,长度<=1024
|
||||
intent: string; // 玩家点击通知之后,如果clickType选了intent填写应用特定页面,需要找客户端定制,长度<=1024
|
||||
}
|
||||
|
||||
export const dicPushMessage = new Map<string, DicPushMessage>();
|
||||
export function loadPushMessage() {
|
||||
dicPushMessage.clear();
|
||||
let arr = readFileAndParse(FILENAME.DIC_PUSH_MESSAGE);
|
||||
|
||||
arr.forEach(o => {
|
||||
dicPushMessage.set(o.pushMsgType, o);
|
||||
});
|
||||
arr = undefined;
|
||||
}
|
||||
@@ -53,6 +53,8 @@ export interface DicServerConst {
|
||||
readonly SKIP_ENCODE: number;
|
||||
// 是否返利
|
||||
readonly NEED_REBATE: number;
|
||||
// 推送
|
||||
readonly PUSH_MSG: number;
|
||||
}
|
||||
|
||||
export const dicServerConst: DicServerConst = {} as DicServerConst;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { DEBUG_PRICE, REDIS_KEY, SDK_37_ADDR, SDK_37_CONST, WJX_KEY } from '../consts';
|
||||
import { request37 } from './httpUtil';
|
||||
import { nowSeconds } from './timeUtil';
|
||||
import { LoginValidataReturn37, Chat37Params, GetServerListParam } from '../domain/sdk';
|
||||
import { LoginValidataReturn37, Chat37Params, GetServerListParam, PushMsg37Param } from '../domain/sdk';
|
||||
import * as crypto from 'crypto'
|
||||
import { gameData } from './data';
|
||||
|
||||
@@ -57,6 +57,18 @@ export function get37CheckChatMd5Sign(body: Chat37Params, key: string) {
|
||||
return sign;
|
||||
}
|
||||
|
||||
export function get37PushMsgMd5Sign(body: PushMsg37Param, key: string) {
|
||||
let { notify_id = '', game_id = '', c_game_id = '', title = '', text = '', target = '', click_type = '', time = '' } = body;
|
||||
let str = encodeUtf8(`${notify_id}${game_id}${c_game_id}${title}${text}${target}${click_type}${key}${time}`);
|
||||
let sign = md5(str);
|
||||
console.log('** origin str', body, str, sign);
|
||||
return sign;
|
||||
}
|
||||
|
||||
function encodeUtf8(str: string) {
|
||||
return Buffer.from(str, 'utf8').toString();
|
||||
}
|
||||
|
||||
export function get37Md5SignB(body: any, key: string) {
|
||||
return getMd5ObjSign(body, '', (str) => `${str}${key}`);
|
||||
}
|
||||
@@ -120,7 +132,6 @@ export function getChannelId(channelType: string, uid: number|string) {
|
||||
return `${channelType}_${uid}`;
|
||||
}
|
||||
|
||||
|
||||
/********* 厚土防沉迷 *********/
|
||||
|
||||
export function getVidObjSign(body: any) {
|
||||
@@ -177,4 +188,8 @@ export function isSkipEncode(isDevelop = false) {
|
||||
|
||||
export function needRebate() {
|
||||
return gameData.serverConst.NEED_REBATE == 1;
|
||||
}
|
||||
|
||||
export function needPushMsg() {
|
||||
return gameData.serverConst.PUSH_MSG == 1;
|
||||
}
|
||||
Reference in New Issue
Block a user