1、通訊用戶:touser 或 通訊組:toparty 2、企業(yè)ID:corpid 3、應(yīng)用ID/密鑰:agentId,secret
通訊錄 用戶的賬號或創(chuàng)建組的部門ID
我的企業(yè)最下方
企業(yè)微信管理員登錄企業(yè)微信,
應(yīng)用管理創(chuàng)建應(yīng)用
可見范圍:發(fā)給誰
#! /usr/bin/env python # -*- coding: UTF-8 -*- import requests, sys class SendWeiXinWork(): def __init__(self): self.CORP_ID = "xxx" # 企業(yè)號的標識 self.SECRET = "xxx" # 管理組憑證密鑰 self.AGENT_ID = xxx # 應(yīng)用ID self.token = self.get_token() def get_token(self): url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken" data = { "corpid": self.CORP_ID, "corpsecret": self.SECRET } req = requests.get(url=url, params=data) res = req.json() if res['errmsg'] == 'ok': return res["access_token"] else: return res def send_message(self, to_user, content): url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=%s" % self.token data = { # "touser": to_user, # 發(fā)送個人就填用戶賬號 "toparty": to_user, # 發(fā)送組內(nèi)成員就填部門ID "msgtype": "text", "agentid": self.AGENT_ID, "text": {"content": content}, "safe": "0" } req = requests.post(url=url, json=data) res = req.json() if res['errmsg'] == 'ok': print("send message sucessed") return "send message sucessed" else: return res if __name__ == '__main__': SendWeiXinWork = SendWeiXinWork() SendWeiXinWork.send_message("2", "測試a")
到此這篇關(guān)于教你利用python實現(xiàn)企業(yè)微信發(fā)送消息的文章就介紹到這了,更多相關(guān)python企業(yè)微信發(fā)送消息內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!