Commit 100e1921 authored by 李尚科's avatar 李尚科

Fix

parent 04d781ac
Pipeline #15193 passed with stage
in 7 seconds
...@@ -6,33 +6,36 @@ const WECHAT_AUTH = 'https://api.weixin.qq.com/sns/oauth2/access_token'; ...@@ -6,33 +6,36 @@ const WECHAT_AUTH = 'https://api.weixin.qq.com/sns/oauth2/access_token';
const WECHAT_APPID = ''; const WECHAT_APPID = '';
const WECHAT_SECRET = ''; const WECHAT_SECRET = '';
const NO_GJJ_PAGE = 'https://www.baidu.com'; const NO_GJJ_PAGE = 'https://www.baidu.com';
const GJJ_DETAIL_PAGE = 'https:www.jianbing.com'; const GJJ_DETAIL_PAGE = 'https://www.jianbing.com';
class WechatController extends Controller { class WechatController extends Controller {
//公众号公积金查询H5授权跳转
async oauthLogin() { async oauthLogin() {
const { ctx } = this; const { ctx } = this;
const code = ctx.query.code; const code = ctx.query.code;
const channel_id = ctx.query.channel_id; const channel_id = ctx.query.channel_id;
if (!code || code.length === 0) { // if (!code || code.length === 0) {
const target_url = WECHAT_CODE_URL + `?appid=${WECHAT_APPID}&redirect_uri=${encodeURIComponent(`https://p.jianbing.com/51ucenter/api/user/oauth?&channel_id=${channel_id}`)}&response_type=code&scope=snsapi_base&state=gjjquery#wechat_redirect`; // const target_url = WECHAT_CODE_URL + `?appid=${WECHAT_APPID}&redirect_uri=${encodeURIComponent(`https://p.jianbing.com/51ucenter/api/user/oauth?&channel_id=${channel_id}`)}&response_type=code&scope=snsapi_base&state=gjjquery#wechat_redirect`;
ctx.redirect(target_url); // ctx.redirect(target_url);
} // }
const url = `${WECHAT_AUTH}?appid=${WECHAT_APPID}&secret=${WECHAT_SECRET}&code=${code}&grant_type=authorization_code` // const url = `${WECHAT_AUTH}?appid=${WECHAT_APPID}&secret=${WECHAT_SECRET}&code=${code}&grant_type=authorization_code`
const result = await ctx.helper.send_request(url, {}, { method: 'GET' }); // const result = await ctx.helper.send_request(url, {}, { method: 'GET' });
if (result.status !== 200) { // if (result.status !== 200) {
ctx.failed('获取openid失败'); // ctx.failed('获取openid失败');
} // }
const wx_ret = result.data; // const wx_ret = result.data;
if (!wx_ret.openid) { // if (!wx_ret.openid) {
ctx.failed('获取openid失败'); // ctx.failed('获取openid失败');
} // }
const openid = wx_ret.openid; // const openid = wx_ret.openid;
const openid = 'lishangke';
//判断是否已绑定手机号 //判断是否已绑定手机号
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, {}, { 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 }));
if (bind_phone_result.status !== 200) { if (bind_phone_result.status !== 200) {
ctx.redirect(NO_GJJ_PAGE); return; ctx.redirect(NO_GJJ_PAGE); return;
} }
...@@ -44,12 +47,13 @@ class WechatController extends Controller { ...@@ -44,12 +47,13 @@ class WechatController extends Controller {
//判断是否有导入公积金 //判断是否有导入公积金
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' });
ctx.logger.info(JSON.stringify({ gjj_exist_result: gjj_exist_result }));
if (gjj_exist_result.status !== 200) { if (gjj_exist_result.status !== 200) {
ctx.redirect(NO_GJJ_PAGE); return; ctx.redirect(NO_GJJ_PAGE); return;
} }
const gjj_exist_ret = gjj_exist_result.data; const gjj_exist_ret = gjj_exist_result.data;
if (!gjj_exist_ret.ret || gjj_exist_ret.ret.length === 0) {//没有导入公积金时 if (!gjj_exist_ret.ret || gjj_exist_ret.ret.length === 0) {//没有导入公积金时
ctx.redirect(NO_GJJ_PAGE); return; // ctx.redirect(NO_GJJ_PAGE); return;
} }
await this.user_login({ code, openid, channel_id });//用户直接登录 await this.user_login({ code, openid, channel_id });//用户直接登录
...@@ -57,6 +61,22 @@ class WechatController extends Controller { ...@@ -57,6 +61,22 @@ class WechatController extends Controller {
ctx.redirect(GJJ_DETAIL_PAGE); return; ctx.redirect(GJJ_DETAIL_PAGE); return;
} }
//判断是否有公积金导入并跳转
async checkGjj() {
const { ctx } = this;
const user_id = ctx.userId;
//判断是否有导入公积金
console.info(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' });
ctx.logger.info(JSON.stringify({ gjj_exist_result: gjj_exist_result }));
if (gjj_exist_result.status !== 200) {
ctx.redirect(NO_GJJ_PAGE); return;
}
ctx.redirect(GJJ_DETAIL_PAGE); return;
}
async checkLogin() { async checkLogin() {
const { ctx } = this; const { ctx } = this;
...@@ -65,11 +85,13 @@ class WechatController extends Controller { ...@@ -65,11 +85,13 @@ class WechatController extends Controller {
if (user_id) { if (user_id) {
is_login = true; is_login = true;
} }
const phone = await ctx.helper.getPhoneCity('15968762898'); // const phone = await ctx.helper.getPhoneCity('15968762898');
ctx.success({ result: is_login, phone }); ctx.success({ result: is_login });
} }
async user_login(params){
async user_login(params) {
const { ctx } = this; const { ctx } = this;
const { code, openid, channel_id } = params; const { code, openid, channel_id } = params;
...@@ -78,7 +100,7 @@ class WechatController extends Controller { ...@@ -78,7 +100,7 @@ class WechatController extends Controller {
const ip = ctx.helper.getClientIP(); const ip = ctx.helper.getClientIP();
const past_deviceno = ctx.helper.md5(user_agent + ip); const past_deviceno = ctx.helper.md5(user_agent + ip);
const app_channel_info = await ctx.poseidonModel.AppChannel.one({ where: { alias: channel_id } }); const app_channel_info = await ctx.blockModel.AppChannel.one({ where: { alias: channel_id } });
if (!app_channel_info || Object.keys(app_channel_info).length === 0) { if (!app_channel_info || Object.keys(app_channel_info).length === 0) {
ctx.failed('渠道未配置'); ctx.failed('渠道未配置');
} }
...@@ -109,16 +131,17 @@ class WechatController extends Controller { ...@@ -109,16 +131,17 @@ class WechatController extends Controller {
const user_login_params = {//用户登录传递的参数 const user_login_params = {//用户登录传递的参数
past_deviceno: past_deviceno,//使用设备码+时间+随机数产生的一个尽量避免重复的字符串,类似游客版h5登 past_deviceno: past_deviceno,//使用设备码+时间+随机数产生的一个尽量避免重复的字符串,类似游客版h5登
// device_no: device_login_data.device_no,//使用新的sdk生成的设备指纹 // device_no: device_login_data.device_no,//使用新的sdk生成的设备指纹
login_type: '5',//登录类型:1 验证码手机登录, 2 password手机登录,4 token登录,5 微信登录, login_type: '5',//登录类型:1 验证码手机登录, 2 password手机登录,4 token登录,5 微信登录,
passport: code,//登录账号:手机登录值为手机 passport: code,//登录账号:手机登录值为手机
password: code,//类型对应的值 password: code,//类型对应的值
app_user_id: input_params.app_user_id || '',//app用户ID token登陆时传的参数 可空 app_user_id: params.app_user_id || '',//app用户ID token登陆时传的参数 可空
code: code || '',//第三方授权登录时的code 可空 code: code || '',//第三方授权登录时的code 可空
device_info: {},//设备信息 device_info: {},//设备信息
openid: openid || '' //例如微信公众号的appid(不传默认是51查个税) openid: openid || '' //例如微信公众号的openid(不传默认是51查个税)
}; };
const result_user_login = await ctx.helper.send_request(this.config.NODE_URL + '/login/user', user_login_params, { method: 'POST' });//用户登录 const result_user_login = await ctx.helper.send_request(this.config.NODE_URL + '/login/user', user_login_params, { method: 'POST' });//用户登录
ctx.logger.info(JSON.stringify({ user_login_params: user_login_params, result_user_login: result_user_login }));
const user_login_data = result_user_login.data;//用户登录返回结果 const user_login_data = result_user_login.data;//用户登录返回结果
if (!user_login_data || Object.keys(user_login_data).length === 0) { if (!user_login_data || Object.keys(user_login_data).length === 0) {
ctx.failed('用户的登录失败'); ctx.failed('用户的登录失败');
......
...@@ -7,4 +7,6 @@ module.exports = app => { ...@@ -7,4 +7,6 @@ module.exports = app => {
router.get('/mine/creditcards', 'gjj.mine.getMyCreditCards');// 我的信用卡 router.get('/mine/creditcards', 'gjj.mine.getMyCreditCards');// 我的信用卡
router.get('/wechat/check_login', 'gjj.wechat.checkLogin');// 公积金公众号检查用户是否登录 router.get('/wechat/check_login', 'gjj.wechat.checkLogin');// 公积金公众号检查用户是否登录
router.get('third', '/wechat/oauth_login', 'gjj.wechat.oauthLogin');// 公积金公众号授权登录
router.get('/wechat/check_gjj', 'gjj.wechat.checkGjj');// 公积金公众号授权登录
}; };
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