qrcode.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /*
  3. * 生成二维码
  4. * @author wanghao 09.12.2016
  5. */
  6. define('IN_T',true);
  7. require_once "./source/include/init.php";
  8. require_once './source/qrcode/phpqrcode.php';
  9. $act = Common::sfilter($_REQUEST['act']);
  10. //二维码存储目录
  11. $temp = ROOT_PATH.'data/qr/';
  12. //不存在目录则创建
  13. if (!is_dir($temp)) {
  14. Common::make_dir($temp);
  15. }
  16. //物体环视项目
  17. if($act=='obj_around'){
  18. $oid = intval($_REQUEST['oid']);
  19. $obj = $Db->query('SELECT id , pk_user_main FROM '.$Base->table('object_around').' WHERE id = '.$oid,'Row');
  20. if (empty($obj)) {
  21. exit;
  22. }
  23. $QR = $temp.'obj_'.$obj['pk_user_main'].'_'.$oid.'.png';
  24. createQr($GLOBALS['_lang']['host'].'obj.php?oid='.$oid,$QR);
  25. $QR = createWithLogo($QR);
  26. header('Content-type: image/png');
  27. ob_clean();
  28. imagepng($QR);
  29. exit;
  30. }
  31. //全景视频
  32. else if($act=='video'){
  33. $vid = intval($_REQUEST['vid']);
  34. $pro = $Db->query('SELECT id , pk_user_main, cdn_host FROM '.$Base->table('video').' WHERE id = '.$vid, 'Row');
  35. if (empty($pro)) {
  36. exit;
  37. }
  38. //没有cdn_host,则取当前的cdn_host
  39. if(empty($pro['cdn_host'])){
  40. $pro['cdn_host'] = $GLOBALS['_lang']['host'];
  41. }
  42. $QR = $temp.'video_'.$pro['pk_user_main'].'_'.$vid.'.png';
  43. createQr($pro['cdn_host'].'video/play.html?vid='.$vid, $QR);
  44. $QR = createWithLogo($QR);
  45. header('Content-type: image/png');
  46. ob_clean();
  47. imagepng($QR);
  48. exit;
  49. }
  50. //全景图片
  51. else{
  52. $viewid = Common::sfilter($_REQUEST['viewid']);
  53. if (empty($viewid)) {
  54. exit;
  55. }
  56. //查询该viewid对应项目
  57. $pro = $Db->query('SELECT w.pk_works_main, p.custom_logo FROM '.$Base->table('worksmain').' as w LEFT JOIN '.$Base->table('pano_config').' as p ON p.pk_works_main=w.pk_works_main WHERE w.view_uuid = "'.$viewid.'"',"Row" );
  58. if (empty($pro)) {
  59. exit;
  60. }
  61. $QR = $temp.$viewid.'.png';
  62. //去掉二维码缓存
  63. createQr($GLOBALS['_lang']['host'].'tour/'.$viewid,$QR);
  64. // if (!file_exists($QR) ){
  65. // createQr($GLOBALS['_lang']['host'].'tour/'.$viewid,$QR);
  66. // }
  67. //生成带logo的二维码
  68. $custom_logo = $Json->decode($pro['custom_logo']);
  69. $logo;
  70. if ($custom_logo['useCustomLogo']=='1') {
  71. $logo = $custom_logo['logoImgPath'];
  72. }
  73. $QR = createWithLogo($QR,$logo);
  74. header('Content-type: image/png');
  75. ob_clean();
  76. imagepng($QR);
  77. exit;
  78. }
  79. function createQr($url,$QR){
  80. // url 路径 容错级别 大小 边距 保存并打印
  81. QRcode::png($url, $QR, 'Q', 8, 1);
  82. }
  83. function createWithLogo($QR,$logo){
  84. //设置该次请求超时时长,10s
  85. @ini_set("max_execution_time", "10");
  86. //兼容php-fpm设置超时
  87. @ini_set("request_terminate_timeout", "10");
  88. if (empty($logo)) {
  89. //使用系统的默认logo
  90. $logo = ROOT_PATH.'plugin/custom_logo/images/custom_logo.png';
  91. }
  92. $QR = imagecreatefromstring(file_get_contents($QR));
  93. $logo = imagecreatefromstring(file_get_contents($logo));
  94. if ($QR&&$logo) {
  95. $QR_width = imagesx($QR);
  96. $QR_height = imagesy($QR);
  97. $logo_width = imagesx($logo);
  98. $logo_height = imagesy($logo);
  99. $logo_qr_width = $QR_width / 4;
  100. $scale = $logo_width / $logo_qr_width;
  101. $logo_qr_height = $logo_height / $scale;
  102. $from_width = ($QR_width - $logo_qr_width) / 2;
  103. imagecopyresampled($QR, $logo, $from_width, $from_width, 0, 0, $logo_qr_width, $logo_qr_height, $logo_width, $logo_height);
  104. }
  105. return $QR;
  106. }
  107. ?>