登录:实名认证
This commit is contained in:
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