我用的是phpci框架,本地服务器是Apache。
class Wechatwo extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper('url_helper');
}
public function wechat_val(){
$timestamp = $_GET['timestamp'];
$nonce = $_GET['nonce'];
$token = 'weixin';
$signature = $_GET['signature'];
$echostr = $_GET['echostr'];
$array = array($timestamp,$nonce,$token);
sort($array);
$tmpstr = implode('', $array);
$tmpstr =sha1($tmpstr);
if($tmpstr==$signature && $echostr){
echo $echostr;
exit;
}else{
$this->reponseMsg();
}
}
public function reponseMsg(){
//获取到微信推送过来的post数据 xml格式
$postArr = $GLOBALS['HTTP_RAW_POST_DATA'];
$postObj = simplexml_load_file($postArr);
//判断该数据包是否是订阅的时间推送
if(strtolower($postObj->MsgType)=='event'){
if(strtolower($postObj->Event=='subscribe')){
//回复
$toUser = $postObj->FromUserName;
$fromUser = $postObj->ToUserName;
$time = time();
$MsgType = 'text';
$Content = '欢迎关注我们的微信号';
$template ="
%s
";
$info = sprintf($template,$toUser,$fromUser,$time,$MsgType,$Content);
echo $info;
}
}
}
}
上面的代码,关注微信号公众号没有消息提示发到用户那里。这是什么问题呢。如果报错哪里可以看呢?