• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

php 搞代码 3年前 (2022-01-23) 15次浏览 已收录 0个评论
文章目录[隐藏]

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

<code><?phpheader('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);         <strong style="color:transparent">本文来源gaodai#ma#com搞@@代~&码*网/</strong><strong>搞gaodaima代码</strong>   $time = time();            $textTpl = "                                                                        %s                                                                        0                        ";            $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><?phpheader('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 = "                                                                        %s                                                                        0                        ";            $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的时候 选择的模式不一样,选择’安全模式’会报错,选择’文明模式’能正常访问。


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:微信公众平台 – 今天弄微信服务号的消息回复自定义php,发现用公司的服务号不能正常运行,但是用自己的公众号却可以自动回复消息
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址