#coding=utf-8 import requests import json Secret = "TUbfeW8nFQakwOS4czm13SCnxSUPOqY2K0XHtM8XLT34" corpid = ‘wwfe776a5bc7b90190a‘ url = ‘https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={}&corpsecret={}‘ getr = requests.get(url=url.format(corpid,Secret)) # print(r.json()) # {‘errcode‘: 0, ‘errmsg‘: ‘ok‘, ‘access_token‘: ‘t2HxARFMOgge-neHJwYXe4MrIXlFcu2m_Ev1pGQIAcmu-Kt1kQ7pey6jkPfdecqyvvZ9RGb3oSfjL1-lbbp1Y6UGGi8ZjNNd64AALtbR58ot1lh6VjE2ITkiWwgIftwWyryNDw_1AJAtVYYQxKU2O16a7NhHVEdcHG20u8czD-QUDUec1LqI4503OcVGzdR4Cq_4yA6a3fIkVLdQ_u3CHg‘, ‘expires_in‘: 7200} access_token = getr.json().get(‘access_token‘) # access_token =‘t2HxARFMOgge-neHJwYXe4MrIXlFcu2m_Ev1pGQIAcmu-Kt1kQ7pey6jkPfdecqyvvZ9RGb3oSfjL1-lbbp1Y6UGGi8ZjNNd64AALtbR58ot1lh6VjE2ITkiWwgIftwWyryNDw_1AJAtVYYQxKU2O16a7NhHVEdcHG20u8czD-QUDUec1LqI4503OcVGzdR4Cq_4yA6a3fIkVLdQ_u3CHg‘ ‘‘‘ ‘‘‘ data = { "touser" : "Zhang", # 向这些用户账户发送,用户账号1|用户账户2 # "toparty" : "PartyID1|PartyID2", # 向这些部门发送 "msgtype": "markdown", "agentid" : 1000002, # 应用的 id 号 "markdown": { "content":‘‘‘ >**接口报警** > >日 期:<font color=\"info\">2018年5月18日</font> >时 间:<font color=\"info\">上午9:00-11:00</font> > ><font color=\"warning\">预警接口</font>: > >[查看详情](http://www.baidu.com/) > >成员: ><font color=\"comment\">@miglioguan</font> ><font color=\"comment\">@kunliu</font> ><font color=\"comment\">@jamdeezhou</font> ‘‘‘ }, "safe":0 } r = requests.post(url="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={}".format(access_token),data=json.dumps(data)) print(r.json())
参考:
https://www.jianshu.com/p/020709b130d3
原文地址:https://www.cnblogs.com/sea-stream/p/12074277.html
时间: 2024-10-29 13:16:30