Index.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace addons\pickup\controller;
  3. use app\common\controller\Api;
  4. use think\Config;
  5. use think\Validate;
  6. use think\Db;
  7. use app\common\library\Sms as Smslib;
  8. use Endroid\QrCode\QrCode;
  9. //use think\addons\Controller;
  10. use think\Response;
  11. /**
  12. * 微信接口
  13. */
  14. //class Index extends Api{
  15. class Index extends \think\addons\Controller {
  16. public function _initialize() {
  17. parent::_initialize();
  18. }
  19. /**
  20. *插件首页
  21. */
  22. public function index() {
  23. return $this->view->fetch();
  24. }
  25. //生成二维码
  26. public function qrcode() {
  27. $config = get_addon_config('qrcode');
  28. $text = $this->request->get('text', request()->domain().'/addons/pickup#/pages/index/index');
  29. $size = intval($this->request->get('size', 250));
  30. $padding = $this->request->get('padding', 5);
  31. $errorcorrection = $this->request->get('errorcorrection', 'medium');
  32. $foreground = $this->request->get('foreground', "#000000");
  33. $background = $this->request->get('background', "#ffffff");
  34. $params = [
  35. 'text' => $text,
  36. 'size' => $size,
  37. 'padding' => $padding,
  38. 'errorlevel' => $errorcorrection,
  39. 'foreground' => $foreground,
  40. 'background' => $background,
  41. 'format' => 'png',
  42. ];
  43. $qrCode = \addons\pickup\library\Service::qrcode($params);
  44. //也可以直接使用render方法输出结果
  45. $mimetype='image/png';
  46. $response = Response::create()->header("Content-Type", $mimetype);
  47. // 直接显示二维码
  48. header('Content-Type: ' . $qrCode->getContentType());
  49. $response->content($qrCode->writeString());
  50. return $response;
  51. }
  52. }