菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
402
0

微信授权

原创
05/13 14:22
阅读数 98107

 <a class="ico_wx" href="https://open.weixin.qq.com/connect/oauth2/authorize?appid={$cfg_weixi_appkey}&redirect_uri=http://mob.handongkeji.com/pub/thirdlogin/?type=wechat&response_type=code&scope=snsapi_base&state={$code}#wechat_redirect"><em></em><span>微信</span></a>

 

public function action_thirdlogin(){

$appid = $GLOBALS['cfg_weixi_appkey'];
$appsecret = $GLOBALS['cfg_weixi_appsecret'];
$code = Arr::get($_GET, 'code');

 $rs = Common::wechat_login($appid, $appsecret,$code);

//打印rs获取用户信息

}

 

 

/**
*
* 微信授权
*/
public static function wechat_login($appid, $appsecret, $code)
{
$token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' . $appid . '&secret=' . $appsecret . '&code=' . $code . '&grant_type=authorization_code';

$token = json_decode(file_get_contents($token_url));
//var_dump($token);die;
if (isset($token->errcode)) {
return false;
}
$access_token_url = 'https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=' . $appid . '&grant_type=refresh_token&refresh_token=' . $token->refresh_token;
//转成对象
$access_token = json_decode(file_get_contents($access_token_url));
if (isset($access_token->errcode)) {
return false;
}
$user_info_url = 'https://api.weixin.qq.com/sns/userinfo?access_token=' . $access_token->access_token . '&openid=' . $access_token->openid . '&lang=zh_CN';
//转成对象
$user_info = json_decode(file_get_contents($user_info_url));
if (isset($user_info->errcode)) {
return false;
}
//var_dump($user_info);die;
$result = json_decode(json_encode($user_info), true);//返回的json数组转换成array数组
//var_dump($result);die;
return $result;
}

发表评论

0/200
402 点赞
0 评论
收藏