Demo.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace app\index\controller;
  3. use app\common\controller\Frontend;
  4. use Endroid\QrCode\QrCode;
  5. use think\Response;
  6. /**
  7. * Demo接口
  8. */
  9. class Demo extends Frontend
  10. {
  11. // 使用布局
  12. protected $layout = 'bootstrap';
  13. public function _initialize()
  14. {
  15. parent::_initialize();
  16. }
  17. public function index()
  18. {
  19. return $this->view->fetch();
  20. }
  21. /**
  22. * 二维码生成
  23. */
  24. public function qrcode()
  25. {
  26. if ($this->request->get("issubmit"))
  27. {
  28. $text = $this->request->get('text');
  29. $size = $this->request->get('size');
  30. $padding = $this->request->get('padding');
  31. $errorcorrection = $this->request->get('errorcorrection');
  32. $foreground = $this->request->get('foreground', "#fff");
  33. $background = $this->request->get('background', "#000");
  34. $logo = $this->request->get('logo');
  35. $logosize = $this->request->get('logosize');
  36. $label = $this->request->get('label');
  37. $labelfontsize = $this->request->get('labelfontsize');
  38. $labelhalign = $this->request->get('labelhalign');
  39. $labelvalign = $this->request->get('labelvalign');
  40. // 前景色
  41. list($r, $g, $b) = sscanf($foreground, "#%02x%02x%02x");
  42. $foregroundcolor = ['r' => $r, 'g' => $g, 'b' => $b];
  43. // 背景色
  44. list($r, $g, $b) = sscanf($background, "#%02x%02x%02x");
  45. $backgroundcolor = ['r' => $r, 'g' => $g, 'b' => $b];
  46. $qrCode = new QrCode();
  47. $qrCode
  48. ->setText($text)
  49. ->setSize($size)
  50. ->setPadding($padding)
  51. ->setErrorCorrection($errorcorrection)
  52. ->setForegroundColor($foregroundcolor)
  53. ->setBackgroundColor($backgroundcolor)
  54. ->setLogoSize($logosize)
  55. ->setLabelFontPath(ROOT_PATH . 'public/assets/fonts/fzltxh.ttf')
  56. ->setLabel($label)
  57. ->setLabelFontSize($labelfontsize)
  58. ->setLabelHalign($labelhalign)
  59. ->setLabelValign($labelvalign)
  60. ->setImageType(QrCode::IMAGE_TYPE_PNG);
  61. if ($logo)
  62. {
  63. $qrCode->setLogo(ROOT_PATH . 'public/assets/img/qrcode.png');
  64. }
  65. //也可以直接使用render方法输出结果
  66. //$qrCode->render();
  67. return new Response($qrCode->get(), 200, ['Content-Type' => $qrCode->getContentType()]);
  68. }
  69. else
  70. {
  71. return $this->view->fetch();
  72. }
  73. }
  74. /**
  75. * Bootstrap组件
  76. */
  77. public function bootstrap()
  78. {
  79. return $this->view->fetch();
  80. }
  81. /**
  82. * 阿里大于短信发送
  83. */
  84. public function alisms()
  85. {
  86. $alisms = new \fast\service\Alisms();
  87. $ret = $alisms->mobile('your mobile')
  88. ->template('your sms template')
  89. ->sign('your sign')
  90. ->param(['code' => '8647'])
  91. ->send();
  92. dump($ret);
  93. }
  94. }