Domanda

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?

È stato utile?

Soluzione

Can you confirm that you have submitted the URL and token into admin.wechat.com and that the URL and token was accepted?

Also note you get XML and you respond with XML no json response.

Have you had a look at: http://youtu.be/kB20Zf51QWU And then this http://youtu.be/_2FSzD2B2F0

This is the documentation for the XML can be found when you google "wechat guide to message api"

So if you still not receiving a success message when submitting your app on admin.wechat.com then you can send me your test URL here. To find this URL check your access logs to see exactly what URL wechat is calling. Then post it here. Please note that when you hit the URL as wechat will you should only see the "echostr" printed on the screen (when viewing the source in your browser). No XML no HTML just the echostr.

Also make sure there are no spaces or newlines after or before the "echostr". When you view the source it should only be one line which is the echostr GET param's value.

The XML response only comes in later when you actually start responding to messages from users. For now Wechat is just confirming if your security is setup correctly.

Also note if your server is load balanced you will have to skip the signature validation and build your own validation when a echostr GET parameter gets passed through and only echo the "echostr" param to screen.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top