代码更新

dependabot/npm_and_yarn/fir_admin/async-2.6.4
nineven 3 years ago
parent 156bf67c1c
commit 97349e758f
  1. 2
      fir_client/vue.config.js
  2. 3
      fir_ser/api/urls.py
  3. 16
      fir_ser/api/views/login_wx.py
  4. 8
      fir_ser/common/core/sysconfig.py
  5. 57
      fir_ser/common/libs/mp/wechat.py
  6. 9
      fir_ser/config.py

@ -82,7 +82,7 @@ if (page) {
}
}
const version='2.3.5';
const version='2.3.6';
const pro_base_env = {
baseUrl: 'https://flyapps.cn',

@ -23,7 +23,7 @@ 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, \
WeChatWebSyncView
WeChatWebSyncView, WeChatAppletView
from api.views.logout import LogoutView
from api.views.notify import NotifyReceiverView, NotifyConfigView, NotifyInfoView
from api.views.order import PriceView, OrderView, PaySuccess, OrderSyncView
@ -71,6 +71,7 @@ urlpatterns = [
re_path("^cname_domain$", DomainCnameView.as_view()),
re_path("^domain_info$", DomainInfoView.as_view()),
re_path("^mp.weixin$", ValidWxChatToken.as_view()),
re_path("^mp.applet$", WeChatAppletView.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()),

@ -14,7 +14,7 @@ from common.cache.storage import WxLoginBindCache
from common.core.auth import ExpiringTokenAuthentication
from common.core.sysconfig import Config
from common.core.throttle import VisitRegister1Throttle, VisitRegister2Throttle
from common.libs.mp.wechat import make_wx_login_qrcode, show_qrcode_url, WxWebLogin, WxTemplateMsg
from common.libs.mp.wechat import make_wx_login_qrcode, show_qrcode_url, WxWebLogin, WxTemplateMsg, WxAppletLogin
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, generate_alphanumeric_token_of_length
@ -223,3 +223,17 @@ class WeChatWebSyncView(APIView):
ret.data = wx_login_obj.make_auth_uri(ticket)
ret.ticket = ticket
return Response(ret.dict)
class WeChatAppletView(APIView):
throttle_classes = [VisitRegister1Throttle, VisitRegister2Throttle]
def post(self, request):
ret = BaseResponse()
auth_code = request.data.get('auth_code')
app_id = request.data.get('app_id')
if auth_code and app_id:
wx_login_obj = WxAppletLogin()
if app_id == wx_login_obj.app_id:
ret.data = wx_login_obj.get_session_from_code(auth_code)
return Response(ret.dict)

@ -207,8 +207,12 @@ class WechatConfCache(ConfigCacheBase):
super(WechatConfCache, self).__init__(*args, **kwargs)
@property
def THIRDLOGINCONF(self):
return super().get_value('THIRDLOGINCONF', THIRDLOGINCONF.wx_official)
def WECHATAPPLET(self):
return super().get_value('WECHATAPPLET', THIRDLOGINCONF.wx_applet)
@property
def WECHATOFFICIAL(self):
return super().get_value('WECHATOFFICIAL', THIRDLOGINCONF.wx_official)
class AuthConfCache(ConfigCacheBase):

@ -170,12 +170,12 @@ class WxOfficialBase(object):
@classmethod
def make_wx_auth_obj(cls):
return cls(**Config.THIRDLOGINCONF.get('auth'))
return cls(**Config.WECHATOFFICIAL.get('auth'))
def check_signature(params):
tmp_list = sorted(
[Config.THIRDLOGINCONF.get('auth', {}).get('token'), params.get("timestamp"), params.get("nonce")])
[Config.WECHATOFFICIAL.get('auth', {}).get('token'), params.get("timestamp"), params.get("nonce")])
tmp_str = "".join(tmp_list)
tmp_str = sha1(tmp_str.encode("utf-8")).hexdigest()
if tmp_str == params.get("signature"):
@ -185,7 +185,7 @@ def check_signature(params):
class WxMsgCrypt(WxMsgCryptBase):
def __init__(self):
super().__init__(**Config.THIRDLOGINCONF.get('auth'))
super().__init__(**Config.WECHATOFFICIAL.get('auth'))
class WxTemplateMsg(object):
@ -195,7 +195,7 @@ class WxTemplateMsg(object):
self.wx_nick_name = wx_nick_name
def send_msg(self, template_id, content):
if not Config.THIRDLOGINCONF.get('active'):
if not Config.WECHATOFFICIAL.get('active'):
return False, f'weixin status is disabled'
msg_uri = f'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token={get_wx_access_token_cache()}'
data = {
@ -562,7 +562,7 @@ class WxWebLogin(object):
def __init__(self):
self.openid = None
self.access_token = None
auth_info = Config.THIRDLOGINCONF.get('auth')
auth_info = Config.WECHATOFFICIAL.get('auth')
self.app_id = auth_info.get('app_id')
self.app_secret = auth_info.get('app_secret')
@ -615,3 +615,50 @@ class WxWebLogin(object):
req.encoding = 'utf-8'
return req.json()
return {}
class WxAppletLogin(object):
"""
https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/login/auth.code2Session.html
"""
def __init__(self):
self.openid = None
self.access_token = None
auth_info = Config.WECHATAPPLET.get('auth')
self.app_id = auth_info.get('app_id')
self.app_secret = auth_info.get('app_secret')
def get_session_from_code(self, js_code):
"""
登录凭证校验通过 wx.login 接口获得临时登录凭证 code 后传到开发者服务器调用此接口完成登录流程
:param js_code:
"""
t_url = f'https://api.weixin.qq.com/sns/jscode2session?appid={self.app_id}&secret={self.app_secret}&js_code={js_code}&grant_type=authorization_code'
req = requests.get(t_url)
if req.status_code == 200:
logger.info(f"get wx applet session {req.status_code} {req.text}")
auth_info = req.json()
return auth_info
return {}
def get_access_token(self):
"""
获取小程序全局唯一后台接口调用凭据access_token调用绝大多数后台接口时都需使用 access_token开发者需要进行妥善保存
"""
t_url = f'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={self.app_id}&secret={self.app_secret}'
req = requests.get(t_url)
if req.status_code == 200:
logger.info(f"get access token {req.status_code} {req.text}")
auth_info = req.json()
self.access_token = auth_info.get('access_token')
return auth_info
return {}
def get_phone_number(self, access_token, js_code):
t_url = f'https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token={access_token}'
req = requests.post(t_url, json={'code': js_code})
if req.status_code == 200:
logger.info(f"get phone number {req.status_code} {req.text}")
return req.json()
return {}

@ -78,11 +78,18 @@ class THIRDLOGINCONF(object):
wx_official = {
'name': 'wx_official',
'auth': {
'app_id': 'wx390e5985fd3699e6',
'app_id': '1wx390e5985fd3699e6',
'app_secret': '5b1796722172a902d019f43e4a2fb678',
'token': 'f0ae76c1559cacf72a99db6a41b879b8',
'encoding_aes_key': '7b9U60tCXk3f4yOFideTN5ithh4Y8X3Xl9pRovp83gG',
},
'active': False
}
wx_applet = {
'auth': {
'app_id': 'wxb65d1894331e9ff3',
'app_secret': 'e05b319562b3b123ffef1d9ce64dd665',
},
'active': True
}

Loading…
Cancel
Save