namespace app\index\controller;
use think\Db;
use think\Request;
class Wxgetuserinfo
{
public function index()
{
$appid = config('appid');
$secret = config('secret');
if (!session('?userinfo')) {
if (!isset($_GET['code'])) {//没有code,去微信接口获取code码
$request = request();
$callback = $request->url(true);//微信服务器回调url,这里是本页url
$redirect_uri = urlencode($callback);
$url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' . $appid . '&redirect_uri=' . $redirect_uri . '&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect';
header("location:$url");
exit();
} else {//获取code后跳转回来到这里了
$code = $_GET['code'];</