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.
 
 
 
 

20 lines
822 B

  1. <?php
  2. require_once '../Common/Mysql.php';
  3. $openid=isset($_COOKIE['user_openid'])?$_COOKIE['user_openid']:'';
  4. $code=isset($_GET['code'])?$_GET['code']:'';
  5. if ($openid==''){
  6. if ($code ==''){
  7. $selfUrl=urlencode("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
  8. $getCodeUrl="https://open.weixin.qq.com/connect/oauth2/authorize?appid=".APPID."&redirect_uri=".$selfUrl."&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
  9. Header("Location: $getCodeUrl");
  10. exit();
  11. }else{
  12. $getOpenidUrl="https://api.weixin.qq.com/sns/oauth2/access_token?appid=".APPID."&secret=".APPSECRET."&code=".$code."&grant_type=authorization_code";
  13. $response=httpRequest($getOpenidUrl);
  14. $openIdObj=json_decode($response);
  15. $openid=$openIdObj->openid;
  16. setcookie('user_openid', $openid, 0, '/');
  17. }
  18. }
  19. echo $openid;
  20. ?>