Commit ef964c83 authored by 方斌's avatar 方斌
parents d37c7e6a fcd6346b
Pipeline #16216 passed with stage
in 57 seconds
...@@ -35,24 +35,33 @@ class WechatController extends Controller { ...@@ -35,24 +35,33 @@ class WechatController extends Controller {
ctx.failed('获取openid失败2'); ctx.failed('获取openid失败2');
} }
const openid = wx_ret.openid; const openid = wx_ret.openid;
//在微信端需要关闭微信重新打开才会销毁cookie值,所以在这里重置cookie值
ctx.cookies.set('openid', openid, { httpOnly: false, signed: false, path: '/', overwrite: true }); ctx.cookies.set('openid', openid, { httpOnly: false, signed: false, path: '/', overwrite: true });
ctx.cookies.set('token', null, { httpOnly: false, signed: false, path: '/', overwrite: true });
ctx.cookies.set('user_id', null, { httpOnly: false, signed: false, path: '/', overwrite: true });
ctx.cookies.set('app_user_id', null, { httpOnly: false, signed: false, path: '/', overwrite: true });
ctx.cookies.set('jianbing_customer_id', null, { httpOnly: false, signed: false, path: '/', overwrite: true });
ctx.cookies.set('auth_token', null, { httpOnly: false, signed: false, path: '/', overwrite: true });
const redirect_url = this.app.config.PULIC_BASE_URL + REDIRECT_PAGE; const redirect_url = this.app.config.PULIC_BASE_URL + REDIRECT_PAGE;
//判断是否已绑定手机号 //判断是否已绑定手机号
const user_exist_url = `${this.app.config.NODE_BASE_URL}/user_api/v1/user/is_exist/${openid}`; const user_exist_url = `${this.app.config.NODE_BASE_URL}/user_api/v1/user/is_exist/${openid}`;
const bind_phone_result = await ctx.helper.send_request(user_exist_url, { type: 5 }, { method: 'GET' }); 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 })); ctx.logger.info(JSON.stringify({ bind_phone_result: bind_phone_result }));
if (bind_phone_result.status !== 200) { 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; const user_exist_ret = bind_phone_result.data;
if (user_exist_ret.result != 'true') {//未绑定的手机号时 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; 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_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' }); const gjj_exist_result = await ctx.helper.send_request(gjj_exist_url, {}, { method: 'GET' });
...@@ -155,6 +164,9 @@ class WechatController extends Controller { ...@@ -155,6 +164,9 @@ class WechatController extends Controller {
} }
if (!user_login_data.token || !user_login_data.uid) { if (!user_login_data.token || !user_login_data.uid) {
const error_msg = user_login_data.error ? user_login_data.error : '用户的登录失败'; const error_msg = user_login_data.error ? user_login_data.error : '用户的登录失败';
if (error_msg === '需要重新授权') {
return { anew: 1 };
}
ctx.failed(error_msg); ctx.failed(error_msg);
} }
//获取用户信息 //获取用户信息
......
'use strict'; 'use strict';
const XML2JS = require('xml2js'); const XML2JS = require('xml2js');
const crypto = require('crypto');
const NodeRSA = require('node-rsa')
module.exports = { module.exports = {
// 获取 Token // 获取 Token
...@@ -84,7 +87,6 @@ module.exports = { ...@@ -84,7 +87,6 @@ module.exports = {
aes256_cbc_encrypt(key, data) { aes256_cbc_encrypt(key, data) {
const iv = '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0'; 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); const cipher = crypto.createCipheriv('aes-256-cbc', key, iv);
let crypted = cipher.update(data, 'utf8', 'binary'); let crypted = cipher.update(data, 'utf8', 'binary');
crypted += cipher.final('binary'); crypted += cipher.final('binary');
...@@ -94,7 +96,6 @@ module.exports = { ...@@ -94,7 +96,6 @@ module.exports = {
aes256_cbc_decrypt(key, crypted) { aes256_cbc_decrypt(key, crypted) {
const iv = '\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0'; 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'); crypted = new Buffer(crypted, 'base64').toString('binary');
const decipher = crypto.createDecipheriv('aes-256-cbc', key, iv); const decipher = crypto.createDecipheriv('aes-256-cbc', key, iv);
let decoded = decipher.update(crypted, 'binary', 'utf8'); let decoded = decipher.update(crypted, 'binary', 'utf8');
...@@ -102,6 +103,28 @@ module.exports = { ...@@ -102,6 +103,28 @@ module.exports = {
return decoded; 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) { aes256_cbc_decrypt_weixin(key, crypted) {
let aesKey = Buffer.from(key + '=', 'base64'); let aesKey = Buffer.from(key + '=', 'base64');
...@@ -342,6 +365,7 @@ module.exports = { ...@@ -342,6 +365,7 @@ module.exports = {
PrefixInteger(num, length) { PrefixInteger(num, length) {
return (Array(length).join('0') + num).slice(-length); return (Array(length).join('0') + num).slice(-length);
}, },
async xmlTojson(data) { async xmlTojson(data) {
const ret_p = new Promise((resolve, reject) => { const ret_p = new Promise((resolve, reject) => {
XML2JS.parseString(data, (err, result) => { XML2JS.parseString(data, (err, result) => {
...@@ -358,6 +382,7 @@ module.exports = { ...@@ -358,6 +382,7 @@ module.exports = {
await ret_p.then((resolve, reject) => { ret_json = resolve }); await ret_p.then((resolve, reject) => { ret_json = resolve });
return ret_json; return ret_json;
}, },
jsonToxml(data) { jsonToxml(data) {
const bulider = new XML2JS.Builder(); const bulider = new XML2JS.Builder();
const xml_params = bulider.buildObject(data); const xml_params = bulider.buildObject(data);
...@@ -389,6 +414,32 @@ module.exports = { ...@@ -389,6 +414,32 @@ module.exports = {
location = provinece + city; location = provinece + city;
return location; 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