#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