質問

So we got our application accepted in the wechat debug console, and are looking to respond with rich media type messages. the request expected from the server is as follows:

<xml>
   <ToUserName>UserName</ToUserName>
    <FromuserName>TestUser</FromuserName>
    <CreateTime>7200</CreateTime>
    <MsgId>12302</MsgId>
    <Content>Test Message</Content>
</xml>

To which we reply with the following:

 <xml>
    <ToUserName>TestUser</ToUserName>
    <FromUserName>UserName</FromUserName>
    <CreateTime>7200</CreateTime>
    <MsgType>news</MsgType>
    <ArticleCount>1</ArticleCount>
    <Articles>
        <item>
             <Title>Test</Title>
             <Description>Test</Description>
             <PicUrl>http://PICURL</PicUrl>
             <Url>http://ARTICLE_URL</Url>
        </item>
    </Articles>
 </xml>

However the application doesn't seem to be getting the requests as it was setup so the questions is:

  1. Will requests go to the URL setup?
  2. If so is the xml provided correct for the response and also for the messages that gets posted to the url provided?
  3. Are there specific headers presents in the request?
役に立ちましたか?

解決

  1. Yes the Requests will go to the URL that you have setup and send a straight XML post to your script.
  2. Check your XML there seems to be quite a few differences from the actual system input and output also check the example of working input and output XML and try this. Obviously replacing the ToUserName and FromUserName:

INPUT RESPONSE

    <xml>
        <ToUserName><![CDATA[gh_4456]]></ToUserName>
        <FromUserName><![CDATA[123abc]]></FromUserName> 
        <CreateTime>1397201326</CreateTime> 
        <MsgType><![CDATA[text]]></MsgType> 
        <Content><![CDATA[test]]></Content> 
        <MsgId>6000934001298302633</MsgId> 
    </xml> 

OUTPUT RESPONSE

    <xml> 
        <ToUserName><![CDATA[123abc]]></ToUserName> 
        <FromUserName><![CDATA[gh_4456]]></FromUserName> 
        <CreateTime>1397201781</CreateTime> 
        <MsgType><![CDATA[news]]></MsgType> 
        <ArticleCount>1</ArticleCount> 
        <Articles>
            <item> 
                <Title><![CDATA[Your test title]]></Title> 
                <Description><![CDATA[test description]]></Description> 
                <PicUrl><![CDATA[http://test.com/img.jpg]]></PicUrl> 
                <Url><![CDATA[http://test.com/]]></Url> 
            </item> 
        </Articles> 
    </xml>  
  1. No headers you need to worry about.

    • FOR OFFICIAL OA: I think your problem might be that you have not enabled developer mode yet. Even though you have setup the URL and TOKEN. Please confirm developer mode is ENABLED. Go to admin.wechat.com -> login -> function -> advanced -> developer mode should be ENABLED.

    • FOR SANDBOX ACCOUNT: developer mode is always enabled.

    • Also check your CreateTime this should be a unix timestamp.

    • If none of that resolves it go and look at your access logs. Find the URL wechat is posting to. Once you have the URL got to http://www.hurl.it/ change the destination type to POST and paste the URL there. Add a Header called "Content-Type" with the value "text/xml" click on add body and post your input response in there. This will give you the response that WeChat sees. I tested yours and found the ToUserName was blank, also ensure you don't have unneeded spaces or newlines there.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top