【问题标题】:Token error when sending Wechat message with Python使用Python发送微信消息时令牌错误
【发布时间】:2018-01-26 21:28:47
【问题描述】:

我有一个微信订阅页面,我在https://admin.wechat.com/中设置了一个token以及我的服务器myserver.com/wechat/webhook的webhook URL

我的服务器 Python 代码使用签名检查、nonce 和时间戳对微信服务器进行身份验证,并且我能够从微信接收消息到我的 webhook。

但我无法将消息从我的服务器发送到微信,我使用以下代码和之前在管理控制台中设置的令牌,并遵循之前的文档: http://admin.wechat.com/wiki/index.php?title=Customer_Service_Messages

# Parse the received WeChat message
message = xmltodict.parse(message)

content = message['xml']['Content']
fromUser = message['xml']['FromUserName']
toUser = message['xml']['ToUserName']
createdTime = message['xml']['CreateTime']

# reply to message
post_data = {
   "touser": fromUser,
   "msgtype": "text",
   "text":
   {
        "content": "Thanks for your message"
   }
}
api_url = 'https://api.wechat.com/cgi-bin/message/custom/send?access_token=' + token
response = requests.post(api_url, data=post_data)
content = response.content

这是我得到的错误:

{"errcode":40001,"errmsg":"invalid credential, access_token is invalid or not latest hint: [udQ9ka0880vr32!]"}

我应该使用什么令牌?或者可能是什么错误?谢谢

【问题讨论】:

    标签: python rest python-requests wechat


    【解决方案1】:

    我认为这可能是权限问题...在我的微信页面管理控制台中,它说我已经获得了自动回复的权限,但没有获得服务 API 的权限。任何人都可以证实这一点?

    确实,我成功测试了立即使用 http 响应(自动回复或回调)回复 POST 消息http://admin.wechat.com/wiki/index.php?title=Callback_Messages

    Service API 似乎无法正常工作(这是我提出问题的目的)http://admin.wechat.com/wiki/index.php?title=Customer_Service_Messages

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-22
      • 2022-07-28
      • 1970-01-01
      • 2016-11-29
      • 2012-04-13
      • 1970-01-01
      • 2021-04-02
      相关资源
      最近更新 更多