获取用户基本信息
用户登录
在用户登录时判断是否是在微信浏览器,然后获取code ,获取code时需在微信公众平台上配置域名代码片
.
public function login()
{
include_once dirname(dirname(dirname(dirname(__FILE__)))).'/addons/wxuser/getuser.php';
if(strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
//微信浏览器
if(empty(Session::get('openid'))){
/* 配置开始 */
$appid = $config['key'];
$appsecret = $config['secret'];
$redirect_uri = $url.'/xxxx.php/index/login.html';
/* 配置结束 */
$wx = new \WxService($appid,$appsecret);
$code = $this->request->get('code');
//var_dump($code);exit;
if(empty($code)){
$wx->getcode($redirect_uri);
$this->getcode();
}else{
$result = $wx->getUserInfo($code);
Session::set("openid", $result[