在ci框架中验证微信公众号token

首先建一个php文件,里面写第一个方法

public function index(){

$this -> valid();

}


然后写验证方法:

public function valid()

{

$echoStr = $_GET["echostr"];

//valid signature , option

if($this->checkSignature()){

echo $echoStr;

exit;

}

}

private function checkSignature()

{

$signature = $_GET["signature"];

$timestamp = $_GET["timestamp"];

$nonce = $_GET["nonce"];

$token = 'dapeng';

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

sort($tmpArr);

$tmpStr = implode( $tmpArr );

$tmpStr = sha1( $tmpStr );

if( $tmpStr == $signature ){

return true;

}else{

return false;

}

}



这样基本就大功告成啦,微信后台直接请求index方法.

你可能感兴趣的:(在ci框架中验证微信公众号token)