微信验证 [ 新手入门 ]
namespace frontend\controllers;
use Yii;
use yii\web\Controller;
class WeixinController extends Controller{
public $token = 'test';
private $echostr; //是否验证Token
public $postObj;
private $msgType;
//首微信接口控制器
public function actionIndex(){
if(isset($_GET["echostr"])){
$this->echostr = $_GET["echostr"];
}
//是否第一次验证
if(isset($this->echostr)){
if($this->checkSignature()){
header('content-type:text');
echo $this->echostr;
exit;
}
}else{
$path = Yii::$app->basePath;
echo $path;
echo '这是微信验证页面';
//$this->Action()
}
}
//套接字处理
private function checkSignature(){
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = $this->token;
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr, SORT_STRING);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature ){
return true;
}else{
return false;
}
}
验证网址 http://www.yourdomain.com/index.php?r=weixin
共 0 条回复
没有找到数据。
sinobill
注册时间:2017-10-26
最后登录:2020-04-03
在线时长:15小时35分
最后登录:2020-04-03
在线时长:15小时35分
- 粉丝2
- 金钱115
- 威望0
- 积分265