Rumah > pembangunan bahagian belakang > tutorial php > 为什么微信平台接口测试通过,但真正发信息却没有回复

为什么微信平台接口测试通过,但真正发信息却没有回复

WBOY
Lepaskan: 2016-06-06 20:33:04
asal
1455 orang telah melayarinya

用微信自带的消息接口调试都成功获得回应,但关注了公众号却没有回复。而且我发现在php里加入了一句插入数据库的代码,发现根本没运行(接口调试时有运行)。究竟什么原因?

<code><?php namespace Home\Controller;
use Think\Controller;
class WeixinController extends BaseController {

    public function index(){
        //define your token
        define("TOKEN", C("TOKEN"));
        $wechatObj = new \Weixin\weixin();

        if (isset($_GET['echostr'])) {
            $wechatObj->valid();
        }else{
            $this->responseMsg();
        }

    }

    private function responseMsg(){
        //get post data, May be due to the different environments
        $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];

        //extract post data
        if (!empty($postStr)){
                /* libxml_disable_entity_loader is to prevent XML eXternal Entity Injection,
                   the best way is to check the validity of xml by yourself */
                libxml_disable_entity_loader(true);
                $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
                $fromUsername = $postObj->FromUserName;
                $toUsername = $postObj->ToUserName;
                $keyword = trim($postObj->Content);
                $time = time();
                $textTpl = "<xml>
                            <tousername></tousername>
                            <fromusername></fromusername>
                            <createtime>%s</createtime>
                            <msgtype></msgtype>
                            <content></content>
                            <funcflag>0</funcflag>
                            </xml>";             
                if(!empty( $keyword ))
                {
                    $msgType = "text";
                    $contentStr = "Welcome to wechat world!";
                    $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $keyword);
                    echo $resultStr;
                }else{
                    echo "Input something...";
                }

        }else {
            echo "";
            exit;
        }
    }
    private function test($content){
        $m = M('list');
        return $m->execute("UPDATE list SET website = '{$content}' WHERE name = 'test'");
    }


}
</code>
Salin selepas log masuk
Salin selepas log masuk

回复内容:

用微信自带的消息接口调试都成功获得回应,但关注了公众号却没有回复。而且我发现在php里加入了一句插入数据库的代码,发现根本没运行(接口调试时有运行)。究竟什么原因?

<code><?php namespace Home\Controller;
use Think\Controller;
class WeixinController extends BaseController {

    public function index(){
        //define your token
        define("TOKEN", C("TOKEN"));
        $wechatObj = new \Weixin\weixin();

        if (isset($_GET['echostr'])) {
            $wechatObj->valid();
        }else{
            $this->responseMsg();
        }

    }

    private function responseMsg(){
        //get post data, May be due to the different environments
        $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];

        //extract post data
        if (!empty($postStr)){
                /* libxml_disable_entity_loader is to prevent XML eXternal Entity Injection,
                   the best way is to check the validity of xml by yourself */
                libxml_disable_entity_loader(true);
                $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
                $fromUsername = $postObj->FromUserName;
                $toUsername = $postObj->ToUserName;
                $keyword = trim($postObj->Content);
                $time = time();
                $textTpl = "<xml>
                            <tousername></tousername>
                            <fromusername></fromusername>
                            <createtime>%s</createtime>
                            <msgtype></msgtype>
                            <content></content>
                            <funcflag>0</funcflag>
                            </xml>";             
                if(!empty( $keyword ))
                {
                    $msgType = "text";
                    $contentStr = "Welcome to wechat world!";
                    $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $keyword);
                    echo $resultStr;
                }else{
                    echo "Input something...";
                }

        }else {
            echo "";
            exit;
        }
    }
    private function test($content){
        $m = M('list');
        return $m->execute("UPDATE list SET website = '{$content}' WHERE name = 'test'");
    }


}
</code>
Salin selepas log masuk
Salin selepas log masuk

...你不贴代码 怎么分析
难道打算让老夫掐指为你算一卦?

关注公众号推送的是事件,看看开发文档吧

微信接口调试,你可以使用file_put_content记录某些信息到log中,发个消息试试,我当初是这么调的

Label berkaitan:
php
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan