推送:接入个推推送接口

This commit is contained in:
qiaoxin
2021-06-30 19:58:11 +08:00
parent 64932c32ef
commit 221b138896
9 changed files with 355 additions and 16 deletions
+7
View File
@@ -1,3 +1,10 @@
export enum HTTP_METHOD {
POST = 'POST',
GET = 'GET',
PUT = 'PUT',
DELETE = 'DELETE',
}
export enum BANTU_VID_ADDR {
HOST = 'https://sdks.trgame.cn',
IDCARD = '/vid/idcard', // 实名认证
+43
View File
@@ -0,0 +1,43 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
/**
* 个推推送消息记录
*/
@index({ roleId: 1 })
export default class Getui_Messages extends BaseModel {
@prop({ required: true })
requestId: string; // 消息标识,唯一
@prop({ required: false })
taskId: string; // 群发消息id
@prop({ required: true })
body: string; // 消息内容
@prop({ required: true })
des: string; // 描述
@prop({ required: true })
isPush: boolean; // 是否推送出去
//推送消息成功
public static async pushMessageSuccess(taskId: string, isPush: boolean) {
await GetuiMessagesModel.findOneAndUpdate({ taskId }, { $set: { isPush } }, { new: true }).lean(true);
}
//添加个人信息
public static async insertSingleMessage(requestId: string, body: string, des: string, isPush: boolean) {
let data = { requestId, body, des, isPush };
await GetuiMessagesModel.insertMany(data);
}
//添加群信息
public static async insertListMessage(requestId: string, taskId: string, body: string, des: string, isPush: boolean) {
let data = { requestId, taskId, body, des, isPush };
await GetuiMessagesModel.insertMany(data);
}
}
export const GetuiMessagesModel = getModelForClass(Getui_Messages);
export interface GetuiMessagesModelType extends Pick<DocumentType<Getui_Messages>, keyof Getui_Messages> { }
export type GetuiMessagesModelTypeParam = Partial<GetuiMessagesModelType>; // 将所有字段变成可选项
+55
View File
@@ -0,0 +1,55 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
/**
* 角色的个推标签数据
*/
@index({ roleId: 1 })
export default class Getui_Tags extends BaseModel {
@prop({ required: true })
roleId: string; // 角色id
@prop({ required: true })
cid: string; // 个推标识
@prop({ required: true })
tags: string[]; // 标签
//查询用户信息
public static async findRole(roleId: string) {
let result: GetuiTagsModelType = await GetuiTagsModel.findOne(
{ roleId }).lean(true);
return result;
}
//查询用户信息
public static async findRoles(roleIds: string[]) {
let result: GetuiTagsModelType[] = await GetuiTagsModel.find(
{ roleId: { $in: roleIds } }).lean(true);
return result;
}
//更新个推标签
public static async updateTags(roleId: string, tags: string[]) {
let result: GetuiTagsModelType = await GetuiTagsModel.findOneAndUpdate(
{ roleId }, { $set: { tags: tags } }, { new: true }).lean(true);
return result;
}
//添加个推信息
public static async insertRole(roleId: string, cid: string, tags: string[]) {
let result: GetuiTagsModelType = await GetuiTagsModel.findOneAndUpdate(
{ roleId, cid }, { $set: { tags: tags } }, { upsert: true, new: true }).lean(true);
return result;
}
//删除角色个推信息
public static async delectRole(roleId: string) {
await GetuiTagsModel.deleteOne({ roleId });
}
}
export const GetuiTagsModel = getModelForClass(Getui_Tags);
export interface GetuiTagsModelType extends Pick<DocumentType<Getui_Tags>, keyof Getui_Tags> { }
export type GetuiTagsModelTypeParam = Partial<GetuiTagsModelType>; // 将所有字段变成可选项
+19
View File
@@ -19,6 +19,12 @@ export default class ServerTemp extends BaseModel {
@prop({ required: true })
huntRoundIndex: number; // 寻宝骑兵-周期数
@prop({ required: true })
getuiToken: string; // 个推token
@prop({ required: true })
getuiTokenExpireTime: number; // 个推token过期时间
//更新寻宝猎人活动数据
public static async updateTreasureHuntData(serverId: number, huntActivityId: number, huntBeginTime: Date, huntEndTime: Date, huntRoundIndex: number) {
let result: ServerTempModelType = await ServerTempModel.findOneAndUpdate({ serverId },
@@ -37,6 +43,19 @@ export default class ServerTemp extends BaseModel {
let result = await ServerTempModel.deleteMany({ serverId });
return result;
}
//更新个推token数据
public static async updateGetuiData(getuiToken: string, getuiTokenExpireTime: number) {
let result: ServerTempModelType = await ServerTempModel.findOneAndUpdate({ serverId: 0 },
{ $set: { getuiToken, getuiTokenExpireTime } }, { upsert: true, new: true }).lean(true);
return result;
}
//查询个推token数据
public static async findGetuiData() {
let result: ServerTempModelType = await ServerTempModel.findOne({ serverId: 0 }).lean(true);
return result;
}
}
export const ServerTempModel = getModelForClass(ServerTemp);
@@ -34,11 +34,13 @@ export class NewHeroGKPage {
pageIndex: number; // 页码
name: string; // 名称
hid: number; //武将id
title: string = '';//客户端用说明文字
constructor(data: any) {
this.pageIndex = data.pageIndex;
this.name = data.name;
this.hid = data.hid;
this.title = data.title;
this.items = [];
for (let obj of data.items) {
this.items.push(new NewHeroGKItem(obj, this.pageIndex))
@@ -25,7 +25,6 @@ export class NewHeroGiftItem {
// 新将礼包数据
export class NewHeroGiftData extends ActivityBase {
name: string = '';//活动名称
title: string = '';//客户端用说明文字
list: Array<NewHeroGiftItem> = [];//礼包列表
totalPoint: number = 0;//获得总点数
consumeTotalPoint: number = 0;//消耗总点数
@@ -56,7 +55,6 @@ export class NewHeroGiftData extends ActivityBase {
public initData(data: string) {
let dataObj = JSON.parse(data);
this.name = dataObj.name;
this.title = dataObj.title;
this.totalPoint = 0;
this.consumeTotalPoint = 0;
this.explain = dataObj.explain;
+35 -12
View File
@@ -7,8 +7,8 @@ import { BANTU_VID_ADDR, BANTU_VID_APP_KEY } from '../consts';
* @param userCode 账号
* @param packageName 包名
*/
export async function reportOnline ( userCode: string, packageName: string) {
if(!packageName || packageName==''){
export async function reportOnline(userCode: string, packageName: string) {
if (!packageName || packageName == '') {
packageName = 'com.bantu.nfsg'
}
@@ -16,7 +16,7 @@ export async function reportOnline ( userCode: string, packageName: string) {
account: userCode,
package: packageName
});
if(result && result.code !== 1) {
if (result && result.code !== 1) {
console.error(result.msg);
}
@@ -30,8 +30,8 @@ export async function reportOnline ( userCode: string, packageName: string) {
* @param userCode 账号
* @param packageName 包名
*/
export async function authenticate (name: string, idNum: string, userCode: string, packageName: string) {
if(!packageName || packageName==''){
export async function authenticate(name: string, idNum: string, userCode: string, packageName: string) {
if (!packageName || packageName == '') {
packageName = 'com.bantu.nfsg'
}
@@ -42,7 +42,7 @@ export async function authenticate (name: string, idNum: string, userCode: strin
appkey: BANTU_VID_APP_KEY,
package: packageName
});
if(result && result.code !== 1) {
if (result && result.code !== 1) {
console.error(result.msg);
}
@@ -56,29 +56,52 @@ export async function vidHttpRequest(addr: string, body: any) {
let options = {
url: BANTU_VID_ADDR.HOST + addr,
method: 'POST',
body:body,
body: body,
json: true
}
try {
let res = await request(options);
let check = checkSign(res);
if(!check) return false;
if (!check) return false;
// console.log('*****request result*****');
// console.log(JSON.stringify(res));
return res;
} catch(e) {
} catch (e) {
console.error(e);
return false
}
}
export function md5Vid (str: string) {
export async function httpRequest(url: string, method: string, headers: any, body: any) {
console.log(`httpRequest*********: ${url}, ${method}, ${JSON.stringify(headers)}, ${JSON.stringify(body)}`)
let options = {
url,
method,
headers,
body,
json: true
}
try {
let res = await request(options);
console.log('*****request result*****');
console.log(JSON.stringify(res));
return res;
} catch (e) {
console.error(e);
return false
}
}
export function md5Vid(str: string) {
str = 'vId' + str;
return crypto.createHash('md5').update(str, 'utf8').digest("hex");
};
export function getObjSign (obj: any) {
export function getObjSign(obj: any) {
const str = [];
Object.keys(obj).sort().forEach((key) => {
if (key == 'sign') {
@@ -94,7 +117,7 @@ export function getObjSign (obj: any) {
return md5Vid(strs);
}
export async function checkSign (obj: any) {
export async function checkSign(obj: any) {
if (getObjSign(obj) === obj.sign) {
return true;
}