<?php
namespace app\index\controller;
use think\Controller;
use app\index\model\User AS UserModel;
class Index extends Controller
{
public function index()
{
$this->valid();
}
private function checkSignature()
{
$signature = $_GET["signature"];
$timestamp = $_GET["timestamp"];
$nonce = $_GET["nonce"];
$token = 'weixin';
$tmpArr = array($token, $timestamp, $nonce);
sort($tmpArr, SORT_STRING);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
if( $tmpStr == $signature ){
return true;
}else{
return false;
}
}
public function valid()//验证接口的方法
{
$echoStr = $_GET["echostr"];//从微信用户端获取一个随机字符赋予变量echostr
//valid signature , option访问地61行的checkSignature签名验证方法,如果签名一致,输出变量 echostr,完整验证配置接口的操作
if($this->checkSignature()){
echo $echoStr;
exit;
}
}
}
php 微信公众号验证实现代码
最新推荐文章于 2022-03-08 11:22:28 发布