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.
 
 
 
 
 
 

63 lines
2.3 KiB

  1. <?php
  2. //调用
  3. require_once '../Common/Config.php';
  4. require_once '../Common/Function.php';
  5. if (!isset($_GET['code'])){
  6. a:
  7. $baseUrl = urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']);
  8. $url="https://open.weixin.qq.com/connect/oauth2/authorize?appid=".APPID."&redirect_uri=".$baseUrl."&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
  9. Header("Location: $url");
  10. exit();
  11. }else {
  12. $code=$_GET['code'];
  13. $openIdUrl="https://api.weixin.qq.com/sns/oauth2/access_token?appid=".APPID."&secret=".APPSECRET."&code=".$code."&grant_type=authorization_code";
  14. $openIdResult=http_request($openIdUrl);
  15. if ($openIdResult){
  16. $userInfo=json_decode($openIdResult,true);
  17. if ($userInfo['errcode'] ==40029){
  18. goto a;
  19. }
  20. $access_token=getAccesstoken();
  21. $getUserInfoUrl="https://api.weixin.qq.com/cgi-bin/user/info?access_token=".$access_token."&openid=".$userInfo['openid']."&lang=zh_CN";
  22. $getUsesrInfo=http_request($getUserInfoUrl);
  23. print_r(json_decode($getUsesrInfo,true));
  24. }
  25. }
  26. exit;
  27. /* $sql="INSERT INTO qrcode(media_id,url,createtime) values('".$media_id."','".$Rurl."','".date("Y-m-d H:i:s")."')";
  28. $pdo = new PDO("sqlsrv:Server=".HOST.";Database=".DB, USER, PASSWORD);//5.6版本pdo连接sqlsrv
  29. $result=$pdo->exec($sql);
  30. $id= $pdo->lastInsertId(); */
  31. $getOpenidListUrl="https://api.weixin.qq.com/cgi-bin/user/get?access_token=".$access_token;
  32. $getOpenidList=http_request($getOpenidListUrl);
  33. echo $getOpenidList;
  34. print_r(json_decode($getOpenidList,true));exit;
  35. if ($getOpenidList){
  36. write_log($getOpenidList);
  37. $openidList_obj=json_decode($getOpenidList);
  38. $ticket=$openidList_obj->ticket;
  39. write_log("qrcode.php-- $ticketUrl url获取ticket:".$ticket);
  40. }
  41. $qrcodeUrl="https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=".urlencode($ticket);
  42. write_log("$qrcodeUrl".$qrcodeUrl);
  43. $imageInfo=downloadImageFromWeiXin($qrcodeUrl);
  44. $dir="./Images";
  45. if (!is_dir($dir)){
  46. mkdir($dir);
  47. }
  48. $filename=$dir."/qrcode"."-".$id."-".time().".jpg";
  49. $local_file=fopen($filename, 'w');
  50. if ($local_file !==false){
  51. if(fwrite($local_file, $imageInfo["body"]) !== false){
  52. fclose($local_file);
  53. /* $filePath=dirname($_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'])."/".$filename;
  54. downfile($filePath); */
  55. }
  56. }
  57. header("Location: $qrcodeUrl");
  58. exit;