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

1
(1)
#!/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)

这篇文章有用吗?

平均评分 1 / 5. 投票数: 1

到目前为止还没有投票!成为第一位评论此文章。

很抱歉,这篇文章对您没有用!

让我们改善这篇文章!

告诉我们我们如何改善这篇文章?

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据