微信小程序 python 发送客服消息
2023-04-18 14:29:58 时间
发表于2020-03-312020-04-03 作者 wind
#!/usr/bin/python
# coding=utf-8
import requests, json, sys, time, logging
if sys.getdefaultencoding() != 'utf-8':
reload(sys)
sys.setdefaultencoding('utf-8')
logging.basicConfig(format='%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s',
level=logging.DEBUG, filename='/var/tmp/wxapp_push.log',
filemode='a')
appid = 'xxx';
appSecret = 'xxx';
url_access_token = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' + appid + '&secret=' + appSecret
touser = sys.argv[1]
subject = "服务器异常"
message = "受限于字数限制,请点击进入查看详情"
tokenRes = requests.get(url_access_token)
token = json.loads(tokenRes.text).get('access_token')
logging.info(token)
url_custom_msg = 'https://api.weixin.qq.com/cgi-bin/message/custom/send';
body = {
"touser": touser,
"msgtype": "text",
"text":
{
"content": sys.argv[1] + '
' + sys.argv[2]
}
}
res = requests.post(url=url_custom_msg, params={
'access_token': token # 这里是我们上面获取到的token
}, data=json.dumps(body, ensure_ascii=False).encode('utf-8'))
print(res.text)
相关文章
- [源码解析] PyTorch 分布式 Autograd (1) ---- 设计
- anaconda navigator 打不开怎么办
- python中如何数出字符串的字符个数
- Django切换MySQL数据库
- python中Pyramid框架是什么?
- [源码解析] PyTorch 分布式 Autograd (2) ---- RPC基础
- 人工智能python是什么
- python是什么编程语言
- python是什么意思中文
- [源码解析] PyTorch 分布式(12) ----- DistributedDataParallel 之 前向传播
- python之禅是什么
- [源码解析] PyTorch 分布式(13) ----- DistributedDataParallel 之 反向传播
- python函数传递参数的两种方式
- python函数标注是什么
- python里的开根号怎么写
- 【Python零基础到入门】Python基础语法篇——数字(Number) 学习
- python如何求偶数和?
- python中num是什么意思
- Python3开发一个web项目
- python中setuptools如何安装