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.
 
 
 
 
 
 

60 lines
1.9 KiB

  1. <?php
  2. //调用
  3. require_once '../Common/Config.php';
  4. require_once '../Common/Function.php';
  5. if (!empty($_POST)){
  6. if( $_POST['media_id']=="" || $_POST['url']=="" ){
  7. echo "不能为空,填写真确的参数";
  8. exit;
  9. }
  10. $media_id=$_POST['media_id'];
  11. $Rurl=$_POST['url'];
  12. $sql="INSERT INTO qrcode(media_id,url,createtime) values('".$media_id."','".$Rurl."','".date("Y-m-d H:i:s")."')";
  13. $pdo = new PDO("sqlsrv:Server=".HOST.";Database=".DB, USER, PASSWORD);//5.6版本pdo连接sqlsrv
  14. $result=$pdo->exec($sql);
  15. $id= $pdo->lastInsertId();
  16. $access_token=getAccesstoken();
  17. $qrcode='{"action_name": "QR_LIMIT_STR_SCENE", "action_info": {"scene": {"scene_str": '.$id.'}}}';
  18. $ticketUrl="https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=".$access_token;
  19. $resultTicket=http_request($ticketUrl,$qrcode);
  20. if ($resultTicket){
  21. write_log($resultTicket);
  22. $ticket_obj=json_decode($resultTicket);
  23. $ticket=$ticket_obj->ticket;
  24. write_log("qrcode.php-- $ticketUrl url获取ticket:".$ticket);
  25. }
  26. $qrcodeUrl="https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=".urlencode($ticket);
  27. write_log("$qrcodeUrl".$qrcodeUrl);
  28. $imageInfo=downloadImageFromWeiXin($qrcodeUrl);
  29. $dir="./Images";
  30. if (!is_dir($dir)){
  31. mkdir($dir);
  32. }
  33. $filename=$dir."/qrcode"."-".$id."-".time().".jpg";
  34. $local_file=fopen($filename, 'w');
  35. if ($local_file !==false){
  36. if(fwrite($local_file, $imageInfo["body"]) !== false){
  37. fclose($local_file);
  38. /* $filePath=dirname($_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'])."/".$filename;
  39. downfile($filePath); */
  40. }
  41. }
  42. header("Location: $qrcodeUrl");
  43. exit;
  44. }
  45. ?>
  46. <html>
  47. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  48. <table>
  49. <tr><td align="right">media_id:</td><td><input type="text" name="media_id" value=""/></td></tr>
  50. <tr><td align="right">跳转url:</td><td><input type="text" name="url" value="" /></td></tr>
  51. </table>
  52. <input type="submit" value="提交" />
  53. </form>
  54. </html>