登录:实名认证
This commit is contained in:
5
shared/consts/constModules/httpConst.ts
Normal file
5
shared/consts/constModules/httpConst.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export enum BANTU_VID_ADDR {
|
||||
HOST = 'https://sdks.trgame.cn',
|
||||
IDCARD = '/vid/idcard' // 实名认证
|
||||
}
|
||||
export const BANTU_VID_APP_KEY = '05c1c495369769e3c5d98426e9c8c2c0';
|
||||
@@ -6,5 +6,6 @@ export * from './constModules/itemConst';
|
||||
export * from './constModules/sysConst';
|
||||
export * from './constModules/guildConst';
|
||||
export * from './constModules/selectConst';
|
||||
export * from './constModules/httpConst';
|
||||
export * from './statusCode';
|
||||
export * from './dataName';
|
||||
@@ -21,6 +21,7 @@ export const STATUS = {
|
||||
PASSWORD_ILLEGEL: { code: 10010, simStr: '请输入密码' },
|
||||
TEL_HAS_USED: { code: 10011, simStr: '该手机号已被使用' },
|
||||
ACCOUNT_NOT_GUEST: { code: 10012, simStr: '该账号已绑定过' },
|
||||
AUTHEN_FAIL: { code: 10013, simStr: '实名失败' },
|
||||
// 战斗相关状态 20000 - 29999
|
||||
// 战斗通用 20000 - 20099
|
||||
BATTLE_MISS_INFO: { code: 20001, simStr: '缺少关卡信息' },
|
||||
|
||||
@@ -169,7 +169,7 @@ export default class User extends BaseModel {
|
||||
}
|
||||
|
||||
public static async findUserByToken(token: string, lean = true) {
|
||||
const user: UserType = await UserModel.findOne({ token }).select('uid token serverType auth tel userCode').lean(lean);
|
||||
const user: UserType = await UserModel.findOne({ token }).select('uid token serverType auth tel userCode pkgName').lean(lean);
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
82
shared/pubUtils/httpUtil.ts
Normal file
82
shared/pubUtils/httpUtil.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
import * as request from "request-promise";
|
||||
import * as crypto from 'crypto'
|
||||
import { BANTU_VID_ADDR, BANTU_VID_APP_KEY } from '@consts';
|
||||
|
||||
/**
|
||||
* 实名认证
|
||||
* @param name 真实姓名
|
||||
* @param idNum 身份证号
|
||||
* @param roleId 账号
|
||||
* @param packageName 包名
|
||||
*/
|
||||
export async function authenticate (name: string, idNum: string, roleId: string, packageName: string) {
|
||||
if(!packageName || packageName==''){
|
||||
packageName = 'com.bantu.nfsg'
|
||||
}
|
||||
|
||||
let result = await vidHttpRequest(BANTU_VID_ADDR.IDCARD, {
|
||||
account: roleId,
|
||||
cardno: idNum,
|
||||
name,
|
||||
appkey: BANTU_VID_APP_KEY,
|
||||
package: packageName
|
||||
});
|
||||
if(result && result.code !== 1) {
|
||||
console.error(result.msg);
|
||||
}
|
||||
|
||||
return result && result.code == 1;
|
||||
}
|
||||
|
||||
export async function vidHttpRequest(addr: string, body: any) {
|
||||
body['sign'] = getObjSign(body);
|
||||
console.log('body: ', JSON.stringify(body))
|
||||
|
||||
let options = {
|
||||
url: BANTU_VID_ADDR.HOST + addr,
|
||||
method: 'POST',
|
||||
body:body,
|
||||
json: true
|
||||
}
|
||||
|
||||
try {
|
||||
let res = await request(options);
|
||||
let check = checkSign(res);
|
||||
if(!check) return false;
|
||||
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) {
|
||||
const str = [];
|
||||
Object.keys(obj).sort().forEach((key) => {
|
||||
if (key == 'sign') {
|
||||
|
||||
} else {
|
||||
str.push(key + '=' + obj[key]);
|
||||
}
|
||||
});
|
||||
if (str.length == 0) {
|
||||
console.error('check obj', obj);
|
||||
}
|
||||
var strs = str.join('');
|
||||
return md5Vid(strs);
|
||||
}
|
||||
|
||||
export async function checkSign (obj: any) {
|
||||
if (getObjSign(obj) === obj.sign) {
|
||||
return true;
|
||||
}
|
||||
console.warn('correct sign:', getObjSign(obj), obj.sign);
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user