Commit 938e2edc authored by 李尚科's avatar 李尚科

fix

parent 131a7e54
Pipeline #16157 passed with stage
in 8 seconds
......@@ -43,16 +43,19 @@ class WechatController extends Controller {
const bind_phone_result = await ctx.helper.send_request(user_exist_url, { type: 5 }, { method: 'GET' });
ctx.logger.info(JSON.stringify({ bind_phone_result: bind_phone_result }));
if (bind_phone_result.status !== 200) {
ctx.redirect(redirect_url + `?channel_id=${channel_id}&type=noLogin&openid=${openid}`); return;
ctx.redirect(redirect_url + `?channel_id=${channel_id}&type=noLogin`); return;
}
const user_exist_ret = bind_phone_result.data;
if (user_exist_ret.result != 'true') {//未绑定的手机号时
ctx.redirect(redirect_url + `?channel_id=${channel_id}&type=noLogin&openid=${openid}`); return;
ctx.redirect(redirect_url + `?channel_id=${channel_id}&type=noLogin`); return;
}
const user_id = user_exist_ret.uid;
//已绑定手机的 继续 判断是否有导入公积金
await this.user_login({ code, openid, channel_id });//已绑定的用户 直接登录
const login_result = await this.user_login({ code, openid, channel_id });//已绑定的用户 直接登录
if (login_result.anew && !login_result.token) {
ctx.redirect(redirect_url + `?channel_id=${channel_id}&type=noLogin`); return;
}
const gjj_exist_url = `${this.app.config.NODE_BASE_URL}/cassandra-server/gjj/list/${user_id}`;
const gjj_exist_result = await ctx.helper.send_request(gjj_exist_url, {}, { method: 'GET' });
......@@ -155,6 +158,9 @@ class WechatController extends Controller {
}
if (!user_login_data.token || !user_login_data.uid) {
const error_msg = user_login_data.error ? user_login_data.error : '用户的登录失败';
if (error_msg === '需要重新授权') {
return { anew: 1 };
}
ctx.failed(error_msg);
}
//获取用户信息
......
'use strict';
const XML2JS = require('xml2js');
const crypto = require('crypto');
const NodeRSA = require('node-rsa')
module.exports = {
// 获取 Token
......@@ -84,7 +87,6 @@ module.exports = {
aes256_cbc_encrypt(key, data) {
const iv = '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0';
const crypto = require('crypto');
const cipher = crypto.createCipheriv('aes-256-cbc', key, iv);
let crypted = cipher.update(data, 'utf8', 'binary');
crypted += cipher.final('binary');
......@@ -94,7 +96,6 @@ module.exports = {
aes256_cbc_decrypt(key, crypted) {
const iv = '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0';
const crypto = require('crypto');
crypted = new Buffer(crypted, 'base64').toString('binary');
const decipher = crypto.createDecipheriv('aes-256-cbc', key, iv);
let decoded = decipher.update(crypted, 'binary', 'utf8');
......@@ -102,6 +103,28 @@ module.exports = {
return decoded;
},
rsaPublicDecrypt(publicKey, encryptContent) {
const public_key = new NodeRSA(publicKey);
const decrypt_data = public_key.decryptPublic(encryptContent).toString('utf8');
return decrypt_data;
},
rsaPrivateEncrypt(privateKey, content) {
const private_key = new NodeRSA(privateKey);
const encrypt_data = private_key.encryptPrivate(content, 'base64');
return encrypt_data;
},
rsaSign() {
},
rsaVerify() {
},
aes256_cbc_decrypt_weixin(key, crypted) {
let aesKey = Buffer.from(key + '=', 'base64');
......@@ -342,6 +365,7 @@ module.exports = {
PrefixInteger(num, length) {
return (Array(length).join('0') + num).slice(-length);
},
async xmlTojson(data) {
const ret_p = new Promise((resolve, reject) => {
XML2JS.parseString(data, (err, result) => {
......@@ -358,6 +382,7 @@ module.exports = {
await ret_p.then((resolve, reject) => { ret_json = resolve });
return ret_json;
},
jsonToxml(data) {
const bulider = new XML2JS.Builder();
const xml_params = bulider.buildObject(data);
......@@ -389,6 +414,32 @@ module.exports = {
location = provinece + city;
return location;
},
//延时函数
async sleep(time) {
return new Promise(function (resolve, reject) {
setTimeout(function () {
resolve('ok');
}, time);
});
},
//格式化地址
formatUrl(url, baseUrl) {
if (!baseUrl) return url;
if (url.indexOf('http') === 0) return url;
let formatUrl = '';
const baseUrlEndsWithSlash = baseUrl.endsWith('/');
const urlStartWithSlash = url.startsWith('/');
if (baseUrlEndsWithSlash && urlStartWithSlash) {
formatUrl = baseUrl + url.substring(1);
} else if (baseUrlEndsWithSlash || urlStartWithSlash) {
formatUrl = baseUrl + url;
} else {
formatUrl = baseUrl + '/' + url;
}
return formatUrl;
}
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment