|
- <?php
- require_once '../Common/Mysql.php';
- $openid=isset($_COOKIE['user_openid'])?$_COOKIE['user_openid']:'';
- $code=isset($_GET['code'])?$_GET['code']:'';
- if ($openid==''){
- if ($code ==''){
- $selfUrl=urlencode("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
- $getCodeUrl="https://open.weixin.qq.com/connect/oauth2/authorize?appid=".APPID."&redirect_uri=".$selfUrl."&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
- Header("Location: $getCodeUrl");
- exit();
- }else{
- $getOpenidUrl="https://api.weixin.qq.com/sns/oauth2/access_token?appid=".APPID."&secret=".APPSECRET."&code=".$code."&grant_type=authorization_code";
- $response=httpRequest($getOpenidUrl);
- $openIdObj=json_decode($response);
- $openid=$openIdObj->openid;
- setcookie('user_openid', $openid, 0, '/');
- }
- }
- echo $openid;
- ?>
|