微信授权登录后,把获取的信息存储到本地数据库中(超详细有用)!下面一起来看看吧!
<?php
namespace Home\Controller;
use Think\Controller;
class YiMuDiController extends Controller
{
/**
* 构造方法
*/
public function __construct()
{
parent::__construct();
$this->modelUserAccount = M('yimudi_account'); // 账户表
$this->wxUserInfo = session('wxUserInfo');
$this->uid = session('uid');
$this->mobile = session('mobile');
if (!$this->uid)
{
$this->uid = $this->getUserId()['user_id'];
$this->mobile = $this->getUserId()['mobile'];
session('uid', $this->uid);
session('mobile', $this->mobile);
}
}
/**
* 获取微信用户信息
* @return mixed
*/
protected function getWxUserInfo()
{
$AppId = C('AppId'); //访问配置文件的appId
$AppSecret = C('AppSecret'); //访问配置文件的appSecret
// 获取微信 code
$code = I('get.code');
if (!$code)
{
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER[