WeChat public number Developer Auto-reply settings no response.

Source: Internet
Author: User
Keywords PHP WeChat public platform developer
Tags cdata sha1
In the Sina Sea platform set up the public number application, set the focus on the automatic reply function, the interface setting is successful, the code is good, the URL also modifies the code page, but the test did not respond.

Define your Token
Define ("TOKEN", "Weixin");
$WECHATOBJ = new Wechatcallbackapitest ();
$WECHATOBJ->valid ();
$WECHATOBJ->responsemsg ();
Class Wechatcallbackapitest
{

    Public Function Valid () {$echoStr = $_get["Echostr"];            Valid signature, option if ($this->checksignature ()) {echo $echoStr;    Exit }}public function responsemsg () {//get post data, May is due to the different environments $postStr    = $GLOBALS ["Http_raw_post_data"]; Extract post Data if (!empty ($POSTSTR)) {$POSTOBJ = simplexml_load_string ($postStr, ' S            Implexmlelement ', libxml_nocdata);            $fromUsername = $POSTOBJ->fromusername;            $toUsername = $POSTOBJ->tousername;             $keyword = Trim ($postObj->content);            $time = time (); $TEXTTPL = "
  
    
     %s 
                                                        
 
     %s 
                                                        
 
    
     %s 
     
     %s 
     
     %s  
     
       0 
      
    
   
  ";                    if (!empty ($keyword)) {$msgType = "text";                    $CONTENTSTR = "Welcome to WeChat world!";                    $RESULTSTR = sprintf ($TEXTTPL, $fromUsername, $toUsername, $time, $msgType, $CONTENTSTR);            Echo $resultStr;            }else{echo "Input something ...";            }}else {echo "";    Exit    }} Private Function Checksignature () {$signature = $_get["signature"];    $timestamp = $_get["timestamp"];                                        $nonce = $_get["nonce"];            $token = token;            $TMPARR = Array ($token, $timestamp, $nonce);            Sort ($TMPARR);            $TMPSTR = implode ($TMPARR);                        $TMPSTR = SHA1 ($TMPSTR);            if ($tmpStr = = $signature) {return true;            }else{return false; }    }

}

?>

Reply content:

In the Sina Sea platform set up the public number application, set the focus on the automatic reply function, the interface setting is successful, the code is good, the URL also modifies the code page, but the test did not respond.

Define your Token
Define ("TOKEN", "Weixin");
$WECHATOBJ = new Wechatcallbackapitest ();
$WECHATOBJ->valid ();
$WECHATOBJ->responsemsg ();
Class Wechatcallbackapitest
{

    Public Function Valid () {$echoStr = $_get["Echostr"];            Valid signature, option if ($this->checksignature ()) {echo $echoStr;    Exit }}public function responsemsg () {//get post data, May is due to the different environments $postStr    = $GLOBALS ["Http_raw_post_data"]; Extract post Data if (!empty ($POSTSTR)) {$POSTOBJ = simplexml_load_string ($postStr, ' S            Implexmlelement ', libxml_nocdata);            $fromUsername = $POSTOBJ->fromusername;            $toUsername = $POSTOBJ->tousername;             $keyword = Trim ($postObj->content);            $time = time (); $TEXTTPL = "
  
    
     %s 
                                                        
 
     %s 
                                                        
 
    
     %s 
     
     %s 
     
     %s  
     
       0 
      
    
   
  ";                    if (!empty ($keyword)) {$msgType = "text";                    $CONTENTSTR = "Welcome to WeChat world!";                    $RESULTSTR = sprintf ($TEXTTPL, $fromUsername, $toUsername, $time, $msgType, $CONTENTSTR);            Echo $resultStr;            }else{echo "Input something ...";            }}else {echo "";    Exit    }} Private Function Checksignature () {$signature = $_get["signature"];    $timestamp = $_get["timestamp"];                                        $nonce = $_get["nonce"];            $token = token;            $TMPARR = Array ($token, $timestamp, $nonce);            Sort ($TMPARR);            $TMPSTR = implode ($TMPARR);                        $TMPSTR = SHA1 ($TMPSTR);            if ($tmpStr = = $signature) {return true;            }else{return false; }    }

}

?>

The valid method is used to detect if the message is coming from the server, it will output the content to the page, so it will disrupt the XML package you want to reply to
You can only call the Responsemsg method

This is just validation.
Take a look at the introduction of the passive reply message in the document.
http://mp.weixin.qq.com/wiki/1/6239b44c206cab9145b1d52c67e6c551.html#. E5.9b.9e.e5.a4.8d.e6.96.87.e6.9c.ac.e6.b6.88.e6.81.af

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.