|
@@ -18,32 +18,31 @@ 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_HOST = "http://19.15.0.128:8080"
|
|
|
-# YZY_HOST = "https://xtbg.digitalgd.com.cn"
|
|
|
+YZY_ACCESS_TOKEN_REDIS_KEY = "YZY_ACCESS_TOKEN_REDIS_KEY"
|
|
|
|
|
|
+'''
|
|
|
+YZY_API_ROOT = "http://19.15.0.128:8080"
|
|
|
YZY_AGENTID = 1004302
|
|
|
YZY_CORPID = "wld341060039"
|
|
|
YZY_CORPSECRET = "5_8aOBBjioNbP7KDwjyBKmwnJ05-y1WbaJlt4irM1eA"
|
|
|
-
|
|
|
-YZY_ACCESS_TOKEN_REDIS_KEY = "YZY_ACCESS_TOKEN_REDIS_KEY"
|
|
|
-
|
|
|
-YZH_PASSID = "yzy_demo"
|
|
|
-YZH_PASSTOKEN = "WjKat55cv6PrJtpCHld0trrHsv1mbCqL"
|
|
|
+YZY_PASSID = "yzy_demo"
|
|
|
+YZY_PASSTOKEN = "WjKat55cv6PrJtpCHld0trrHsv1mbCqL"
|
|
|
+'''
|
|
|
|
|
|
def __get_access_token():
|
|
|
- url = "{}/ebus/yzyapi/cgi-bin/gettoken?corpid={}&corpsecret={}".format(YZY_HOST, YZY_CORPID, YZY_CORPSECRET)
|
|
|
+ url = "{}/ebus/yzyapi/cgi-bin/gettoken?corpid={}&corpsecret={}".format(settings.YZY_API_ROOT, settings.YZY_CORPID, settings.YZY_CORPSECRET)
|
|
|
print('yzy url:', url)
|
|
|
|
|
|
timestamp = str(int(time.time()))
|
|
|
nonce = ranstr(20)
|
|
|
- signature = calcResponseSign(timestamp, YZH_PASSTOKEN, nonce)
|
|
|
+ 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": YZH_PASSID
|
|
|
+ "x-tif-paasid": settings.YZY_PASSID
|
|
|
}
|
|
|
response = requests.get(url, headers=headers, timeout=15)
|
|
|
print('yzy return:', response.text)
|
|
@@ -65,17 +64,17 @@ def get_cache_access_token():
|
|
|
|
|
|
def get_user_info(code: str):
|
|
|
access_token = get_cache_access_token()
|
|
|
- url = "{}/ebus/yzyapi/cgi-bin/user/getuserinfo?access_token={}&code={}".format(YZY_HOST, access_token, code)
|
|
|
+ url = "{}/ebus/yzyapi/cgi-bin/user/getuserinfo?access_token={}&code={}".format(settings.YZY_API_ROOT, access_token, code)
|
|
|
return __post_url__(url, {})
|
|
|
|
|
|
def send_text_message(users, content: str):
|
|
|
access_token = get_cache_access_token()
|
|
|
- url = "{}/ebus/yzyapi/cgi-bin/message/send?access_token={}".format(YZY_HOST, access_token)
|
|
|
+ url = "{}/ebus/yzyapi/cgi-bin/message/send?access_token={}".format(settings.YZY_API_ROOT, access_token)
|
|
|
|
|
|
data = {
|
|
|
"touser": "|".join(users),
|
|
|
"msgtype" : "text",
|
|
|
- "agentid" : YZY_AGENTID,
|
|
|
+ "agentid" : settings.YZY_AGENTID,
|
|
|
"text": {
|
|
|
"content": content
|
|
|
}
|
|
@@ -85,7 +84,7 @@ def send_text_message(users, content: str):
|
|
|
|
|
|
def send_textcard_message(users, title: str, description: str, detail_url):
|
|
|
access_token = get_cache_access_token()
|
|
|
- url = "{}/ebus/yzyapi/cgi-bin/message/send?access_token={}".format(YZY_HOST, access_token)
|
|
|
+ url = "{}/ebus/yzyapi/cgi-bin/message/send?access_token={}".format(settings.YZY_API_ROOT, access_token)
|
|
|
|
|
|
touser = ""
|
|
|
if isinstance(users, list) == True:
|
|
@@ -95,7 +94,7 @@ def send_textcard_message(users, title: str, description: str, detail_url):
|
|
|
data = {
|
|
|
"touser": touser,
|
|
|
"msgtype" : "textcard",
|
|
|
- "agentid" : YZY_AGENTID,
|
|
|
+ "agentid" : settings.YZY_AGENTID,
|
|
|
"textcard": {
|
|
|
"title": title,
|
|
|
"description": description,
|
|
@@ -112,14 +111,14 @@ def __post_url__(url, data):
|
|
|
|
|
|
timestamp = str(int(time.time()))
|
|
|
nonce = ranstr(20)
|
|
|
- signature = calcResponseSign(timestamp, YZH_PASSTOKEN, nonce)
|
|
|
+ signature = calcResponseSign(timestamp, 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": YZH_PASSID
|
|
|
+ "x-tif-paasid": settings.YZY_PASSID
|
|
|
}
|
|
|
response = requests.post(url, data=data,headers=headers, timeout=5)
|
|
|
print('yzy return:', response.text)
|
|
@@ -201,9 +200,9 @@ def format_redirect_url(redirect_url: str) -> str:
|
|
|
print('state_base64:', state)
|
|
|
|
|
|
detail_url = "https://open.weixin.qq.com/connect/Oauth2/authorize?appid={}&redirect_uri={}&response_type=code&scope=snsapi_base&agentid={}&state={}#wechat_redirect".format(
|
|
|
- YZY_CORPID,
|
|
|
+ settings.YZY_CORPID,
|
|
|
yzy_callback_url,
|
|
|
- YZY_AGENTID,
|
|
|
+ settings.YZY_AGENTID,
|
|
|
state)
|
|
|
|
|
|
logger.info("detail_url: {}", detail_url)
|