收藏
回答

40003, invalid openid

想调用客服接口来实现收到一次用户消息回复多条信息。但是每次都是invalid openid。用的测试接口号,有客服接口权限。代码如下;

class Handle(object):
    def POST(self):
        url = "https://api.weixin.qq.com/cgi-bin/token?" \
     "grant_type=client_credential&appid=APPID&" \
              "secret=SECRET"
        response = requests.get(url=url)
        json_data = json.loads(response.text)
        access_token = json_data.get("access_token")
        try:
            webData = web.data()
            receive = parse_xml(webData)
            toUser = receive.FromUserName
            replies = ['1', '2']
            url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=%s" % access_token
            for reply in replies:
                    data = {"openid": toUser,
                            "msgtype": "text",
                            "command": "Typing",
                            "text":
                                {
                                    "content": reply
                                }
                            }
                    response = requests.post(url=url, data=data)
            else:
                print("暂且不处理")
                return "success"
        except Exception as Argment:
            return Argment

上面的APPID和SECRET已经确认过,都是测试接口号的

最后一次编辑于  2018-12-08  (未经腾讯允许,不得转载)
回答关注问题邀请回答
收藏