function wxlogin()
{
$appid = "wx8220c76bf8XXXX5";
$secret = "f6951af54c4e35XXX9912173daXXXXX";
$str="http://***.***.com/getToken";
$redirect_uri=urlencode($str);
//通过code获得 access_token + openid
$url="https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$appid."&redirect_uri=".$redirect_uri."&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect";
header("Location:" . $url);
}
function getToken()
{
$code = $_GET["code"];
$appid = "";
$secret = "";
//通过code获得 access_token + openid
$url="https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid
."&secret=" . $secret . "&code=" . $code . "&grant_type=authorization_code";
$jsonResult =$this->https_request($url);
$resultArray = json_decode($jsonResult, true);
$access_token = $resultArray["access_token"];
$openid = $resultArray["openid"];
//第三步 获取用户信息
//通过access_token + openid 获得用户所有信息,结果全部存储在$infoArray里,后面再写自己的代码逻辑
$infoUrl = "https://api.weixin.qq.com/sns/userinfo?access_token=" . $access_token . "&openid=" . $openid.'&lang=zh_CN';
$infoResult = $this->https_request($infoUrl);
$infoArray = json_decode($infoResult, true);
if($infoArray['unionid'])
{
}
}