feat(活动): 微信公众号口令

This commit is contained in:
luying
2023-04-04 10:11:05 +08:00
parent 94b6dca4cc
commit cecd959c00
22 changed files with 441 additions and 43 deletions

View File

@@ -209,4 +209,5 @@ export const PUSH_ROUTE = {
GVG_CONTRIBUTE_UPDATE: 'onGVGContributeUpdate', // 贡献更新
GVG_TARGET_CITY_UPDATE: 'onGVGTargetCitiesUpdate', // 目标城池更新
GVG_NOTICE_UPDATE: 'onGVGNoticeUpdate', // 管理信息更新
PUBLIC_ACCOUNT_GIFT: 'onPublicAccountGift', // 公众号发送
}

View File

@@ -30,8 +30,10 @@ export enum SDK_37_CONST {
CHAT_KEY = '3PerD)H!JdTC_pEUnZl8vXKgasj5;7Q~', // 聊天KEY
IOS_PID = 'zyz',
BACKEND_KEY = 'zyzbackend2022',
PUBLIC_GIFT_KEY = 'zyzbackend202304',
PUSH_KEY = '7mV3FzL7drRxTPkoBPkcRXpeTapG2jk9', // 推送消息KEY
PUSH_GAME_ID = 814, // 推送消息的GAME_ID
GIFT_GAME_ID = 814, // 游戏id
}
export enum SDK_TA_CONST {
@@ -62,4 +64,6 @@ export enum SDK_PUSH_MSG_PLAYER_TYPE {
HAS_LEAGUE = 2, // 有联军且48小时内登录过但当前未在线的玩家
AFK = 3, // 至少48小时未上线且等级>=20级的玩家
ACTIVE_PLAYER = 4, // 24小时内登录过但当前未在线的玩家
}
}
export const PUBLIC_ACCOUNT_GIFT = 'YJZPUBACC';

View File

@@ -268,6 +268,8 @@ export enum REDIS_KEY {
GVG_SEND_REWARD ='gvgSendReward', // gvg发放奖励
GVG_SPINE_CNT ='gvgSpineCnt', // gvg spine的下发数量
ACTIVITY_MINI_GAME ='miniGame', // 活动小游戏排行榜
PUBLIC_ACCOUNT_GIFT = 'pubAccGiftChannel', // 公众号频道
SEND_GIFT_CODE = 'sendGiftCodeChannel', // 礼包码频道
}
// 各排行榜对应hash的key

View File

