3

I have a Debugging Official Account with WeChat. I have entered my public URL and Token into the field provided http://admin.wechat.com/debug/sandbox and also attempted debugging the request with http://admin.wechat.com/debug/

My ASP.Net [.Net4.5] Web API application's POST Method looks like the following :

public HttpResponseMessage PostMessage([FromBody]Strikemedia.Api.WeChat.TextMessage value)
    {
        if (value == null)
        {
            var richMediaMessage = new RichMediaMessage();
            richMediaMessage.touser = value.FromuserName;

            //Create Article
            var item = new Article()
            {
                title = "Didn't receive anything back",
                description = "Mind entering 'test'",
                picurl = "URL",
                url = "URL"
            };
            var articles = new List<Article>();
            articles.Add(item);
            richMediaMessage.articles = articles;
            richMediaMessage.articleCount = articles.Count;
            return Request.CreateResponse(HttpStatusCode.OK, richMediaMessage, "application/json");
        }

        var exploded = value.Content.Split(' ')[0];

        var richMedia = new RichMediaMessage();
        richMedia.touser = value.FromuserName;

        //Create Article
        var article = new Article() { 
            title = response.KeywordDescription,
            description = response.Response,
            picurl = "URL",
            url = "URL"
        };
        var _articles = new List<Article>();
        _articles.Add(article);
        richMedia.articles = _articles;
        richMedia.articleCount = _articles.Count;

        //Return response
        var resp = Request.CreateResponse(HttpStatusCode.OK, richMedia, "application/json");
        //resp.RequestMessage.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
        return resp;
    }

It needs to respond with a RichMessageType in JSON format and is received in XML format

Am i missing something or have i overlooked something?

4

1 回答 1

1

您能否确认您已将 URL 和令牌提交到 admin.wechat.com 并且 URL 和令牌已被接受?

另请注意,您获得了 XML,并且您使用 XML 无 json 响应进行响应。

你有没有看过:http: //youtu.be/kB20Zf51QWU 然后这个 http://youtu.be/_2FSzD2B2F0

这是当你谷歌“微信消息API指南”时可以找到的XML文档

因此,如果您在 admin.wechat.com 上提交应用时仍然没有收到成功消息,那么您可以在此处将您的测试 URL 发送给我。要查找此 URL,请检查您的访问日志以查看微信正在调用的 URL。然后在这里发布。请注意,当您以微信身份点击 URL 时,您应该只看到屏幕上打印的“echostr”(在浏览器中查看源代码时)。没有 XML 没有 HTML,只有 echostr。

还要确保在“echostr”之后或之前没有空格或换行符。当您查看源代码时,它应该只有一行,即 echostr GET 参数的值。

XML 响应仅在您实际开始响应来自用户的消息时才会出现。目前,微信只是确认您的安全设置是否正确。

另请注意,如果您的服务器是负载平衡的,您将不得不跳过签名验证并在 echostr GET 参数通过并且仅将“echostr”参数回显到屏幕时构建自己的验证。

于 2014-04-10T14:42:32.760 回答