前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >微信小程序 python 发送客服消息

微信小程序 python 发送客服消息

作者头像
前Thoughtworks-杨焱
发布2021-12-07 19:58:57
发布2021-12-07 19:58:57
98600
代码可运行
举报
文章被收录于专栏:杨焱的专栏杨焱的专栏
运行总次数:0
代码可运行

发表于2020-03-312020-04-03 作者 wind

代码语言:javascript
代码运行次数:0
运行
复制
#!/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] + '\n' + 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)
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-03-31,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档