推送:接入个推推送接口
This commit is contained in:
+35
-12
@@ -7,8 +7,8 @@ import { BANTU_VID_ADDR, BANTU_VID_APP_KEY } from '../consts';
|
||||
* @param userCode 账号
|
||||
* @param packageName 包名
|
||||
*/
|
||||
export async function reportOnline ( userCode: string, packageName: string) {
|
||||
if(!packageName || packageName==''){
|
||||
export async function reportOnline(userCode: string, packageName: string) {
|
||||
if (!packageName || packageName == '') {
|
||||
packageName = 'com.bantu.nfsg'
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ export async function reportOnline ( userCode: string, packageName: string) {
|
||||
account: userCode,
|
||||
package: packageName
|
||||
});
|
||||
if(result && result.code !== 1) {
|
||||
if (result && result.code !== 1) {
|
||||
console.error(result.msg);
|
||||
}
|
||||
|
||||
@@ -30,8 +30,8 @@ export async function reportOnline ( userCode: string, packageName: string) {
|
||||
* @param userCode 账号
|
||||
* @param packageName 包名
|
||||
*/
|
||||
export async function authenticate (name: string, idNum: string, userCode: string, packageName: string) {
|
||||
if(!packageName || packageName==''){
|
||||
export async function authenticate(name: string, idNum: string, userCode: string, packageName: string) {
|
||||
if (!packageName || packageName == '') {
|
||||
packageName = 'com.bantu.nfsg'
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ export async function authenticate (name: string, idNum: string, userCode: strin
|
||||
appkey: BANTU_VID_APP_KEY,
|
||||
package: packageName
|
||||
});
|
||||
if(result && result.code !== 1) {
|
||||
if (result && result.code !== 1) {
|
||||
console.error(result.msg);
|
||||
}
|
||||
|
||||
@@ -56,29 +56,52 @@ export async function vidHttpRequest(addr: string, body: any) {
|
||||
let options = {
|
||||
url: BANTU_VID_ADDR.HOST + addr,
|
||||
method: 'POST',
|
||||
body:body,
|
||||
body: body,
|
||||
json: true
|
||||
}
|
||||
|
||||
try {
|
||||
let res = await request(options);
|
||||
let check = checkSign(res);
|
||||
if(!check) return false;
|
||||
if (!check) return false;
|
||||
// console.log('*****request result*****');
|
||||
// console.log(JSON.stringify(res));
|
||||
return res;
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export function md5Vid (str: string) {
|
||||
|
||||
export async function httpRequest(url: string, method: string, headers: any, body: any) {
|
||||
console.log(`httpRequest*********: ${url}, ${method}, ${JSON.stringify(headers)}, ${JSON.stringify(body)}`)
|
||||
|
||||
let options = {
|
||||
url,
|
||||
method,
|
||||
headers,
|
||||
body,
|
||||
json: true
|
||||
}
|
||||
|
||||
try {
|
||||
let res = await request(options);
|
||||
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) {
|
||||
export function getObjSign(obj: any) {
|
||||
const str = [];
|
||||
Object.keys(obj).sort().forEach((key) => {
|
||||
if (key == 'sign') {
|
||||
@@ -94,7 +117,7 @@ export function getObjSign (obj: any) {
|
||||
return md5Vid(strs);
|
||||
}
|
||||
|
||||
export async function checkSign (obj: any) {
|
||||
export async function checkSign(obj: any) {
|
||||
if (getObjSign(obj) === obj.sign) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user