Qrcode.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace app\admin\controller;
  3. use think\Controller;
  4. class Qrcode extends Controller
  5. {
  6. public function qrcode(){ // 流程超时提醒
  7. $yqcode = input('code','','trim');
  8. $type = input('type/d',0); // 0=不做处理 1=think
  9. if($type == 1){
  10. $yqcode = think_decrypt($yqcode);
  11. }
  12. //生成二维码图片
  13. $object = new \phpqrcode\QRcode();
  14. $level=3;
  15. $size=9;
  16. $errorCorrectionLevel =intval($level) ;//容错级别
  17. $matrixPointSize = intval($size);//生成图片大小
  18. $temp = './uploads/temp/'.md5($yqcode).'.png';
  19. $temp2 = './uploads/temp/'.md5($yqcode).'_2.png';
  20. $templogo = './uploads/temp/'.md5($yqcode).'_logo.png';
  21. $object->png($yqcode, $temp, $errorCorrectionLevel, $matrixPointSize, 2);
  22. $image = \think\Image::open($temp);
  23. //
  24. $logowidth = round($image->width()/4);
  25. //
  26. $orgId = cur_org_id();
  27. // if($orgId == 17){
  28. // $logo = './hb.png';
  29. // }else{
  30. // $logo = './logo.png';
  31. // }
  32. $logo = './logo.png';
  33. $imagelogo = \think\Image::open($logo);
  34. $imagelogo->thumb($logowidth,$logowidth,\think\Image::THUMB_SCALING)->save($templogo);
  35. $image->water($templogo,\think\Image::WATER_CENTER)->save($temp2);
  36. $QRBuffer = imagecreatefromstring(file_get_contents($temp2));
  37. @unlink($temp);
  38. @unlink($temp2);
  39. @unlink($templogo);
  40. //输出图片
  41. ob_clean();
  42. header('Content-type: image/png');
  43. imagepng($QRBuffer);
  44. exit();
  45. }
  46. public function wj_code(){ //问卷调查
  47. $get = $_GET;
  48. $r = '';
  49. $i = 1;
  50. foreach ($get as $k=>$v){
  51. if(count($get)!=$i && $k!='url'){
  52. $r.=$k.'='.$v.'&';
  53. }else{
  54. if($k!='url'){
  55. $r.=$k.'='.$v;
  56. }else{
  57. if(count($get)==$i){
  58. $r.=$v;
  59. }else{
  60. $r.=$v.'&';
  61. }
  62. }
  63. }
  64. $i++;
  65. }
  66. // $value = $_GET['url'];//二维码内容
  67. $yqcode =$r;//二维码内容
  68. if (empty($yqcode)) {
  69. $this->error('URL不能为空');
  70. }
  71. //生成二维码图片
  72. $object = new \phpqrcode\QRcode();
  73. $level=3;
  74. $size=9;
  75. $errorCorrectionLevel =intval($level) ;//容错级别
  76. $matrixPointSize = intval($size);//生成图片大小
  77. $temp = './uploads/temp/'.md5($yqcode).'.png';
  78. $temp2 = './uploads/temp/'.md5($yqcode).'_2.png';
  79. $templogo = './uploads/temp/'.md5($yqcode).'_logo.png';
  80. $object->png($yqcode, $temp, $errorCorrectionLevel, $matrixPointSize, 2);
  81. $image = \think\Image::open($temp);
  82. //
  83. $logowidth = round($image->width()/4);
  84. //
  85. $orgId = cur_org_id();
  86. // if($orgId == 17){
  87. // $logo = './hb.png';
  88. // }else{
  89. // $logo = './logo.png';
  90. // }
  91. $logo = './logo.png';
  92. $imagelogo = \think\Image::open($logo);
  93. $imagelogo->thumb($logowidth,$logowidth,\think\Image::THUMB_SCALING)->save($templogo);
  94. $image->water($templogo,\think\Image::WATER_CENTER)->save($temp2);
  95. $QRBuffer = imagecreatefromstring(file_get_contents($temp2));
  96. @unlink($temp);
  97. @unlink($temp2);
  98. @unlink($templogo);
  99. //输出图片
  100. ob_clean();
  101. header('Content-type: image/png');
  102. imagepng($QRBuffer);
  103. exit();
  104. }
  105. }