企业微信有免费的消息发送接口,可以发送消息给相应的企业微信账号

class Wechatwork:
    def __init__(self):
        # 企业ID
        self.corpid = 'dad20bbb1'
        # 企业中创建应用的Secret
        self.secret = 'vIcbI9ACQ'
    def send_msg(self, message):
        # 获取AccessToken
        tokurl = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid='+self.corpid+'&corpsecret='+self.secret
        acctok = requests.get(tokurl).json()['access_token']
        # 发送消息
        msgurl = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' + acctok
        # 发送的人,多个人可以以|隔开
        touser = 'leo.mia.binw'
        contnt = message
        params = {"touser": touser,"msgtype": "text","agentid": 1000005,"text": {"content": contnt},"safe":0}
        result = requests.post(msgurl, data=json.dumps(params))
        return result.json()
wcwk = Wechatwork()
result = wcwk.send_msg("消息", "模板")
Last modification:February 28th, 2021 at 03:39 pm
硬币投入口