第一步 首先注册账号成为开发者。
第二步 把图片上的token对应的值写入框架的constants.php配置文件中。
图片上的url为自己的项目路径。直接指向入口文件就行了。
token的值只要和配置文件中的token一样就行了,不一定是weixin ,可以随意定义。
constants.php中这样定义:
define('TOKEN', 'weixin');
接下来就可以做验证的判断了,我写到了commen.php控制器中,因为这个是平台和项目必须要通信成功才可以。每次的请求都会进行token验证。
我封装了个方法吗,commen控制器要继承Ci_Controller ,首要加载的控制器比如是index控制器要继承commen控制器,然后调用下面的验证方法就行了。
//验证token
public function _valid(){
$token = TOKEN;
$signature = $this->input->get('signature');
$timestamp = $this->input->get('timestamp');
$nonce = $this->input->get('nonce');
$echostr = $this->input->get('echostr');
$tmp_arr = array($token, $timestamp, $nonce);
sort($tmp_arr);
$tmp_str = implode($tmp_arr);
$tmp_str = sha1($tmp_str);
return ($tmp_str==$signature);
}
这个是只是把平台和自己的项目进行通信成功。想要了解更多请继续关注本博客的文章。