-
Notifications
You must be signed in to change notification settings - Fork 1
/
wxloginmobile.php
58 lines (50 loc) · 1.78 KB
/
wxloginmobile.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!DOCTYPE html>
<html>
<head>
<title>微信登陆演示</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="http://hstatic.cn/uajsapi/uajsapi.js" type="text/javascript"></script>
</head>
<body>
<?php
include_once 'comm.php';
include_once 'config.php';
$token= getData($_REQUEST, "token", "");
if(strlen($token)==0 || $wxlogin->isExprise($token)){
die("无效的参数,请重新扫描");
}else if($wxlogin->isLogined($token)){
die("不要重复登陆哦");
}
$action= getData($_REQUEST, "action", "wxlogin");
if($action=="wxlogin"){
$url= getCurrentUrl("wxloginmobile.php?token=$token&action=getinfo");
$url="https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri=".urlencode($url)
."&response_type=code&scope=snsapi_userinfo&state=123#wechat_redirect";
// die($url);
header("location:$url");
die();
}else if($action=="getinfo"){
$code=getData($_GET, "code","");
if(strlen($code)==0) return ;
$b=getWxUserInfo($code);
// var_dump($b);
$wxlogin->setUserInfo($token,$b);
echo "登陆成功,请在网页上继续操作";
}
function getWxUserInfo($code){
global $appid,$appsecret;
$url="https://api.weixin.qq.com/sns/oauth2/access_token?appid=$appid&secret=$appsecret&code=$code&grant_type=authorization_code ";
$res=file_get_contents($url);
$json= json_decode($res);
$accesstoken=$json->access_token;
$openid=$json->openid;
$url="https://api.weixin.qq.com/sns/userinfo?access_token=$accesstoken&openid=$openid&lang=zh_CN";
$res=file_get_contents($url);
$json= json_decode($res);
// var_dump($json);
return $json;
}
?>
</body>
</html>