40003, invalid openid
发布于 6 年前 作者 xiulan37 12072 次浏览 来自 问答

想调用客服接口来实现收到一次用户消息回复多条信息。但是每次都是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已经确认过,都是测试接口号的

回到顶部