tianyunperfect 3 سال پیش
والد
کامیت
8c9fa4a84a
2فایلهای تغییر یافته به همراه32 افزوده شده و 2 حذف شده
  1. 0 2
      fastapi-demo/main.py
  2. 32 0
      tmp/wechat/push_user.py

+ 0 - 2
fastapi-demo/main.py

@@ -18,8 +18,6 @@ from config import logger, CfgBaseInit
 
 app = FastAPI(title="project name ", description="通用系统 ", version="v 0.0.0")
 
-# app.routes.pop(1)  # drop default docs_url router
-
 # 添加 session 中间键,使项目中可以使用session
 app.add_middleware(SessionMiddleware, secret_key='123456hhh')
 app.add_middleware(

+ 32 - 0
tmp/wechat/push_user.py

@@ -0,0 +1,32 @@
+import json
+
+import requests
+
+
+def send_message_QiYeVX(corp_id, agent_id, secret, _message, userid_list=None):  # 默认发送给自己
+    if userid_list is None:
+        userid_list = []
+    userid_str = "|".join(userid_list)
+    response = requests.get(f"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={corp_id}&corpsecret={secret}")
+    data = json.loads(response.text)
+    access_token = data['access_token']
+
+    json_dict = {
+        "touser": userid_str,
+        "msgtype": "text",
+        "agentid": agent_id,
+        "text": {
+            "content": _message
+        },
+        "safe": 0,
+        "enable_id_trans": 0,
+        "enable_duplicate_check": 0,
+        "duplicate_check_interval": 1800
+    }
+    json_str = json.dumps(json_dict)
+    response_send = requests.post(f"https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={access_token}",
+                                  data=json_str)
+    return json.loads(response_send.text)['errmsg'] == 'ok'
+
+
+send_message_QiYeVX("ww582505d35b886cde", "1000002", "yDCwvVOHSvb_43Y3e17mZi4E7hEZ2Z3UDyDpuKxzPsQ", "测试消息", ["TianYun"])