1 >>> import sys 2 >>> sys.version 3 '3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)]'
pip install requests
#!/usr/bin/env python # -*- coding: utf-8 -*- import requests import json import sys
def get_token(): url='https://qyapi.weixin.qq.com/cgi-bin/gettoken' values = {'corpid' : '[企業號的標識]' , 'corpsecret':'[管理組憑證密鑰]', } req = requests.post(url, params=values) data = json.loads(req.text) return data["access_token"] def send_msg(): url="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token="+get_token() values = json.dumps({ 'touser':"[企業號中的用戶賬號]", 'toparty':"[企業號中的部門id]", 'msgtype':"[消息類型]", 'agentid':"[企業號中的應用id]", 'text':{ 'content':'[消息]' }, 'safe':'0' },ensure_ascii=True) print(values) data = json.loads(values) req = requests.post(url, values) if __name__ == '__main__': send_msg()
代碼來源網絡,稍做修改。python