微信公众平台 - 今天弄微信服务号的消息回复自定义php,发现用公司的服务号不能正常运行,但是用自己的公众号却可以自动回复消息

WBOY
풀어 주다: 2016-07-06 13:51:49
원래의
1283명이 탐색했습니다.

今天弄微信服务号的消息回复自定义php,发现用公司的服务号不能正常运行,但是用自己的公众号却可以自动回复消息
请问这种情况会是什么造成的

<code><?php header('Content-type:text');
define("TOKEN", "weixin");
$wechatObj = new wechatCallbackapiTest();
if (isset($_GET['echostr'])) {
    $wechatObj->valid();
}else{
    $wechatObj->responseMsg();
}

class wechatCallbackapiTest
{
    public function valid()
    {
        $echoStr = $_GET["echostr"];
        if($this->checkSignature()){
            header('content-type:text');
            echo $echoStr;
            exit;
        }
    }

    private function checkSignature()
    {
        $signature = $_GET["signature"];
        $timestamp = $_GET["timestamp"];
        $nonce = $_GET["nonce"];

        $token = TOKEN;
        $tmpArr = array($token, $timestamp, $nonce);
        sort($tmpArr, SORT_STRING);
        $tmpStr = implode( $tmpArr );
        $tmpStr = sha1( $tmpStr );

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

    public function responseMsg()
    {
        $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];

        if (!empty($postStr)){
            $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>";
            $msgType = "text";
            $contentStr = date("Y-m-d H:i:s",time())."\n\n".'hello';
            $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
            echo $resultStr;
        }else{
            echo "";
            exit;
        }
    }
}
?></code>
로그인 후 복사
로그인 후 복사

回复内容:

今天弄微信服务号的消息回复自定义php,发现用公司的服务号不能正常运行,但是用自己的公众号却可以自动回复消息
请问这种情况会是什么造成的

<code><?php header('Content-type:text');
define("TOKEN", "weixin");
$wechatObj = new wechatCallbackapiTest();
if (isset($_GET['echostr'])) {
    $wechatObj->valid();
}else{
    $wechatObj->responseMsg();
}

class wechatCallbackapiTest
{
    public function valid()
    {
        $echoStr = $_GET["echostr"];
        if($this->checkSignature()){
            header('content-type:text');
            echo $echoStr;
            exit;
        }
    }

    private function checkSignature()
    {
        $signature = $_GET["signature"];
        $timestamp = $_GET["timestamp"];
        $nonce = $_GET["nonce"];

        $token = TOKEN;
        $tmpArr = array($token, $timestamp, $nonce);
        sort($tmpArr, SORT_STRING);
        $tmpStr = implode( $tmpArr );
        $tmpStr = sha1( $tmpStr );

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

    public function responseMsg()
    {
        $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];

        if (!empty($postStr)){
            $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>";
            $msgType = "text";
            $contentStr = date("Y-m-d H:i:s",time())."\n\n".'hello';
            $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
            echo $resultStr;
        }else{
            echo "";
            exit;
        }
    }
}
?></code>
로그인 후 복사
로그인 후 복사

可以先看一下是否把自己的微信公众号配置信息当成公司的信息配置到了代码中

已解决,是两个公众号在绑定URL的时候 选择的模式不一样,选择'安全模式'会报错,选择'文明模式'能正常访问。

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!