diff --git a/fir_client/src/components/user/FirUserProfileInfo.vue b/fir_client/src/components/user/FirUserProfileInfo.vue index 9f82a6e..55c3609 100644 --- a/fir_client/src/components/user/FirUserProfileInfo.vue +++ b/fir_client/src/components/user/FirUserProfileInfo.vue @@ -344,11 +344,49 @@ export default { unique_key: '' } }, methods: { + + loop_get_wx_web_info(wx_login_ticket, c_count = 1, unique_key = getRandomStr()) { + if (wx_login_ticket && wx_login_ticket.length < 3) { + this.$message.error("获取登陆码失败,请稍后再试"); + return + } + if (!this.show_web_visible) { + return; + } + wxLoginFun(data => { + c_count += 1; + if (c_count > 30) { + return; + } + if (data.code === 1000) { + if (this.userinfo.uid === data.data.uid) { + this.$message.success("更新成功"); + this.show_web_visible = false; + this.get_wx_user_list(); + } + } else if (data.code === 1006) { + return this.loop_get_wx_web_info(wx_login_ticket, c_count, unique_key) + } else { + this.$message({ + message: data.msg, + type: 'error', + duration: 30000 + }); + this.show_web_visible = false; + } + }, { + "methods": "POST", + data: {"ticket": wx_login_ticket, "unique_key": unique_key} + }) + }, + + wx_web_login_fun() { wxWebScanFun(data => { if (data.code === 1000) { this.show_web_visible = true; this.wx_web_login_url = data.data; + this.loop_get_wx_web_info(data.ticket) } else { this.$message.error("信息获取失败") } diff --git a/fir_client/src/restful/index.js b/fir_client/src/restful/index.js index 0b93a1c..c56142c 100644 --- a/fir_client/src/restful/index.js +++ b/fir_client/src/restful/index.js @@ -263,7 +263,7 @@ export function wxBindFun(callBack, params, load = true) { export function wxWebScanFun(callBack, params, load = true) { getData( params.methods, - USERSEVER + '/mp.web.login', + USERSEVER + '/mp.web.sync', params.data, data => { callBack(data); diff --git a/fir_ser/api/urls.py b/fir_ser/api/urls.py index 409a9ce..37ace0d 100644 --- a/fir_ser/api/urls.py +++ b/fir_ser/api/urls.py @@ -22,7 +22,8 @@ from api.views.download import ShortDownloadView, InstallView, DownloadView from api.views.getip import GetRemoteIp from api.views.login import LoginView, UserInfoView, RegistView, AuthorizationView, ChangeAuthorizationView, \ UserApiTokenView, CertificationView, ChangeInfoView -from api.views.login_wx import WeChatLoginView, WeChatLoginCheckView, WeChatBindView, WeChatWebLoginView +from api.views.login_wx import WeChatLoginView, WeChatLoginCheckView, WeChatBindView, WeChatWebLoginView, \ + WeChatWebSyncView from api.views.logout import LogoutView from api.views.notify import NotifyReceiverView, NotifyConfigView, NotifyInfoView from api.views.order import PriceView, OrderView, PaySuccess, OrderSyncView @@ -68,6 +69,7 @@ urlpatterns = [ re_path("^domain_info$", DomainInfoView.as_view()), re_path("^mp.weixin$", ValidWxChatToken.as_view()), re_path("^mp.web.login$", WeChatWebLoginView.as_view(), name="mp.web.login"), + re_path("^mp.web.sync$", WeChatWebSyncView.as_view(), name="mp.web.sync"), re_path("^third.wx.login$", WeChatLoginView.as_view()), re_path("^third.wx.bind$", WeChatBindView.as_view()), re_path("^third.wx.sync$", WeChatLoginCheckView.as_view()), diff --git a/fir_ser/api/views/login_wx.py b/fir_ser/api/views/login_wx.py index 1e9ab3a..dbb3beb 100644 --- a/fir_ser/api/views/login_wx.py +++ b/fir_ser/api/views/login_wx.py @@ -1,6 +1,6 @@ import logging -from django.http import HttpResponse +from django.shortcuts import redirect from rest_framework.response import Response from rest_framework.views import APIView @@ -17,7 +17,7 @@ from common.core.throttle import VisitRegister1Throttle, VisitRegister2Throttle from common.libs.mp.wechat import make_wx_login_qrcode, show_qrcode_url, WxWebLogin, WxTemplateMsg from common.utils.caches import set_wx_ticket_login_info_cache, get_wx_ticket_login_info_cache from common.utils.pending import get_pending_result -from common.utils.token import verify_token +from common.utils.token import verify_token, generate_alphanumeric_token_of_length logger = logging.getLogger(__name__) @@ -185,11 +185,11 @@ class WeChatWebLoginView(APIView): throttle_classes = [VisitRegister1Throttle, VisitRegister2Throttle] def get(self, request): - logger.error(request.query_params) wx_login_obj = WxWebLogin() ret = BaseResponse() code = request.query_params.get('code') if code: + state = request.query_params.get('state', 'FLYAPPS') wx_login_obj.get_wx_token(code) wx_user_info = wx_login_obj.get_user_info() logger.info(f'{wx_user_info}') @@ -197,13 +197,29 @@ class WeChatWebLoginView(APIView): 'openid': wx_user_info.get('openid'), 'nickname': wx_user_info.get('nickname'), 'sex': wx_user_info.get('sex'), - # 'subscribe_time': wx_user_info.get('subscribe_time', 0), 'head_img_url': wx_user_info.get('headimgurl', ''), 'address': f"{wx_user_info.get('country')}-{wx_user_info.get('province')}-{wx_user_info.get('city')}", - # 'subscribe': wx_user_info.get('subscribe', 0), } logger.info(f'{wx_user_info}') WeChatInfo.objects.filter(openid=wx_user_info.get('openid')).update(**wx_user_info) - return HttpResponse('