微信客户端发消息给公众号后,自身服务器能够接受到微信服务器推送过来的消息,但无法返回消息给微信服务器,不知道问题出在哪里,这种情况该怎么调试?请大神指点,以下是代码
public function index(){
// echo '1234567890';
if (isset($_GET["echostr"])){
$echostr = $_GET["echostr"];
if ($this->checkSignature()){
return $echostr;
}}else {
//此处写业务逻辑simplexml_load_string
$this->responseMsg();
}
}
public function responseMsg()
{
$result=null;
$postStr = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : file_get_contents("php://input");
if (!empty($postStr)){
libxml_disable_entity_loader(true);
$postObj = simplexml_load_string($postStr,'SimpleXMLElement',LIBXML_NOCDATA);
$RX_TYPE = trim($postObj->MsgType);
DB::execute($sql);
switch ($RX_TYPE)
{
case "event":
$result=$this->receiveEvent($postObj);
break;
case "text":
$content=trim($postObj->Content);
$result=$this->receiveText($postObj);
echo $result;
break;
default:
echo "";
;
}
// echo $result;
}else {
echo "";
exit;
}
}
public function receiveText($postObj)
{
Db::execute(" insert into tempNo (billno) values('欢迎2')");
$content = "";
switch ($postObj->Content)
{
case "5": //
$content = "欢迎关注";
break;
case "1": //
$content = "欢迎关注";
break;
case "user_get_card":
$content="事件测试消息2。";
break;
case "text":
$content="事件测试消息1。";
break;
}
$result= $this->transmitText($postObj, $content);
return $result;
}
public function transmitText($object, $content)
{
$textTpl = "<xml><ToUserName><![CDATA[%s]]></ToUserName><FromUserName><![CDATA[%s]]></FromUserName><CreateTime>%s</CreateTime><MsgType><![CDATA[%s]]></MsgType><Content><![CDATA[%s]]></Content></xml>";
$fromUser=trim($object->FromUserName);
$toUserName=trim($object->ToUserName);
$time=time();
$msgType='text';
$result= sprintf($textTpl,$fromUser,$toUserName,$time,$msgType,$content);
Db::execute(" insert into tempNo (ctext) values('transmitText')");
return $result;
}
以下是相关的代码
public function index(){
Db::execute(' insert into tempNo (billno) values(123)');
// echo '1234567890';
if (isset($_GET["echostr"])){
$echostr = $_GET["echostr"];
if ($this->checkSignature()){
return $echostr;
}}else {
//此处写业务逻辑simplexml_load_string
$this->responseMsg();
}
}
public function responseMsg()
{
$result=null;
$postStr = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : file_get_contents("php://input");
if (!empty($postStr)){
libxml_disable_entity_loader(true);
$postObj = simplexml_load_string($postStr,'SimpleXMLElement',LIBXML_NOCDATA);
$RX_TYPE = trim($postObj->MsgType);
DB::execute($sql);
switch ($RX_TYPE)
{
case "event":
$result=$this->receiveEvent($postObj);
break;
case "text":
$content=trim($postObj->Content);
$result=$this->receiveText($postObj);
echo $result;
break;
default:
echo "";
;
}
// echo $result;
}else {
echo "";
exit;
}
}
public function receiveText($postObj)
{
Db::execute(" insert into tempNo (billno) values('欢迎2')");
$content = "";
switch ($postObj->Content)
{
case "5": //
$content = "欢迎关注";
break;
case "1": //
$content = "欢迎关注";
break;
case "user_get_card":
$content="事件测试消息2。";
break;
case "text":
$content="事件测试消息1。";
break;
}
$result= $this->transmitText($postObj, $content);
return $result;
}
public function transmitText($object, $content)
{
$textTpl = "<xml><ToUserName><![CDATA[%s]]></ToUserName><FromUserName><![CDATA[%s]]></FromUserName><CreateTime>%s</CreateTime><MsgType><![CDATA[%s]]></MsgType><Content><![CDATA[%s]]></Content></xml>";
$fromUser=trim($object->FromUserName);
$toUserName=trim($object->ToUserName);
$time=time();
$msgType='text';
$result= sprintf($textTpl,$fromUser,$toUserName,$time,$msgType,$content);
Db::execute(" insert into tempNo (ctext) values('transmitText')");
return $result;
}
不知道哪里原因导致消息无法返回