|
@@ -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"])
|