123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- namespace crmeb\services;
- use app\services\system\attachment\SystemAttachmentServices;
- use crmeb\services\wechat\MiniProgram;
- use GuzzleHttp\Psr7\Utils;
- class QrcodeService
- {
-
- public static function getWechatQrcodePath(string $name, string $link, bool $force = false)
- {
-
- $systemAttchment = app()->make(SystemAttachmentServices::class);
- try {
- $imageInfo = $systemAttchment->getInfo(['name' => $name]);
- $siteUrl = sys_config('site_url');
- if (!$imageInfo) {
- $codeUrl = UtilService::setHttpType($siteUrl . $link, request()->isSsl() ? 0 : 1);
- $imageInfo = UtilService::getQRCodePath($codeUrl, $name);
- if (is_string($imageInfo) && $force)
- return false;
- if (is_array($imageInfo)) {
- $systemAttchment->attachmentAdd($imageInfo['name'], $imageInfo['size'], $imageInfo['type'], $imageInfo['dir'], $imageInfo['thumb_path'], 1, $imageInfo['image_type'], $imageInfo['time'], 2);
- $url = $imageInfo['dir'];
- } else {
- $url = '';
- $imageInfo = ['image_type' => 0];
- }
- } else $url = $imageInfo['att_dir'];
- if ($imageInfo['image_type'] == 1 && $url) $url = $siteUrl . $url;
- return $url;
- } catch (\Throwable $e) {
- if ($force)
- return false;
- else
- return '';
- }
- }
-
- public static function getRoutineQrcodePath(int $id, int $uid, int $type, array $parame = [])
- {
- $page = '';
- $namePath = '';
- $data = 'id=' . $id . '&spid=' . $uid;
- switch ($type) {
- case 1:
- $page = 'pages/activity/goods_combination_details/index';
- $namePath = 'combination_' . $id . '_' . $uid . '.jpg';
- break;
- case 2:
- $page = 'pages/activity/goods_seckill_details/index';
- $namePath = 'seckill_' . $id . '_' . $uid . '.jpg';
- if (isset($parame['stop_time']) && $parame['stop_time']) {
- $data .= '&time=' . $parame['stop_time'];
- $namePath = $parame['stop_time'] . $namePath;
- }
- break;
- }
- if (!$page || !$namePath) {
- return false;
- }
-
- $systemAttchment = app()->make(SystemAttachmentServices::class);
- try {
- $imageInfo = $systemAttchment->getInfo($namePath, 'name');
- $siteUrl = sys_config('site_url');
- if (!$imageInfo) {
- $res = MiniProgram::appCodeUnlimit($page, $data, 280);
- if (!$res) return false;
- $uploadType = (int)sys_config('upload_type', 1);
- $upload = UploadService::init($uploadType);
- $res = (string)Utils::streamFor($res);
- $res = $upload->to('routine/product')->validate()->stream($res, $namePath);
- if ($res === false) {
- return false;
- }
- $imageInfo = $upload->getUploadInfo();
- $imageInfo['image_type'] = $uploadType;
- if ($imageInfo['image_type'] == 1) $remoteImage = UtilService::remoteImage($siteUrl . $imageInfo['dir']);
- else $remoteImage = UtilService::remoteImage($imageInfo['dir']);
- if (!$remoteImage['status']) return false;
- $systemAttchment->attachmentAdd($imageInfo['name'], $imageInfo['size'], $imageInfo['type'], $imageInfo['dir'], $imageInfo['thumb_path'], 1, $imageInfo['image_type'], $imageInfo['time'], 2);
- $url = $imageInfo['dir'];
- } else $url = $imageInfo['att_dir'];
- if ($imageInfo['image_type'] == 1) $url = $siteUrl . $url;
- return $url;
- } catch (\Throwable $e) {
- return false;
- }
- }
- }
|