您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

微信公众平台消息接口(PHP)-官方的Demo有问题

2024/5/4 23:11:51发布30次查看
微信公众平台消息接口(php)-官方的demo有问题 下面个人进行了处理。
事例代码也跑不通。我研究了一番,终于搞定。
首先:
在你的服务器上上传好一个接口文件,如http://www.xxx.com/weixin.php  内容如下:
 代码如下 复制代码
?valid();
//$wechatobj->responsemsg(); 
class wechatcallbackapitest
{
    public function valid()
    {
        $echostr = $_get[echostr]; 
        if($this->checksignature()){
            echo $echostr;
            exit;
        }
    } 
    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
            ;
            if(!empty( $keyword ))
            {
                $msgtype = text;
                $contentstr = mess;
                $resultstr = sprintf($texttpl, $fromusername, $tousername, $time, $msgtype, $contentstr);
                echo $resultstr;
            }else{
                echo mess;
            } 
        }else {
            echo mess;
            exit;
        }
    }
private function checksignature()
    {
        $signature = $_get[signature];
        $timestamp = $_get[timestamp];
        $nonce = $_get[nonce];
        $token =token;
        $tmparr = array($token, $timestamp, $nonce);
        sort($tmparr);
        $tmpstr = implode( $tmparr );
        $tmpstr = sha1( $tmpstr );
if( $tmpstr == $signature ){
            return true;
        }else{
            return false;
        }
    }
}
    ?>
然后:
设置回复接口,填好url和token(必须跟上面定义的token一致)
这个接口先要验证,成功之后
再注释掉$wechatobj->valid(); 这行,同时去掉//$wechatobj->responsemsg();这行的注释。
消息接口就可以使用了,发个消息试试看吧?
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product