起名:添加屏蔽词检测
This commit is contained in:
@@ -14,7 +14,9 @@ export const BANTU_VID_APP_KEY = '05c1c495369769e3c5d98426e9c8c2c0';
|
||||
|
||||
export enum SDK_37_ADDR {
|
||||
LOGIN = 'https://apimyh5.37.com/index.php?c=sdk-unified&a=validate',
|
||||
CHECK_CHAT = 'http://api.gamechat.37.com/checkChatV2.php'
|
||||
CHECK_CHAT = 'http://api.gamechat.37.com/checkChatV2.php',
|
||||
CHECK_NAME = 'http://api.gamechat.37.com/checkName.php',
|
||||
CHECK_UNION = 'http://api.gamechat.37.com/checkUnion.php',
|
||||
}
|
||||
export enum SDK_37_CONST {
|
||||
GAME_ID = 165, // 研发使用的GAME_ID
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType, Ref } from '@typegoose/typegoose';
|
||||
import Role, { RoleType } from './Role';
|
||||
import { genCode } from '../pubUtils/util';
|
||||
import { GUILD_STRUCTURE, GUILD_STATUS, GUILD_PER_PAGE, GUILD_SELECT, REDIS_KEY, SHOP_REFRESH_TYPE } from '../consts';
|
||||
import { getZeroPoint, getZeroPointD, nowSeconds } from '../pubUtils/timeUtil';
|
||||
import { reduceCe } from '../pubUtils/util';
|
||||
@@ -112,11 +111,11 @@ export default class Guild extends BaseModel {
|
||||
@prop({ required: true, default: 0 })
|
||||
openBossCnt: number; // 开启boss本次数
|
||||
|
||||
public static async createGuild(params: { name: string, icon: number, notice: string }, role: RoleType, serverId: number) {
|
||||
public static async createGuild(params: { guildCode: string, name: string, icon: number, notice: string }, role: RoleType, serverId: number) {
|
||||
const doc = new GuildModel();
|
||||
const update = Object.assign(doc.toJSON(), params, { leader: role._id, members: [role.roleId], guildCe: role.ce, serverId, lvUpdateTime: nowSeconds() });
|
||||
delete update._id;
|
||||
const code = genCode(6);
|
||||
const code = params.guildCode;
|
||||
const result: GuildType = await GuildModel.findOneAndUpdate({ code }, update, { upsert: true, new: true })
|
||||
.select({ _id: 0, __v: 0, createdAt: 0, updatedAt: 0 })
|
||||
.populate('leader', { roleId: 1, roleName: 1, head: 1, frame: 1, spine: 1, lv: 1, quitTime: 1, ce: 1, title: 1, _id: 0 }, 'Role')
|
||||
|
||||
@@ -259,7 +259,7 @@ export default class User extends BaseModel {
|
||||
}
|
||||
|
||||
public static async findUserByUid(uid: number) {
|
||||
const user: UserType = await UserModel.findOne({ uid }).select('uid tel channelInfo ip').lean({ getters: true });
|
||||
const user: UserType = await UserModel.findOne({ uid }).select('uid tel channelInfo channelType ip').lean({ getters: true });
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
@@ -126,6 +126,69 @@ export class Chat37Params {
|
||||
}
|
||||
}
|
||||
|
||||
setSign(sign: string) {
|
||||
this.sign = sign;
|
||||
}
|
||||
}
|
||||
|
||||
export class CheckName37Params {
|
||||
game_key: string;
|
||||
sid: number; // 游戏区
|
||||
username: number; // channelInfo.uid
|
||||
actor: string; // roleName
|
||||
actor_id: string; // roleId
|
||||
ip: string; // 玩家ip
|
||||
time: number; // unix时间戳
|
||||
sign: string;
|
||||
|
||||
constructor(role: RoleType, roleName: string, user: UserType) {
|
||||
let channelInfo = <LoginValidateData37>user.channelInfo;
|
||||
this.game_key = SDK_37_CONST.GAME_KEY;
|
||||
this.sid = role.serverId;
|
||||
this.username = channelInfo.uid;
|
||||
this.actor = roleName;
|
||||
this.actor_id = role.roleId;
|
||||
this.ip = user.ip;
|
||||
this.time = nowSeconds();
|
||||
}
|
||||
|
||||
getBody() {
|
||||
let { game_key, sid, username, actor_id, ip, time } = this;
|
||||
return {
|
||||
game_key, sid, username, actor_id, ip, time
|
||||
}
|
||||
}
|
||||
|
||||
setSign(sign: string) {
|
||||
this.sign = sign;
|
||||
}
|
||||
}
|
||||
|
||||
export class CheckGuild37Params {
|
||||
game_key: string;
|
||||
sid: number; // 游戏区
|
||||
guildid: number; // 军团code
|
||||
time: number; // unix时间戳
|
||||
sign: string;
|
||||
type: number;
|
||||
content: string; // 内容
|
||||
|
||||
constructor(guildCode: string, serverId: number, type: number, content: string) {
|
||||
this.game_key = SDK_37_CONST.GAME_KEY;
|
||||
this.sid = serverId;
|
||||
this.guildid = 10;
|
||||
this.time = nowSeconds();
|
||||
this.type = type;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
getBody() {
|
||||
let { game_key, sid, time, type } = this;
|
||||
return {
|
||||
game_key, sid, time, type
|
||||
}
|
||||
}
|
||||
|
||||
setSign(sign: string) {
|
||||
this.sign = sign;
|
||||
}
|
||||
|
||||
@@ -1,9 +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, get37Md5Sign, getVidObjSign } from "./sdkUtil";
|
||||
import { checkVidObjSign, get37CheckChatMd5Sign, get37Md5Sign, get37PostMd5Sign, getVidObjSign } from "./sdkUtil";
|
||||
import { STATUS } from '../consts'
|
||||
import { resResult } from "./util";
|
||||
import { Chat37Params, CheckGuild37Params, CheckName37Params } from "../domain/sdk";
|
||||
|
||||
// 通用,请求http
|
||||
export async function httpRequest(url: string, method: string, body: any, headers?: any, timeout = 150) {
|
||||
@@ -20,8 +21,8 @@ export async function httpRequest(url: string, method: string, body: any, header
|
||||
method,
|
||||
headers,
|
||||
body,
|
||||
json: true,
|
||||
timeout
|
||||
timeout,
|
||||
JSON: true
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -30,11 +31,41 @@ export async function httpRequest(url: string, method: string, body: any, header
|
||||
console.log(JSON.stringify(res));
|
||||
return res;
|
||||
} catch (e) {
|
||||
let code = (<RequestError>e).cause.code;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function httpRequestForm(url: string, method: string, form: any, timeout = 150) {
|
||||
console.log(`httpRequest*********: ${url}, ${method}, ${JSON.stringify(form)}`)
|
||||
|
||||
let options = {
|
||||
url,
|
||||
method,
|
||||
headers: {
|
||||
'content-type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
form,
|
||||
timeout,
|
||||
JSON: true
|
||||
}
|
||||
|
||||
try {
|
||||
let res = await request(options);
|
||||
console.log('*****request result*****');
|
||||
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 {
|
||||
console.error(e);
|
||||
return resResult(STATUS.REQUEST_TIME_OUT);
|
||||
}
|
||||
}
|
||||
@@ -117,15 +148,26 @@ export async function vidHttpRequest(addr: string, body: any) {
|
||||
export async function request37(url: string, body: any, key: string) {
|
||||
body['sign'] = get37Md5Sign(body, key);
|
||||
|
||||
let result = await httpRequest(url, HTTP_METHOD.POST, {}, body);
|
||||
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);
|
||||
export async function request37CheckChat(url: string, body: Chat37Params, key: string) {
|
||||
body.setSign(get37CheckChatMd5Sign(body, key));
|
||||
|
||||
let result = await httpRequest(url, HTTP_METHOD.GET, {}, body, 3 * 60 * 1000);
|
||||
let result = await httpRequestForm(url, HTTP_METHOD.GET, body, 3 * 60 * 1000);
|
||||
if(result != 1 && result.code != STATUS.REQUEST_TIME_OUT.code) {
|
||||
return false
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export async function request37Post(url: string, body: CheckName37Params|CheckGuild37Params, key: string) {
|
||||
body.setSign(get37PostMd5Sign(body.getBody(), key));
|
||||
|
||||
let result = await httpRequestForm(url, HTTP_METHOD.POST, body, 1 * 60 * 1000);
|
||||
console.log('*******', result != 1, result.code != STATUS.REQUEST_TIME_OUT.code)
|
||||
if(result != 1 && result.code != STATUS.REQUEST_TIME_OUT.code) {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -50,6 +50,10 @@ export function get37CheckChatMd5Sign(body: Chat37Params, key: string) {
|
||||
return md5(str);
|
||||
}
|
||||
|
||||
export function get37PostMd5Sign(body: any, key: string) {
|
||||
return getMd5ObjSign(body, '', (str) => `${str}${key}`);
|
||||
}
|
||||
|
||||
export async function loginValidate37(clientId: string, pst: string, platformAppid: string, childGameId: number) {
|
||||
let result: LoginValidataReturn37 = await request37(SDK_37_ADDR.LOGIN, {
|
||||
clientid: clientId,
|
||||
|
||||
Reference in New Issue
Block a user