Home > Mobile >  Why the server configuration (enabled), but after responseMsg method, WeChat not auto reply?
Why the server configuration (enabled), but after responseMsg method, WeChat not auto reply?

Time:10-16

This did not change what
<? PHP
/* *
* wechat PHP test
*/

//define your token
Define (" TOKEN ", "huaxingo123");
$wechatObj=new wechatCallbackapiTest ();
$wechatObj - & gt; ResponseMsg ();

The class wechatCallbackapiTest
{
The public function valid ()
{
$echoStr=$_GET["echostr"];

//valid signature, option
If ($this - & gt; CheckSignature ()) {
Echo $echoStr;
The exit;
}
}

The public function responseMsg ()
{
//get the post data, May be due to the company's environments
$postStr=$GLOBALS [" HTTP_RAW_POST_DATA "];

//extract post data
if (! Empty ($postStr)) {
/* libxml_disable_entity_loader is to prevent eXternal XML Entity Injection,
The best way is to check the gnosis.xml.validity of XML by yourself */
Libxml_disable_entity_loader (true);
$postObj=simplexml_load_string ($postStr, 'simplexmlelements, LIBXML_NOCDATA);
$fromUsername=$postObj - & gt; FromUserName;
$toUsername=$postObj - & gt; ToUserName;
$keyword=trim ($postObj - & gt; The Content);
$time=time ();
$textTpl="& lt; Xml>


% s


0 & lt;/FuncFlag>
";
if(! Empty ($keyword))
{
$msgType="text";
$contentStr="welcome to you!" ;
$resultStr=sprintf ($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
Echo $resultStr;
} else {
Echo "Input something... ";
}

} else {
Echo "";
The exit;
}
}

Private function checkSignature ()
{
//you must define TOKEN by yourself
if (! Defined (" TOKEN ")) {
Throw new Exception (' TOKEN is not defined! ');
}

$signature=$_GET["signature"];
$timestamp=$_GET["timestamp"];
$nonce=$_GET [" nonce "];

$token=token;
$tmpArr=array ($token, $timestamp, $nonce);
//use SORT_STRING rule
Sort ($tmpArr SORT_STRING);
$tmpStr=the implode ($tmpArr);
$tmpStr=sha1 ($tmpStr);

If ($tmpStr==$signature) {
return true;
} else {
return false;
}
}
}

?>

CodePudding user response:

http://www.111cn.net/phper/php-gj/58255.htm
Comparing to see if there is a problem of your code

CodePudding user response:

Ask what you have written in PHP WeChat, PHP development environment set up you use what tools and server? Openshift how to set up close?

CodePudding user response:

1/f, reference code of endless reply:

http://www.111cn.net/phper/php-gj/58255.htmComparing to look at your code to see if there is problem
page 404

CodePudding user response:

I am stuck in here, the code should be no problem, just can't reply
  • Related