@@ -669,6 +669,8 @@ export const STATUS = {
ACTIVITY_MONTHLY_FUND_NOT_FOUND: { code: 50061, simStr: '未找到该配置' },
ACTIVITY_MONTHLY_FUND_LOCK: { code: 50062, simStr: '本次签到暂未解锁' },
ACTIVITY_MONTHLY_FUND_HAS_SIGN: { code: 60063, simStr: '本次签到奖励已领取' },
ACTIVITY_PUBLIC_ACCOUNT_WAIT: { code: 60064, simStr: '请在公众号输入口令' },
ACTIVITY_PUBLIC_ACCOUNT_RECEIVED: { code: 60065, simStr: '已领取' },
// GM后台相关状态 60000 - 69999
GM_ERR_PASSWORD: { code: 60001, simStr: '账号或密码错误' },
@@ -779,4 +781,18 @@ export const BACKEND_37_CODE = {
TIME_IS_EXPIRED: { code: -3, simStr: '请求超时(连接已过期)' },
USER_NOT_FOUND: { code: -4, simStr: '非法账号' },
LOGIN_FAIL: { code: -5, simStr: '登录失败' },
}
export const SDK_37_SEND_GIFT_RESULT_CODE = {
SUCCESS: { code: 1, simStr: '成功' },
WRONG_PARAMS: { code: 10001, simStr: '参数异常' },
ROLE_NOT_FOUND: { code: 10002, simStr: '角色不存在' },
SIGN_ERR: { code: 10003, simStr: '签名错误' },
INTERNAL_ERR: { code: 10004, simStr: '处理异常' },
GIFT_NOT_FOUND: { code: 20002, simStr: '礼包id不存在' },
ORDER_DUPLICATE: { code: 20003, simStr: '订单号重复' },
USE_CNT_MAX: { code: 20004, simStr: '超过使用次数' },
GIFT_CODE_HAS_EXPIRED: { code: 20005, simStr: '礼包码已过期' },
GIFT_CODE_NOT_START: { code: 20006, simStr: '礼包码暂未开启' },
GIFT_CHANNEL_ERR: { code: 20007, simStr: '礼包不可在此渠道使用' },
}

View File

@@ -0,0 +1,49 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
/**
* 自助商店
*/
@index({ activityId: 1, channelId: 1 })
export default class Activity_Public_Account_Code extends BaseModel {
@prop({ required: true })
activityId: number; // 对应礼包码
@prop({ required: true })
channelId: string; // 37平台id
@prop({ required: true })
serverId: number; // 服
@prop({ required: true })
roleId: string; // 玩家id
@prop({ required: true })
orderId: string; // 收到回调的订单号
@prop({ required: true })
hasReceived: boolean; // 是否领取
public static async findByChannel(activityId: number, channelId: string) {
let result: ActivityPublicAccountCodeType = await ActivityPublicAccountCodeModel.findOne({ activityId, channelId }).lean();
return result;
}
public static async sendGift(activityId: number, channelId: string, serverId: number, roleId: string, orderId: string) {
let result: ActivityPublicAccountCodeType = await ActivityPublicAccountCodeModel.findOneAndUpdate({ activityId, channelId }, { $set: { serverId, roleId, orderId }, $setOnInsert: { hasReceived: false } }, { new: true, upsert: true }).lean();
return result;
}
public static async receive(activityId: number, channelId: string) {
let result: ActivityPublicAccountCodeType = await ActivityPublicAccountCodeModel.findOneAndUpdate({ activityId, channelId, hasReceived: false }, { $set: { hasReceived: true }}, { new: true }).lean();
return result;
}
}
export const ActivityPublicAccountCodeModel = getModelForClass(Activity_Public_Account_Code);
export interface ActivityPublicAccountCodeType extends Pick<DocumentType<Activity_Public_Account_Code>, keyof Activity_Public_Account_Code> { }
export type ActivityPublicAccountCodeTypeParam = Partial<ActivityPublicAccountCodeType>; // 将所有字段变成可选项

View File

@@ -52,6 +52,9 @@ export default class GiftCode extends BaseModel {
@prop({ required: true, default: 0 })
usedNum: number; // 使用次数
@prop({ required: true, default: 0 })
type: number; // 0-游戏内领取 1-公众号口令活动领取 2-邮件领取
@prop({ required: true, default: true })
isEnable: boolean; // 是否可以使用

View File

@@ -16,6 +16,9 @@ class RoleRecord {
@prop({ required: true, default: 0 })
serverId: number;
@prop({ required: false, default: '' })
orderId?: string;
@prop({ required: true, default: 0 })
time: number;
}
@@ -70,9 +73,9 @@ export default class GiftCodeDetail extends BaseModel {
return result;
}
public static async increaseUsedNum(code: string, roleId: string, roleName: string, serverId: number) {
public static async increaseUsedNum(code: string, roleId: string, roleName: string, serverId: number, orderId?: string) {
let result: GiftCodeDetailType = await GiftCodeDetailModel.findOneAndUpdate({ code }, {
$inc: { usedNum: 1 }, $push: { roleIds: roleId, record: { roleId, roleName, serverId, time: nowSeconds() } }
$inc: { usedNum: 1 }, $push: { roleIds: roleId, record: { roleId, roleName, serverId, time: nowSeconds(), orderId } }
}, { new: true }).lean();
return result;
}

View File

@@ -246,7 +246,7 @@ export default class User extends BaseModel {
}
public static async findUserByChannel(channelId: string) {
const user: UserType = await UserModel.findOne({ channelId }).select('uid token serverType auth tel userCode pkgName ip deviceId').lean({ getters: true });
const user: UserType = await UserModel.findOne({ channelId }).select('uid token serverType auth tel userCode pkgName ip deviceId channelId').lean({ getters: true });
return user;
}

View File

@@ -5,6 +5,7 @@ import { ActivityBindPhoneRewardType } from '../../db/ActivityBindPhoneReward';
import { LinkType } from '../../db/Link';
import { UserType } from '../../db/User';
import { ActivityBase } from './activityField';
import { ActivityPublicAccountCodeType } from '../../db/ActivityPublicAccountCode';
// 数据库
interface PageDataInDb {
@@ -12,7 +13,6 @@ interface PageDataInDb {
pageName: string;
type: number;
rewards: string;
giftCode: string;
}
interface BindPhoneDataInDb {
@@ -49,18 +49,21 @@ class BindPhonePage extends PageData {
super(pageData);
this.rewards = pageData.rewards;
}
public setBindPhoneStatus(user: UserType, data: ActivityBindPhoneRewardType) {
if(user && user.channelInfo && user.channelInfo.is_phone_bind == 1) this.status = BIND_PHONE_STATUS.HAS_BIND;
if(data) this.status = data.status;
}
}
class WXPublicAccountPage extends PageData {
qrCodeLink: string; // 公众号二维码
rewards: string; // 口令能有的奖励
originGiftCode: string; // 加密后的口令
giftCode: string; // 加密后的口令
status: number = BIND_PHONE_STATUS.WAIT_BIND; // 状态 0-未使用 1-可领取 2-已领取
constructor(pageData: PageDataInDb) {
super(pageData);
this.originGiftCode = pageData.giftCode;
this.rewards = pageData.rewards;
}
@@ -72,6 +75,11 @@ class WXPublicAccountPage extends PageData {
this.giftCode = giftCode;
}
public setPlayerRecord(playerRecord: ActivityPublicAccountCodeType) {
if(!playerRecord) return;
this.status = playerRecord.hasReceived? BIND_PHONE_STATUS.HAS_BIND: BIND_PHONE_STATUS.RECEIVED;
}
public getShowResult() {
return pick(this, ['pageIndex', 'pageName', 'type', 'qrCodeLink', 'rewards', 'giftCode', 'status']);
}
@@ -133,15 +141,8 @@ export class BindPhoneData extends ActivityBase {
}
}
public setBindPhoneStatus(user: UserType, data: ActivityBindPhoneRewardType) {
if(this.bindPhone) {
if(user && user.channelInfo && user.channelInfo.is_phone_bind == 1) this.bindPhone.status = BIND_PHONE_STATUS.HAS_BIND;
if(data) this.bindPhone.status = data.status;
}
}
public getShowResult() {
let pages: (WXGroupPage|BindPhonePage|WXPublicAccountPage|BBSPage)[] = [];
let pages: any[] = [];
if(this.wxGroup) pages.push(this.wxGroup);
if(this.bindPhone) pages.push(this.bindPhone);
if(this.wxPublicAccount) pages.push(this.wxPublicAccount.getShowResult());

View File

@@ -419,4 +419,33 @@ export class PushMsg37Param {
public setSign(sign: string) {
this.sign = sign;
}
}
export class SendGiftCodeParam {
user_id: number; // 用户id
server_id: number; // 区服id
role_id: string; // 角色id
gift_id: string; // 礼包id
order_id: string; // 订单号
time: number; // 时间戳
sign: string; // 37给的签名
constructor(data: any) {
this.user_id = data.user_id;
this.server_id = data.server_id;
this.role_id = data.role_id;
this.gift_id = data.gift_id;
this.order_id = data.order_id;
this.time = data.time;
this.sign = data.sign;
}
checkParams() {
return this.user_id != undefined && this.server_id != undefined && this.gift_id != undefined && this.order_id != undefined && this.time != undefined && this.sign != undefined
}
getBody() {
let { user_id, server_id, role_id, gift_id, order_id, time } = this;
return { user_id, server_id, role_id, gift_id, order_id, time }
}
}

View File

@@ -49,6 +49,28 @@ export function aesDecryptcfb(data, key, iv) {
}
}
export function aes128Encrypt(input: string, key = '') {
const cipher = crypto.createCipheriv('aes-128-ecb', key, null);
let crypted = cipher.update(pkcs5_pad(input, 16), 'utf8', 'base64');
crypted += cipher.final('base64');
console.log('****aesEncryptcfb', 'input: ', input, 'crypted:', crypted)
return crypted;
}
function pkcs5_pad(text: string, blocksize: number) {
const pad = blocksize - (text.length % blocksize);
return text + String.fromCharCode(pad).repeat(pad);
}
export function aes128Decrypt(data: string, key = '') {
const decipher = crypto.createDecipheriv('aes-128-ecb', key, null);
let crypted = decipher.update(data, 'base64', 'utf8');
crypted += decipher.final('utf8');
const padding = crypted.charCodeAt(crypted.length - 1);
// console.log('****aesEncryptcfb', data, crypted)
return crypted.slice(0, -padding);;
}
export function genCode(len) {
const chars = '123456789ABCDEFGHJKLMNPQRSTWXYZabcdefghijklmnopqrstuvwxyz';
const charArr = chars.split('');