why.xingtongworld.com项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

44 lines
1.6 KiB

<?php
include("lib/wechat.class.php");
$token=md5('szcaee_culture');
$options = array(
'token'=>$token, //填写你设定的key
'appid'=>'wx2104ec4219a6c4c3', //填写高级调用功能的app id, 请在微信开发模式后台查询
'appsecret'=>'1322ae83f14427dea0af85b877b57376', //填写高级调用功能的密钥
);
$we_obj = new Wechat($options);
$code = isset($_GET['code'])?$_GET['code']:'';
if ($code) {
$json = $we_obj->getOauthAccessToken();
if (!$json) {
echo json_encode(['status'=>0,'msg'=>'获取用户授权失败,请重新确认']);exit;
}
$open_id = $json["openid"];
$access_token = $json['access_token'];
$userinfo = $we_obj->getUserInfo($open_id);
//var_dump($userinfo);
$wxuser=[];
if($userinfo && !empty($userinfo['nickname'])) {
$wxuser = array(
'open_id'=>$this->open_id,
'nickname'=>$userinfo['nickname'],
'sex'=>intval($userinfo['sex']),
'location'=>$userinfo['province'].'-'.$userinfo['city'],
'avatar'=>$userinfo['headimgurl']
);
} elseif (strstr($json['scope'],'snsapi_userinfo')!==false) {
$userinfo = $we_obj->getOauthUserinfo($access_token,$open_id);
if ($userinfo && !empty($userinfo['nickname'])) {
$wxuser = array(
'open_id'=>$this->open_id,
'nickname'=>$userinfo['nickname'],
'sex'=>intval($userinfo['sex']),
'location'=>$userinfo['province'].'-'.$userinfo['city'],
'avatar'=>$userinfo['headimgurl']
);
}
}
echo json_encode(['status'=>1,'data'=>$wxuser]);exit;
}
?>