为了账号安全,请及时绑定邮箱和手机立即绑定

正在回答

6 回答

请问,你解决了吗

0 回复 有任何疑惑可以回复我~

$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];很可能是这行代码有问题,这行代码我是获取不到数据的,所以进不了判断。$postStr =file_get_contents("php://input"); 改用这句就可以获取xml数据,然后进入判断了。

0 回复 有任何疑惑可以回复我~

这个是代码  token已经配置成功了 大神看看为啥关注成功不回复消息 

0 回复 有任何疑惑可以回复我~

<?php

namespace app\index\controller;


class Index

{

public function index(){

//获得参数 signature nonce token timestamp echostr

$nonce     = $_GET['nonce'];

$token     = 'imooc';

$timestamp = $_GET['timestamp'];

$echostr   = $_GET['echostr'];

$signature = $_GET['signature'];

//形成数组,然后按字典序排序

$array = array();

$array = array($nonce, $timestamp, $token);

sort($array);

//拼接成字符串,sha1加密 ,然后与signature进行校验

$str = sha1( implode( $array ) );

if( $str == $signature && $echostr){

//第一次接入weixin api接口的时候

echo  $echostr;

exit;

}else{

$this->reponseMsg();

}

}

public function reponseMsg(){

$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];

        //½«xmlÊý¾Ý°üת³É¶ÔÏó

        $postObj = simplexml_load_string($postStr);

        $fromUsername = $postObj->FromUserName;

        $toUsername = $postObj->ToUserName;

        $time = time();

        if(strtolower($postObj->MsgType) == 'event') {

//判断如果是关注

        if(strtolower($postObj->Event) == 'subscribe'){

                $textTpl = "<xml>

                                <ToUserName><![CDATA[%s]]></ToUserName>

                                <FromUserName><![CDATA[%s]]></FromUserName>

                                <CreateTime>%s</CreateTime>

                                <MsgType><![CDATA[%s]]></MsgType>

                                <Content><![CDATA[%s]]></Content>

                            </xml>";

                $msgType = "text";

                $contentStr = "谢谢关注000";

                $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);

                echo $resultStr;

            }


        }

}//reponseMsg end

}


0 回复 有任何疑惑可以回复我~

我的也不行,怎么解决啊?兄弟


0 回复 有任何疑惑可以回复我~

不进else多半是代码有错,要贴代码才好找

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

to ken 配置成功 就是关注不回复

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号