Qrcode.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 山西牛酷信息科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com.cn
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace app\model\system;
  13. use app\model\BaseModel;
  14. use extend\QRcode as QRcodeExtend;
  15. use app\model\web\WebSite;
  16. /**
  17. * 二维码生成类
  18. */
  19. class Qrcode extends BaseModel
  20. {
  21. public function createQrcode(array $param)
  22. {
  23. try {
  24. $checkpath_result = $this->checkPath($param['qrcode_path']);
  25. if($checkpath_result["code"] != 0) return $checkpath_result;
  26. $urlParam = '';
  27. if (!empty($param['data'])) {
  28. foreach ($param['data'] as $key => $value) {
  29. if ($urlParam == '') $urlParam .= '?' . $key .'='. $value;
  30. else $urlParam .= '&' . $key .'='. $value;
  31. }
  32. }
  33. $website = new WebSite();
  34. $website_info = $website->getWebSite([['site_id', '=', 0]], 'wap_domain');
  35. $domain = !empty($website_info['data']['wap_domain']) ? $website_info['data']['wap_domain'] : '';
  36. $url = $domain . $param['page'] . $urlParam;
  37. $filename = $param['qrcode_path'] . '/' . $param['qrcode_name'] . '_' . $param['app_type'] . '.png';
  38. QRcodeExtend::png($url, $filename, 'L', 4, 1);
  39. return $this->success(['path' => $filename]);
  40. } catch (\Exception $e) {
  41. return $this->error('', $e->getMessage());
  42. }
  43. }
  44. /**
  45. * 校验目录是否可写
  46. * @param unknown $path
  47. * @return multitype:number unknown |multitype:unknown
  48. */
  49. private function checkPath($path)
  50. {
  51. if (is_dir($path) || mkdir($path, intval('0755', 8), true)) {
  52. return $this->success();
  53. }
  54. return $this->error('', "directory {$path} creation failed");
  55. }
  56. }