1.使用内网传图将php运行环境映射公网(具体可以看内网传图哪一篇博客)
2.创建weixin控制器
/*
author:kaka
wechat:fangkangfk
*/
<?php
namespace app\index\controller;
use think\Controller;
use Request;
use Log;
class Weixin extends Controller
{
private $token = "kaka";
/**
* 显示资源列表
*
* @return \think\Response
*/
public function check()
{
$signature = Request::param('signature');
$timestamp = Request::param('timestamp');
$nonce = Request::param('nonce');
$echostr = Request::param('echostr');
// Log::write("=====>>signnature : " .$signnature);
// Log::write("=====>>timestamp : " .$timestamp);
// Log::write("=====>>nonce : " .$nonce);
// Log::write("=====>>echostr : " .$echostr);
// 根据字典序排序
$arrayName = array($timestamp,$nonce,$this->token);
// 转化为字符串
$temp = implode($arrayName);
// 对字符串尽心加密
$temp = sha1($temp);
if($temp == $signature){
echo $echostr;
}
}
}
3.配置微信公众号的服务器配置
服务器地址就是内网传图映射的地址
token自己写即可
这里的地址我是将public/index.php隐藏了(具体请看TP5.1隐藏public/index.php)