|
@@ -19,6 +19,7 @@ from sqlalchemy.orm import Session
|
|
|
# https://open.weixin.qq.com/connect/Oauth2/authorize?appid=wld341060039&redirect_uri=https://www.baidu.com/#/&response_type=code&scope=snsapi_base&agentid=1004302&state=xxxxxx#wechat_redirect
|
|
|
|
|
|
YZY_ACCESS_TOKEN_REDIS_KEY = "YZY_ACCESS_TOKEN_REDIS_KEY"
|
|
|
+YZY_JSAPI_TICKET_REDIS_KEY = "YZY_JSAPI_TICKET_REDIS_KEY"
|
|
|
|
|
|
'''
|
|
|
YZY_API_ROOT = "http://19.15.0.128:8080"
|
|
@@ -62,6 +63,40 @@ def get_cache_access_token():
|
|
|
|
|
|
return access_token
|
|
|
|
|
|
+def __get_jsapi_ticket():
|
|
|
+ access_token = get_cache_access_token()
|
|
|
+ url = "{}/ebus/yzyapi/cgi-bin/get_jsapi_ticket?access_token={}".format(settings.YZY_API_ROOT, access_token)
|
|
|
+ print('yzy url:', url)
|
|
|
+
|
|
|
+ timestamp = str(int(time.time()))
|
|
|
+ nonce = ranstr(20)
|
|
|
+ signature = calcResponseSign(timestamp, settings.YZY_PASSTOKEN, nonce)
|
|
|
+
|
|
|
+ headers = {
|
|
|
+ 'Content-Type': 'application/json;charset=UTF-8',
|
|
|
+ "x-tif-signature": signature,
|
|
|
+ "x-tif-timestamp": timestamp,
|
|
|
+ "x-tif-nonce": nonce,
|
|
|
+ "x-tif-paasid": settings.YZY_PASSID
|
|
|
+ }
|
|
|
+ response = requests.get(url, headers=headers, timeout=15)
|
|
|
+ print('yzy return:', response.text)
|
|
|
+ if response.status_code == 200 :
|
|
|
+ result = response.json()
|
|
|
+ errcode = int(result['errcode'])
|
|
|
+ if errcode == 0:
|
|
|
+ return (result['ticket'], result['expires_in'])
|
|
|
+ else:
|
|
|
+ raise YzyException(errcode=errcode, errmsg=result['errmsg'])
|
|
|
+
|
|
|
+def get_cache_jsapi_ticket():
|
|
|
+ ticket = redis_get(YZY_JSAPI_TICKET_REDIS_KEY)
|
|
|
+ if ticket is None:
|
|
|
+ ticket, expires_in = __get_jsapi_ticket()
|
|
|
+ redis_set_with_time(YZY_JSAPI_TICKET_REDIS_KEY, ticket, expires_in - 600)
|
|
|
+
|
|
|
+ return ticket
|
|
|
+
|
|
|
def get_user_info(code: str):
|
|
|
access_token = get_cache_access_token()
|
|
|
url = "{}/ebus/yzyapi/cgi-bin/user/getuserinfo?access_token={}&code={}".format(settings.YZY_API_ROOT, access_token, code)
|