UtilService.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. <?php
  2. /**
  3. *
  4. * @author: xaboy<365615158@qq.com>
  5. * @day: 2017/11/02
  6. */
  7. namespace crmeb\services;
  8. use crmeb\exceptions\UtilException;
  9. use think\facade\Config;
  10. use dh2y\qrcode\QRcode;
  11. use crmeb\services\upload\Upload;
  12. class UtilService
  13. {
  14. public static function filtrate($string, $admin = false)
  15. {
  16. $ra = array(
  17. // '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  18. '/script/',
  19. '/javascript/',
  20. '/vbscript/',
  21. '/expression/',
  22. '/applet/',
  23. '/meta/',
  24. '/xml/',
  25. '/blink/',
  26. '/link/',
  27. '/style/',
  28. '/embed/',
  29. '/object/',
  30. '/frame/',
  31. '/layer/',
  32. '/title/',
  33. '/bgsound/',
  34. '/base/',
  35. '/onload/',
  36. '/onunload/',
  37. '/onchange/',
  38. '/onsubmit/',
  39. '/onreset/',
  40. '/onselect/',
  41. '/onblur/',
  42. '/onfocus/',
  43. '/onabort/',
  44. '/onkeydown/',
  45. '/onkeypress/',
  46. '/onkeyup/',
  47. '/onclick/',
  48. '/ondblclick/',
  49. '/onmousedown/',
  50. '/onmousemove/',
  51. '/onmouseout/',
  52. '/onmouseover/',
  53. '/onmouseup/',
  54. '/onunload/',
  55. "/<(\\/?)(script|i?frame|style|html|body|title|link|meta|object|\\?|\\%)([^>]*?)>/isU",
  56. "/(<[^>]*)on[a-zA-Z]+\s*=([^>]*>)/isU",
  57. );
  58. $str = preg_replace($ra, "", $string);
  59. if ($admin) {
  60. return $str;
  61. }
  62. return addslashes($str);
  63. }
  64. public static function sweep($array, $admin = false)
  65. {
  66. if (is_array($array)) {
  67. foreach ($array as $k => $v) {
  68. $array[$k] = self::sweep($v, $admin);
  69. }
  70. } else {
  71. $array = self::filtrate($array, $admin);
  72. }
  73. return $array;
  74. }
  75. /**
  76. * 获取POST请求的数据
  77. * @param $params
  78. * @param null $request
  79. * @param bool $suffix
  80. * @return array
  81. */
  82. public static function postMore($params, $request = null, $suffix = false, $admin = false)
  83. {
  84. if ($request === null) $request = app('request');
  85. $p = [];
  86. $i = 0;
  87. foreach ($params as $param) {
  88. if (!is_array($param)) {
  89. $p[$suffix == true ? $i++ : $param] = self::sweep($request->param($param), $admin);
  90. } else {
  91. if (!isset($param[1])) $param[1] = null;
  92. if (!isset($param[2])) $param[2] = '';
  93. if (!isset($param[3])) $param[3] = '';
  94. if (!isset($param[4])) $param[4] = '';
  95. if (!isset($param[5])) $param[5] = '';
  96. if (is_array($param[0])) {
  97. $name = is_array($param[1]) ? $param[0][0] . '/a' : $param[0][0] . '/' . $param[0][1];
  98. $keyName = $param[0][0];
  99. } else {
  100. $name = is_array($param[1]) ? $param[0] . '/a' : $param[0];
  101. $keyName = $param[0];
  102. }
  103. $p[$suffix == true ? $i++ : ($param[3] ? $param[3] : $keyName)] = self::sweep($request->param($name, $param[1], $param[2]), $admin);
  104. if (not_empty_check($param[4])) {
  105. if (!is_array($param[4])) {
  106. if (is_string($param[4]) && !function_exists($param[4])) {
  107. throw new UtilException('验证的方法' . $param[4] . '未定义');
  108. }
  109. if (!$param[4]($request->param($name, $param[1], $param[2]))) {
  110. throw new UtilException($param[5]);
  111. }
  112. } else {
  113. foreach ($param[4] as $k => $v) {
  114. if (is_string($v) && !function_exists($v)) {
  115. throw new UtilException('验证的方法' . $v . '未定义');
  116. }
  117. if (!$v($request->param($name, $param[1], $param[2]))) {
  118. throw new UtilException(is_array($param[5]) ? $param[5][$k] : $param[5]);
  119. }
  120. }
  121. }
  122. }
  123. }
  124. }
  125. return $p;
  126. }
  127. /**
  128. * 获取请求的数据
  129. * @param $params
  130. * @param null $request
  131. * @param bool $suffix
  132. * @return array
  133. */
  134. public static function getMore($params, $request = null, $suffix = false)
  135. {
  136. if ($request === null) $request = app('request');
  137. $p = [];
  138. $i = 0;
  139. foreach ($params as $param) {
  140. if (!is_array($param)) {
  141. $p[$suffix == true ? $i++ : $param] = self::sweep($request->param($param));
  142. } else {
  143. if (!isset($param[1])) $param[1] = null;
  144. if (!isset($param[2])) $param[2] = '';
  145. if (!isset($param[3])) $param[3] = '';
  146. if (!isset($param[4])) $param[4] = '';
  147. if (!isset($param[5])) $param[5] = '参数错误';
  148. if (is_array($param[0])) {
  149. $name = is_array($param[1]) ? $param[0][0] . '/a' : $param[0][0] . '/' . $param[0][1];
  150. $keyName = $param[0][0];
  151. } else {
  152. $name = is_array($param[1]) ? $param[0] . '/a' : $param[0];
  153. $keyName = $param[0];
  154. }
  155. $p[$suffix == true ? $i++ : ($param[3] ? $param[3] : $keyName)] = self::sweep($request->param($name, $param[1], $param[2]));
  156. if (not_empty_check($param[4])) {
  157. if (!is_array($param[4])) {
  158. if (is_string($param[4]) && !function_exists($param[4])) {
  159. throw new UtilException('验证的方法' . $param[4] . '未定义');
  160. }
  161. if (!$param[4]($request->param($name, $param[1], $param[2]))) {
  162. throw new UtilException($param[5]);
  163. }
  164. } else {
  165. foreach ($param[4] as $k => $v) {
  166. if (is_string($v) && !function_exists($v)) {
  167. throw new UtilException('验证的方法' . $v . '未定义');
  168. }
  169. if (!$v($request->param($name, $param[1], $param[2]))) {
  170. throw new UtilException(is_array($param[5]) ? $param[5][$k] : $param[5]);
  171. }
  172. }
  173. }
  174. }
  175. }
  176. }
  177. return $p;
  178. }
  179. /**
  180. * TODO 砍价 拼团 分享海报生成
  181. * @param array $data
  182. * @param $path
  183. * @return array|bool|string
  184. * @throws \Exception
  185. */
  186. public static function setShareMarketingPoster($data = array(), $path)
  187. {
  188. $config = array(
  189. 'text' => array(
  190. array(
  191. 'text' => $data['price'],//TODO 价格
  192. 'left' => 116,
  193. 'top' => 200,
  194. 'fontPath' => app()->getRootPath() . 'public/static/font/Alibaba-PuHuiTi-Regular.otf', //字体文件
  195. 'fontSize' => 50, //字号
  196. 'fontColor' => '255,0,0', //字体颜色
  197. 'angle' => 0,
  198. ),
  199. array(
  200. 'text' => $data['label'],//TODO 标签
  201. 'left' => 450,
  202. 'top' => 188,
  203. 'fontPath' => app()->getRootPath() . 'public/static/font/Alibaba-PuHuiTi-Regular.otf', //字体文件
  204. 'fontSize' => 24, //字号
  205. 'fontColor' => '255,255,255', //字体颜色
  206. 'angle' => 0,
  207. ),
  208. array(
  209. 'text' => $data['msg'],//TODO 简述
  210. 'left' => 80,
  211. 'top' => 270,
  212. 'fontPath' => app()->getRootPath() . 'public/static/font/Alibaba-PuHuiTi-Regular.otf', //字体文件
  213. 'fontSize' => 22, //字号
  214. 'fontColor' => '40,40,40', //字体颜色
  215. 'angle' => 0,
  216. )
  217. ),
  218. 'image' => array(
  219. array(
  220. 'url' => $data['image'], //图片
  221. 'stream' => 0,
  222. 'left' => 120,
  223. 'top' => 340,
  224. 'right' => 0,
  225. 'bottom' => 0,
  226. 'width' => 450,
  227. 'height' => 450,
  228. 'opacity' => 100
  229. ),
  230. array(
  231. 'url' => $data['url'], //二维码资源
  232. 'stream' => 0,
  233. 'left' => 260,
  234. 'top' => 890,
  235. 'right' => 0,
  236. 'bottom' => 0,
  237. 'width' => 160,
  238. 'height' => 160,
  239. 'opacity' => 100
  240. )
  241. ),
  242. 'background' => 'static/poster/poster.jpg'
  243. );
  244. if (!file_exists($config['background'])) exception('缺少系统预设背景图片');
  245. if (strlen($data['title']) < 36) {
  246. $text = array(
  247. 'text' => $data['title'],//TODO 标题
  248. 'left' => 76,
  249. 'top' => 100,
  250. 'fontPath' => app()->getRootPath() . 'public/static/font/Alibaba-PuHuiTi-Regular.otf', //字体文件
  251. 'fontSize' => 32, //字号
  252. 'fontColor' => '0,0,0', //字体颜色
  253. 'angle' => 0,
  254. );
  255. array_push($config['text'], $text);
  256. } else {
  257. $titleOne = array(
  258. 'text' => mb_strimwidth($data['title'], 0, 24),//TODO 标题
  259. 'left' => 76,
  260. 'top' => 70,
  261. 'fontPath' => app()->getRootPath() . 'public/static/font/Alibaba-PuHuiTi-Regular.otf', //字体文件
  262. 'fontSize' => 32, //字号
  263. 'fontColor' => '0,0,0', //字体颜色
  264. 'angle' => 0,
  265. );
  266. $titleTwo = array(
  267. 'text' => mb_strimwidth($data['title'], 24, 24),//TODO 标题
  268. 'left' => 76,
  269. 'top' => 120,
  270. 'fontPath' => app()->getRootPath() . 'public/static/font/Alibaba-PuHuiTi-Regular.otf', //字体文件
  271. 'fontSize' => 32, //字号
  272. 'fontColor' => '0,0,0', //字体颜色
  273. 'angle' => 0,
  274. );
  275. array_push($config['text'], $titleOne);
  276. array_push($config['text'], $titleTwo);
  277. }
  278. return self::setSharePoster($config, $path);
  279. }
  280. /**
  281. * TODO 生成分享二维码图片(增强版:支持圆形头像、透明、错误处理)
  282. * @param array $config
  283. * @param $path
  284. * @return array|bool|string
  285. * @throws \Exception
  286. */
  287. public static function setSharePoster($config = array(), $path)
  288. {
  289. $imageDefault = array(
  290. 'left' => 0,
  291. 'top' => 0,
  292. 'right' => 0,
  293. 'bottom' => 0,
  294. 'width' => 100,
  295. 'height' => 100,
  296. 'opacity' => 100,
  297. 'circle' => false, // 新增:圆形蒙版
  298. 'border_width' => 0, // 新增:边框宽(px)
  299. 'border_color' => '0,0,0' // 新增:边框色 RGB
  300. );
  301. $textDefault = array(
  302. 'text' => '',
  303. 'left' => 0,
  304. 'top' => 0,
  305. 'fontSize' => 32,
  306. 'fontColor' => '255,255,255',
  307. 'angle' => 0,
  308. );
  309. $background = $config['background'];
  310. if (substr($background, 0, 1) === '/') {
  311. $background = substr($background, 1);
  312. }
  313. $bgInfo = getimagesize($background);
  314. if (!$bgInfo) return '背景图无效';
  315. $background = imagecreatefromstring(file_get_contents($background));
  316. if (!$background) return '背景图加载失败';
  317. $backgroundWidth = $bgInfo[0];
  318. $backgroundHeight = $bgInfo[1];
  319. $imageRes = imagecreatetruecolor($backgroundWidth, $backgroundHeight);
  320. $black = imagecolorallocate($imageRes, 0, 0, 0);
  321. imagefill($imageRes, 0, 0, $black);
  322. imagecopyresampled($imageRes, $background, 0, 0, 0, 0, $backgroundWidth, $backgroundHeight, imagesx($background), imagesy($background));
  323. imagedestroy($background);
  324. $hasCircle = false; // 新增:检测是否 PNG 输出
  325. if (!empty($config['image'])) {
  326. foreach ($config['image'] as $key => $val) {
  327. $val = array_merge($imageDefault, $val);
  328. $info = @getimagesize($val['url']); // 加@
  329. if (!$info) {
  330. error_log("海报图像加载失败: {$val['url']}"); // 日志
  331. continue; // 跳过无效图
  332. }
  333. $ext = image_type_to_extension($info[2], false);
  334. $function = 'imagecreatefrom' . $ext;
  335. if ($val['stream']) {
  336. $info = @getimagesizefromstring($val['url']);
  337. $function = 'imagecreatefromstring';
  338. }
  339. $res = @$function($val['url']);
  340. if (!$res) {
  341. error_log("海报图像创建失败: {$val['url']}, type: $ext");
  342. continue;
  343. }
  344. $resWidth = $info[0];
  345. $resHeight = $info[1];
  346. // ===== 修复:透明 canvas =====
  347. $canvas = imagecreatetruecolor($val['width'], $val['height']);
  348. imagesavealpha($canvas, true);
  349. imagealphablending($canvas, false);
  350. $transparent = imagecolorallocatealpha($canvas, 0, 0, 0, 127);
  351. imagefill($canvas, 0, 0, $transparent);
  352. // 合成源图
  353. imagealphablending($canvas, true);
  354. imagecopyresampled($canvas, $res, 0, 0, 0, 0, $val['width'], $val['height'], $resWidth, $resHeight);
  355. imagedestroy($res);
  356. // ===== 新增:圆形蒙版 =====
  357. if ($val['circle']) {
  358. $hasCircle = true;
  359. $radius = min($val['width'], $val['height']) / 2 - 1;
  360. $centerX = $val['width'] / 2;
  361. $centerY = $val['height'] / 2;
  362. // 创建蒙版(白圆 = 保留,透明外)
  363. $mask = imagecreatetruecolor($val['width'], $val['height']);
  364. imagesavealpha($mask, true);
  365. imagefill($mask, 0, 0, $transparent);
  366. $maskWhite = imagecolorallocatealpha($mask, 255, 255, 255, 0); // 全不透明白
  367. imagefilledellipse($mask, $centerX, $centerY, $radius * 2, $radius * 2, $maskWhite);
  368. // 像素蒙版合成(高效小图)
  369. for ($x = 0; $x < $val['width']; $x++) {
  370. for ($y = 0; $y < $val['height']; $y++) {
  371. $maskRgb = imagecolorat($mask, $x, $y);
  372. $alpha = 127 - (($maskRgb >> 16) & 0x7F); // 白→低alpha(保留)
  373. if ($alpha > 64) { // 阈值,外透明
  374. imagesetpixel($canvas, $x, $y, $transparent);
  375. }
  376. }
  377. }
  378. imagedestroy($mask);
  379. }
  380. // ===== 新增:边框(可选,圆形增强) =====
  381. if ($val['border_width'] > 0) {
  382. list($r, $g, $b) = explode(',', $val['border_color']);
  383. $borderColor = imagecolorallocate($canvas, $r, $g, $b);
  384. $borderRadius = min($val['width'], $val['height']) / 2;
  385. imagefilledellipse($canvas, $centerX, $centerY, $borderRadius * 2, $borderRadius * 2, $borderColor);
  386. // 内减边框宽
  387. $innerRadius = $borderRadius - $val['border_width'] * 2;
  388. imagefilledellipse($canvas, $centerX, $centerY, $innerRadius * 2, $innerRadius * 2, $transparent);
  389. }
  390. // 位置调整 + 合成
  391. $val['left'] = $val['left'] < 0 ? $backgroundWidth - abs($val['left']) - $val['width'] : $val['left'];
  392. $val['top'] = $val['top'] < 0 ? $backgroundHeight - abs($val['top']) - $val['height'] : $val['top'];
  393. imagecopymerge($imageRes, $canvas, $val['left'], $val['top'], $val['right'], $val['bottom'], $val['width'], $val['height'], $val['opacity']);
  394. imagedestroy($canvas);
  395. }
  396. }
  397. // 文字不变(你的动态 left 已完美)
  398. if (isset($config['text']) && !empty($config['text'])) {
  399. foreach ($config['text'] as $key => $val) {
  400. $val = array_merge($textDefault, $val);
  401. list($R, $G, $B) = explode(',', $val['fontColor']);
  402. $fontColor = imagecolorallocate($imageRes, $R, $G, $B);
  403. $val['left'] = $val['left'] < 0 ? $backgroundWidth - abs($val['left']) : $val['left'];
  404. $val['top'] = $val['top'] < 0 ? $backgroundHeight - abs($val['top']) : $val['top'];
  405. imagettftext($imageRes, $val['fontSize'], $val['angle'], $val['left'], $val['top'], $fontColor, $val['fontPath'], $val['text']);
  406. }
  407. }
  408. // ===== 输出:PNG if circle =====
  409. ob_start();
  410. $key = substr(md5(rand(0, 9999)), 0, 5) . date('YmdHis') . rand(0, 999999);
  411. $key .= $hasCircle ? '.png' : '.jpg';
  412. if ($hasCircle) {
  413. imagesavealpha($imageRes, true);
  414. imagepng($imageRes);
  415. } else {
  416. imagejpeg($imageRes);
  417. }
  418. imagedestroy($imageRes);
  419. $res = ob_get_contents();
  420. ob_end_clean();
  421. // 上传不变
  422. $uploadType = (int)sys_config('upload_type', 1);
  423. $upload = new Upload($uploadType, [ /* 配置不变 */ ]);
  424. $res = $upload->to($path)->validate()->stream($res, $key);
  425. if ($res === false) {
  426. return $upload->getError();
  427. } else {
  428. $info = $upload->getUploadInfo();
  429. $info['image_type'] = $uploadType;
  430. return $info;
  431. }
  432. }
  433. /**
  434. * TODO 获取小程序二维码是否生成
  435. * @param $url
  436. * @return array
  437. */
  438. public static function remoteImage($url)
  439. {
  440. $curl = curl_init();
  441. curl_setopt($curl, CURLOPT_URL, $url);
  442. curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  443. $result = curl_exec($curl);
  444. $result = json_decode($result, true);
  445. if (is_array($result)) return ['status' => false, 'msg' => $result['errcode'] . '---' . $result['errmsg']];
  446. return ['status' => true];
  447. }
  448. /**
  449. * TODO 修改 https 和 http 移动到common
  450. * @param $url $url 域名
  451. * @param int $type 0 返回https 1 返回 http
  452. * @return string
  453. */
  454. public static function setHttpType($url, $type = 0)
  455. {
  456. $domainTop = substr($url, 0, 5);
  457. if ($type) {
  458. if ($domainTop == 'https') $url = 'http' . substr($url, 5, strlen($url));
  459. } else {
  460. if ($domainTop != 'https') $url = 'https:' . substr($url, 5, strlen($url));
  461. }
  462. return $url;
  463. }
  464. /**
  465. * 获取二维码
  466. * @param $url
  467. * @param $name
  468. * @return array|bool|string
  469. */
  470. public static function getQRCodePath($url, $name)
  471. {
  472. if (!strlen(trim($url)) || !strlen(trim($name))) return false;
  473. try {
  474. $uploadType = sys_config('upload_type');
  475. //TODO 没有选择默认使用本地上传
  476. if (!$uploadType) $uploadType = 1;
  477. $uploadType = (int)$uploadType;
  478. $siteUrl = sys_config('site_url');
  479. if (!$siteUrl) return '请前往后台设置->系统设置->网站域名 填写您的域名格式为:http://域名';
  480. $info = [];
  481. $outfile = Config::get('qrcode.cache_dir');
  482. $code = new QRcode();
  483. $wapCodePath = $code->png($url, $outfile . '/' . $name)->getPath(); //获取二维码生成的地址
  484. $content = file_get_contents('.' . $wapCodePath);
  485. if ($uploadType === 1) {
  486. $info["code"] = 200;
  487. $info["name"] = $name;
  488. $info["dir"] = $wapCodePath;
  489. $info["time"] = time();
  490. $info['size'] = 0;
  491. $info['type'] = 'image/png';
  492. $info["image_type"] = 1;
  493. $info['thumb_path'] = $wapCodePath;
  494. return $info;
  495. } else {
  496. $upload = new Upload($uploadType, [
  497. 'accessKey' => sys_config('accessKey'),
  498. 'secretKey' => sys_config('secretKey'),
  499. 'uploadUrl' => sys_config('uploadUrl'),
  500. 'storageName' => sys_config('storage_name'),
  501. 'storageRegion' => sys_config('storage_region'),
  502. ]);
  503. $res = $upload->to($outfile)->validate()->stream($content, $name);
  504. if ($res === false) {
  505. return $upload->getError();
  506. }
  507. $info = $upload->getUploadInfo();
  508. $info['image_type'] = $uploadType;
  509. return $info;
  510. }
  511. } catch (\Exception $e) {
  512. return $e->getMessage();
  513. }
  514. }
  515. /**
  516. * @param array $data
  517. * @param string $path
  518. * @return array|bool|string
  519. * @throws \Exception
  520. */
  521. public static function setShareProductPoster($data = array(), $path = '')
  522. {
  523. $config = array(
  524. 'text' => array(
  525. array(
  526. 'text' => $data['price'],//TODO 价格
  527. 'left' => 219,
  528. 'top' => 1055,
  529. 'fontPath' => app()->getRootPath() . 'public/static/font/Alibaba-PuHuiTi-Regular.otf', //字体文件
  530. 'fontSize' => 50, //字号
  531. 'fontColor' => '131,28,32', //字体颜色
  532. 'angle' => 0,
  533. ),
  534. array(
  535. 'text' => '原价:¥' . $data['ot_price'],//TODO 原价
  536. 'left' => 94,
  537. 'top' => 1105,
  538. 'fontPath' => app()->getRootPath() . 'public/static/font/Alibaba-PuHuiTi-Light-My.otf', //字体文件
  539. 'fontSize' => 18, //字号
  540. 'fontColor' => '0,0,0', //字体颜色
  541. 'angle' => 0,
  542. ),
  543. array(
  544. 'text' => $data['user_nickname'],//TODO 用户名
  545. 'left' => 220,
  546. 'top' => 240,
  547. 'fontPath' => app()->getRootPath() . 'public/static/font/Alibaba-PuHuiTi-Light.ttf', //字体文件
  548. 'fontSize' => 20, //字号
  549. 'fontColor' => '0,0,0', //字体颜色
  550. 'angle' => 0,
  551. ),
  552. array(
  553. 'text' => implode($data['user_nickname_pinyin'], ' '),//TODO 用户名拼音
  554. 'left' => 220,
  555. 'top' => 260,
  556. 'fontPath' => app()->getRootPath() . 'public/static/font/Alibaba-PuHuiTi-Light.ttf', //字体文件
  557. 'fontSize' => 10, //字号
  558. 'fontColor' => '0,0,0', //字体颜色
  559. 'angle' => 0,
  560. ),
  561. ),
  562. 'image' => array(
  563. array(
  564. 'url' => $data['image'], //图片
  565. 'stream' => 0,
  566. 'left' => 94,
  567. 'top' => 359,
  568. 'right' => 0,
  569. 'bottom' => 0,
  570. 'width' => 561,
  571. 'height' => 613,
  572. 'opacity' => 100
  573. ),
  574. array(
  575. 'url' => $data['url'], //二维码资源
  576. 'stream' => 0,
  577. 'left' => 557,
  578. 'top' => 1013,
  579. 'right' => 0,
  580. 'bottom' => 0,
  581. 'width' => 99,
  582. 'height' => 99,
  583. 'opacity' => 100
  584. ),
  585. array(
  586. 'url' => $data['user_avatar'], //头像资源
  587. 'stream' => 0,
  588. 'left' => 98,
  589. 'top' => 211,
  590. 'right' => 0,
  591. 'bottom' => 0,
  592. 'width' => 92,
  593. 'height' => 92,
  594. 'opacity' => 100
  595. )
  596. ),
  597. 'background' => 'static/poster/product.jpg'
  598. );
  599. if (!file_exists($config['background'])) exception('缺少系统预设背景图片');
  600. if (strlen($data['title']) < 27) {
  601. $text = array(
  602. 'text' => $data['title'],//TODO 标题
  603. 'left' => 130,
  604. 'top' => 1172,
  605. 'fontPath' => app()->getRootPath() . 'public/static/font/Alibaba-PuHuiTi-Regular.otf', //字体文件
  606. 'fontSize' => 22, //字号
  607. 'fontColor' => '255,255,255', //字体颜色
  608. 'angle' => 0,
  609. );
  610. array_push($config['text'], $text);
  611. } else {
  612. $titleOne = array(
  613. 'text' => mb_substr($data['title'], 0, 8) . '…',//TODO 标题
  614. 'left' => 130,
  615. 'top' => 1172,
  616. 'fontPath' => app()->getRootPath() . 'public/static/font/Alibaba-PuHuiTi-Regular.otf', //字体文件
  617. 'fontSize' => 22, //字号
  618. 'fontColor' => '255,255,255', //字体颜色
  619. 'angle' => 0,
  620. );
  621. /*$titleTwo = array(
  622. 'text' => mb_substr($data['title'], 12, 12),//TODO 标题
  623. 'left' => 60,
  624. 'top' => 1310,
  625. 'fontPath' => app()->getRootPath() . 'public/static/font/Alibaba-PuHuiTi-Regular.otf', //字体文件
  626. 'fontSize' => 40, //字号
  627. 'fontColor' => '255,255,255', //字体颜色
  628. 'angle' => 0,
  629. );*/
  630. array_push($config['text'], $titleOne);
  631. // array_push($config['text'], $titleTwo);
  632. }
  633. return self::setSharePoster($config, $path);
  634. }
  635. }