sdk:根据玩家获取军团信息
This commit is contained in:
@@ -464,4 +464,14 @@ export const PAY_37_CALLBACK_CODE = {
|
||||
WRONG_PARAM: { code: -8, simStr: '参数错误' },
|
||||
SERVER_NOT_FOUND: { code: -9, simStr: '游戏服不存在' },
|
||||
PAY_ERR: { code: 10, simStr: '充值失败' }
|
||||
}
|
||||
|
||||
export const SDK_37_TREAT_CODE = {
|
||||
SUCCESS: { code: 1, simStr: '成功' },
|
||||
WRONG_PARAMS: { code: -1, simStr: '参数错误' },
|
||||
SIGN_ERR: { code: -2, simStr: '签名错误' },
|
||||
TIME_IS_EXPIRED: { code: -3, simStr: 'time时间已过期' },
|
||||
ERR: { code: -4, simStr: '其他错误' },
|
||||
USER_NOT_FOUND: { code: -5, simStr: '用户不存在' },
|
||||
ROLE_NOT_FOUND: { code: -6, simStr: '角色不存在' },
|
||||
}
|
||||
@@ -52,7 +52,7 @@ export interface LoginValidataReturn37 {
|
||||
|
||||
export type ChannelInfo = LoginValidataReturn37|{};
|
||||
|
||||
export interface PayCallback37Data {
|
||||
export class PayCallback37Data {
|
||||
appid: string; // 平台id
|
||||
uid: number; // 37用户id
|
||||
game_id: number; // 游戏id
|
||||
@@ -67,6 +67,29 @@ export interface PayCallback37Data {
|
||||
time: number; // 请求时间
|
||||
ext: string; // 扩展参数
|
||||
sign: string;
|
||||
|
||||
constructor(params: PayCallback37Data) {
|
||||
this.appid = params.appid;
|
||||
this.uid = params.uid;
|
||||
this.game_id = params.game_id;
|
||||
this.fc_c_game_id = params.fc_c_game_id;
|
||||
this.sid = params.sid;
|
||||
this.actor_id = params.actor_id;
|
||||
this.order_id = params.order_id;
|
||||
this.order_no = params.order_no;
|
||||
this.money = params.money;
|
||||
this.game_coin = params.game_coin;
|
||||
this.product_id = params.product_id;
|
||||
this.time = params.time;
|
||||
this.ext = params.ext;
|
||||
this.sign = params.sign;
|
||||
}
|
||||
|
||||
getBody() {
|
||||
let { appid, uid, game_id, sid, actor_id, order_id, order_no, money, game_coin, product_id, time, ext } = this;
|
||||
return { appid, uid, game_id, sid, actor_id, order_id, order_no, money, game_coin, product_id, time, ext }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class Chat37Params {
|
||||
@@ -192,4 +215,85 @@ export class CheckGuild37Params {
|
||||
setSign(sign: string) {
|
||||
this.sign = sign;
|
||||
}
|
||||
}
|
||||
|
||||
export class RoleNameCallBackParam {
|
||||
username: number; // 玩家账号
|
||||
game_key: string; // 游戏标识
|
||||
sid: number; // 区服标识
|
||||
actor: string; // 玩家角色名称
|
||||
actor_id: string; // 玩家角色名id
|
||||
time: number; // 时间戳
|
||||
sign: string;
|
||||
|
||||
constructor(param: RoleNameCallBackParam) {
|
||||
this.username = param.username;
|
||||
this.game_key = param.game_key;
|
||||
this.sid = param.sid;
|
||||
this.actor = param.actor;
|
||||
this.actor_id = param.actor_id;
|
||||
this.time = param.time;
|
||||
this.sign = param.sign;
|
||||
}
|
||||
|
||||
checkParams() {
|
||||
return this.username != undefined && this.game_key != undefined && this.sid != undefined && this.actor != undefined && this.actor_id != undefined && this.time != undefined && this.sign != undefined
|
||||
}
|
||||
|
||||
getBody() {
|
||||
let { username, game_key, sid, actor_id, time } = this;
|
||||
return { username, game_key, sid, actor_id, time }
|
||||
}
|
||||
}
|
||||
|
||||
export class GuildNameCallBackParam {
|
||||
game_key: string; // 游戏标识
|
||||
sid: number; // 区服标识
|
||||
type: number; // 类型 1-公会名 2-公会公告
|
||||
guildid: string; // 公会id
|
||||
time: number; // 时间戳
|
||||
sign: string;
|
||||
|
||||
constructor(param: GuildNameCallBackParam) {
|
||||
this.game_key = param.game_key;
|
||||
this.sid = param.sid;
|
||||
this.type = param.type;
|
||||
this.guildid = param.guildid;
|
||||
this.time = param.time;
|
||||
this.sign = param.sign;
|
||||
}
|
||||
|
||||
checkParams() {
|
||||
return this.game_key != undefined && this.sid != undefined && this.type != undefined && this.guildid != undefined && this.time != undefined && this.sign != undefined
|
||||
}
|
||||
|
||||
getBody() {
|
||||
let { game_key, sid, type, guildid, time, sign } = this;
|
||||
return { game_key, sid, type, guildid, time, sign }
|
||||
}
|
||||
}
|
||||
|
||||
export class GetGuildInfoByUserParam {
|
||||
game_key: string; // 游戏标识
|
||||
uid: number; // 账号名
|
||||
time: number; // 时间戳
|
||||
sid: number; // 区服id
|
||||
sign: string;
|
||||
|
||||
constructor(param: GetGuildInfoByUserParam) {
|
||||
this.game_key = param.game_key;
|
||||
this.uid = param.uid;
|
||||
this.time = param.time;
|
||||
this.sid = param.sid;
|
||||
this.sign = param.sign;
|
||||
}
|
||||
|
||||
checkParams() {
|
||||
return this.game_key != undefined && this.uid != undefined && this.sid != undefined && this.time != undefined && this.sign != undefined
|
||||
}
|
||||
|
||||
getBody() {
|
||||
let { game_key, sid, uid, time, sign } = this;
|
||||
return { game_key, sid, uid, time, sign }
|
||||
}
|
||||
}
|
||||
@@ -236,5 +236,5 @@ export const GK_MAINELITE = {
|
||||
};
|
||||
export const SERVER_DEBUG_MODE = {
|
||||
CURRENT_TIME: 1, // 服务器是否打开推送时间debug模式
|
||||
CHECK_WORD: 0, // 服务器是否打开聊天屏蔽
|
||||
CHECK_WORD: 1, // 服务器是否打开聊天屏蔽
|
||||
};
|
||||
|
||||
@@ -80,7 +80,7 @@ export async function loginValidata(channelType: string, params: { clientId: str
|
||||
}
|
||||
|
||||
export function getChannelId(channelType: string, uid: number|string) {
|
||||
return `${channelType}: ${uid}`;
|
||||
return `${channelType}_${uid}`;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -182,5 +182,9 @@
|
||||
{
|
||||
"channel": "37",
|
||||
"ip": "221.5.32.28"
|
||||
},
|
||||
{
|
||||
"channel": "local",
|
||||
"ip": "::1"
|
||||
}
|
||||
]
|
||||
@@ -1,32 +1,26 @@
|
||||
import { STATUS } from '@consts';
|
||||
import { httpRequest } from 'app/pubUtils/httpUtil';
|
||||
import { Controller } from 'egg';
|
||||
import { PayCallback37Data } from '../domain/sdk';
|
||||
import { GetGuildInfoByUserParam, GuildNameCallBackParam, PayCallback37Data, RoleNameCallBackParam } from '../domain/sdk';
|
||||
|
||||
export default class SdkController extends Controller {
|
||||
|
||||
public async pay37Callback() {
|
||||
const { ctx } = this;
|
||||
const params: PayCallback37Data = ctx.request.body;
|
||||
const params = new PayCallback37Data(ctx.request.body);
|
||||
ctx.body = await ctx.service.sdk.pay37Callback(params);
|
||||
return;
|
||||
}
|
||||
|
||||
public async treatRoleName() {
|
||||
const { ctx } = this;
|
||||
|
||||
|
||||
let test = await httpRequest('http://127.0.0.1:7001/cb/treatguildname', "POST", {}, null);
|
||||
console.log('result: ', typeof test, test);
|
||||
ctx.body = ctx.service.utils.resResult(STATUS.SUCCESS, '');
|
||||
const params = new RoleNameCallBackParam(ctx.request.body);
|
||||
ctx.body = await ctx.service.sdk.treatRoleName(params);
|
||||
return;
|
||||
}
|
||||
|
||||
public async treatGuildName() {
|
||||
const { ctx } = this;
|
||||
const params = ctx.request.body;
|
||||
console.log(params)
|
||||
ctx.body = ctx.service.utils.resResult(STATUS.SUCCESS, '');
|
||||
const params = new GuildNameCallBackParam(ctx.request.body);
|
||||
ctx.body = await ctx.service.sdk.treatGuildName(params);
|
||||
return;
|
||||
|
||||
}
|
||||
@@ -34,7 +28,8 @@ export default class SdkController extends Controller {
|
||||
public async getGuildByUser() {
|
||||
const { ctx } = this;
|
||||
|
||||
ctx.body = ctx.service.utils.resResult(STATUS.SUCCESS, '');
|
||||
const params = new GetGuildInfoByUserParam(ctx.request.body);
|
||||
ctx.body = await ctx.service.sdk.getGuildByUser(params);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,8 @@ export default (app: Application) => {
|
||||
|
||||
// sdk 回调
|
||||
router.post('/cb/pay37callback', controller.sdk.pay37Callback);
|
||||
router.post('/cb/treatusername', controller.sdk.treatRoleName);
|
||||
router.post('/cb/treatguildname', controller.sdk.treatGuildName);
|
||||
router.post('/cb/getguildbyuser', controller.sdk.getGuildByUser);
|
||||
router.get('/cb/treatusername', controller.sdk.treatRoleName);
|
||||
router.get('/cb/treatguildname', controller.sdk.treatGuildName);
|
||||
router.get('/cb/getguildbyuser', controller.sdk.getGuildByUser);
|
||||
|
||||
};
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
|
||||
import { Service } from 'egg';
|
||||
import { REDIS_KEY, PAY_37_CALLBACK_CODE, SDK_37_CONST, ORDER_STATE, } from '@consts';
|
||||
import { PayCallback37Data } from '../domain/sdk';
|
||||
import { REDIS_KEY, PAY_37_CALLBACK_CODE, SDK_37_CONST, ORDER_STATE, SDK_37_TREAT_CODE } from '@consts';
|
||||
import { GetGuildInfoByUserParam, GuildNameCallBackParam, PayCallback37Data, RoleNameCallBackParam } from '../domain/sdk';
|
||||
import { RedisClient } from 'redis';
|
||||
import { get37Md5Sign, getRedisSubChannel } from '../pubUtils/sdkUtil';
|
||||
import { pick } from 'underscore';
|
||||
import { get37Md5Sign, get37PostMd5Sign, getChannelId, getRedisSubChannel } from '../pubUtils/sdkUtil';
|
||||
import { UserOrderModel } from '@db/UserOrder';
|
||||
import { nowSeconds } from 'app/pubUtils/timeUtil';
|
||||
import { RoleModel } from '@db/Role';
|
||||
import { gameData } from 'app/pubUtils/data';
|
||||
import { resResult } from 'app/pubUtils/util';
|
||||
import { UserModel } from '@db/User';
|
||||
import { UserGuildModel } from '@db/UserGuild';
|
||||
import { GuildModel } from '@db/Guild';
|
||||
|
||||
/**
|
||||
* Test Service
|
||||
@@ -16,8 +19,7 @@ import { gameData } from 'app/pubUtils/data';
|
||||
export default class Sdk extends Service {
|
||||
|
||||
public check37Sign(params: PayCallback37Data) {
|
||||
let body = pick(params, ['appid', 'uid', 'game_id', 'sid', 'actor_id', 'order_id', 'order_no', 'money', 'game_coin', 'product_id', 'time', 'ext']);
|
||||
let sign = get37Md5Sign(body, SDK_37_CONST.PAY_KEY);
|
||||
let sign = get37Md5Sign(params.getBody, SDK_37_CONST.PAY_KEY);
|
||||
console.log('******37Sign', sign);
|
||||
return sign == params.sign;
|
||||
}
|
||||
@@ -27,7 +29,7 @@ export default class Sdk extends Service {
|
||||
const { app } = ctx;
|
||||
const ip = ctx.request.ip;
|
||||
|
||||
let checkResult = ctx.service.sdk.check37Sign(params);
|
||||
let checkResult = this.check37Sign(params);
|
||||
if(!checkResult) return ctx.service.utils.resResult(PAY_37_CALLBACK_CODE.MD5_ERR, '');
|
||||
|
||||
if(gameData.whiteip.indexOf(ip) == -1) {
|
||||
@@ -75,4 +77,72 @@ export default class Sdk extends Service {
|
||||
}
|
||||
|
||||
|
||||
public check37WordsSign(params: RoleNameCallBackParam|GuildNameCallBackParam|GetGuildInfoByUserParam) {
|
||||
let sign = get37PostMd5Sign(params.getBody(), SDK_37_CONST.CHAT_KEY);
|
||||
console.log('******37Sign', sign);
|
||||
return sign == params.sign;
|
||||
}
|
||||
|
||||
public treatRoleOrGuildNameValidate(params: RoleNameCallBackParam|GuildNameCallBackParam|GetGuildInfoByUserParam) {
|
||||
const { ctx } = this;
|
||||
const ip = ctx.request.ip;
|
||||
|
||||
if(!params.checkParams()) return SDK_37_TREAT_CODE.WRONG_PARAMS;
|
||||
|
||||
if(params.game_key != SDK_37_CONST.GAME_KEY) {
|
||||
return SDK_37_TREAT_CODE.ERR;
|
||||
}
|
||||
|
||||
let checkResult = this.check37WordsSign(params);
|
||||
if(!checkResult) return SDK_37_TREAT_CODE.SIGN_ERR;
|
||||
|
||||
if(nowSeconds() - params.time > 15 * 60) {
|
||||
return SDK_37_TREAT_CODE.TIME_IS_EXPIRED;
|
||||
}
|
||||
|
||||
if(gameData.whiteip.indexOf(ip) == -1) {
|
||||
return SDK_37_TREAT_CODE.ERR;
|
||||
}
|
||||
return SDK_37_TREAT_CODE.SUCCESS
|
||||
}
|
||||
|
||||
// 用户名违规处理
|
||||
public async treatRoleName(params: RoleNameCallBackParam) {
|
||||
let check = this.treatRoleOrGuildNameValidate(params);
|
||||
if(check.code != SDK_37_TREAT_CODE.SUCCESS.code) return check.code;
|
||||
|
||||
return check.code
|
||||
}
|
||||
|
||||
// 公会信息违规处理
|
||||
public async treatGuildName(params: GuildNameCallBackParam) {
|
||||
let check = this.treatRoleOrGuildNameValidate(params);
|
||||
if(check.code != SDK_37_TREAT_CODE.SUCCESS.code) return check.code;
|
||||
|
||||
return check.code
|
||||
}
|
||||
|
||||
// 根据玩家获得公会信息
|
||||
public async getGuildByUser(params: GetGuildInfoByUserParam) {
|
||||
let check = this.treatRoleOrGuildNameValidate(params);
|
||||
if(check.code != SDK_37_TREAT_CODE.SUCCESS.code) return resResult(check);
|
||||
|
||||
let channelId = getChannelId('37', params.uid);
|
||||
console.log(channelId)
|
||||
let user = await UserModel.findUserByChannel(channelId);
|
||||
if(!user) return resResult(SDK_37_TREAT_CODE.USER_NOT_FOUND);
|
||||
|
||||
let role = await RoleModel.findByUid(user.uid, params.sid);
|
||||
if(!role) return resResult(SDK_37_TREAT_CODE.ROLE_NOT_FOUND);
|
||||
|
||||
let userGuild = await UserGuildModel.getMyGuild(role.roleId);
|
||||
if(userGuild) {
|
||||
let guild = await GuildModel.findByCode(userGuild.guildCode, params.sid);
|
||||
if(guild) {
|
||||
return resResult(check, [{ guildid: guild.code, guild_name: guild.name }]);
|
||||
}
|
||||
}
|
||||
|
||||
return resResult(check, []);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user