用户
 找回密码
 入住 CI 中国社区
搜索
查看: 1289|回复: 0
收起左侧

[HELP] 想用CI开发微信公众平台 token 验证错误

[复制链接]
发表于 2016-3-19 23:58:30 | 显示全部楼层 |阅读模式
今天本来想用CI试试开发微信公众平台,但是验证那里就卡死了,我是个CI的新手,不知道哪里出问题了,我是将CI压缩包直接解压在我的SEA云盘上路径是http://2222222.applinzi.com。没用CI的时候 ,我把验证代码放在根目录下的index.php文件中,验证地址为http://2222222.applinzi.com就可以验证成功了。当我用上CI后,在controller文件夹中建了个weixin.php,

class Weixin extends CI_Controller
{


    // 在微信平台上设置的对外 URL
    public function index()
    {
        if ($this->_valid())//这里是验证
        {
            // 判读是不是只是验证
            $echostr = $this->input->get('echostr');
            if (!empty($echostr))
            {
                $this->load->view('valid_view', array('output' => $echostr));
            }
            else
            {
                // 实际处理用户消息
                $this->_responseMsg();
            }
        }
        else
        {
            $this->load->view('valid_view', array('output' => 'Error!'));
        }
    }
// 用于接入验证
    private function _valid()
    {
        $token = TOKEN;

                $echoStr = $this->input->get('echostr');
        $signature = $this->input->get('signature');
        $timestamp = $this->input->get('timestamp');
        $nonce = $this->input->get('nonce');


        $tmp_arr = array($token, $timestamp, $nonce);
        sort($tmp_arr);
        $tmp_str = implode($tmp_arr);
        $tmp_str = sha1($tmp_str);

                if($tmpStr == $signature){
                        header('content-type:text');
            echo $echoStr;
            exit;
        }
    }

验证路径改为http://2222222.applinzi.com/index.php/Weixin 一直验证不成功,不知道原因是什么,请大家帮下忙

本版积分规则