123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- import json
- import random
- import requests
- notes = [
- """我们曾如此渴望命运的波澜,到最后才发现,人生最曼妙的风景,竟是内心的淡定与从容;
- 我们曾如此期盼外界的认可,到最后才知道,世界是自己的,与他人毫无关系。""",
- """做一个浪漫的人,对世界保持永远的好奇,但别让他轻易改变你。"""
- ]
- def get_des():
- li = random.choice(notes).split("\n")
- li.append("点击进行复习。")
- res = ''
- for line in li:
- res += "<div>" + line.strip() + "</div>"
- return res
- 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": "textcard",
- "agentid": agent_id,
- "textcard": {
- "title": "念念不忘,必有回响",
- "description": get_des(),
- "url": "https://memory.tianyunperfect.cn/",
- "btntxt": "更多"
- },
- "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"])
|