web-server 注册、登录、获取服务器列表;game-server token 校验
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { TURBO_CORE_URL, APP_ID, PARM_SECRET } from './../consts/consts';
|
||||
import { TURBO_CORE_URL, APP_ID, TURBO_PARM_SECRET } from './../consts/consts';
|
||||
import { Service } from 'egg';
|
||||
const crypto = require('crypto');
|
||||
/**
|
||||
@@ -7,31 +7,56 @@ const crypto = require('crypto');
|
||||
export default class TurboCore extends Service {
|
||||
|
||||
/**
|
||||
* sayHi to you
|
||||
* @param name - your name
|
||||
* 用户获取手机验证码
|
||||
* @param telNo - 用户手机号
|
||||
*/
|
||||
|
||||
public async getSms(telNo: string) {
|
||||
const ctx = this.ctx;
|
||||
let body = {
|
||||
'telNo':telNo
|
||||
}
|
||||
telNo
|
||||
};
|
||||
const result = await ctx.curl(`${TURBO_CORE_URL}/user/getSms`, {
|
||||
// 必须指定 method
|
||||
method: 'POST',
|
||||
// 通过 contentType 告诉 HttpClient 以 JSON 格式发送
|
||||
contentType: 'json',
|
||||
headers: {
|
||||
'AppId': APP_ID,
|
||||
'sign': this.getTurboSign( body, PARM_SECRET)
|
||||
'sign': this.getTurboSign( body, TURBO_PARM_SECRET)
|
||||
},
|
||||
data: body,
|
||||
// 明确告诉 HttpClient 以 JSON 格式处理返回的响应 body
|
||||
dataType: 'json',
|
||||
});
|
||||
return result.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户获取到手机验证码之后发送验证登录请求
|
||||
* @param telNo 登录手机号
|
||||
* @param code 登录验证码
|
||||
*/
|
||||
public async smsLogin(telNo: string, code: string) {
|
||||
const ctx = this.ctx;
|
||||
let body = {
|
||||
telNo, code
|
||||
};
|
||||
const result = await ctx.curl(`${TURBO_CORE_URL}/user/getSms`, {
|
||||
method: 'POST',
|
||||
contentType: 'json',
|
||||
headers: {
|
||||
'AppId': APP_ID,
|
||||
'sign': this.getTurboSign( body, TURBO_PARM_SECRET)
|
||||
},
|
||||
data: body,
|
||||
dataType: 'json',
|
||||
});
|
||||
return result.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取多宝规则下的参数签名
|
||||
* @param params 参数列表
|
||||
* @param secret 密钥
|
||||
*/
|
||||
private getTurboSign(params, secret) {
|
||||
let paramsString = this.joinParamsStr(params);
|
||||
let stringToSign = paramsString;
|
||||
@@ -46,6 +71,10 @@ export default class TurboCore extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将参数组合成字符串
|
||||
* @param params 参数列表
|
||||
*/
|
||||
private joinParamsStr(params) {
|
||||
let signString = Object.keys(params).filter(function (key) {
|
||||
return params[key] !== undefined && params[key] !== '' && ['pfx', 'partner_key', 'sign', 'key'].indexOf(key) < 0;
|
||||
|
||||
Reference in New Issue
Block a user