| | |
| | | /* @var array $config 名片设置 */ |
| | | private $config; |
| | | public $template; |
| | | private $businessName; |
| | | |
| | | /** |
| | | * 构造方法 |
| | |
| | | * @param $dealer |
| | | * @throws \Exception |
| | | */ |
| | | public function __construct($dealer) |
| | | public function __construct($dealer,$businessName='business') |
| | | { |
| | | parent::__construct(); |
| | | // 用户信息 |
| | | $this->dealer = $dealer; |
| | | $this->businessName = $businessName; |
| | | $this->template = (new Template())->detail($dealer['template_id']); |
| | | // 名片设置 |
| | | $this->config = json_decode($this->template['style'], true); |
| | |
| | | */ |
| | | public function getImage($isType = true) |
| | | { |
| | | if (file_exists($this->getPosterPath('business')) && $isType) { |
| | | return $this->getPosterUrl('business'); |
| | | if (file_exists($this->getPosterPath($this->businessName)) && $isType) { |
| | | return $this->getPosterUrl($this->businessName); |
| | | } |
| | | // 小程序id |
| | | $appId = $this->dealer['app_id']; |
| | |
| | | $avatarUrl = $this->saveTempImage($appId, $this->dealer['user']['avatarUrl'], 'avatar'); |
| | | } |
| | | $logo = ''; |
| | | if ($this->dealer['logoImage']['file_path']) { |
| | | if (!empty($this->dealer['logoImage']['file_path'])) { |
| | | // 2. 下载logo |
| | | $logo = $this->saveTempImage($appId, $this->dealer['logoImage']['file_path'], 'logo'); |
| | | } |
| | | // 4. 拼接名片 |
| | | return $this->savePoster($backdrop, $avatarUrl, 'business', $logo); |
| | | return $this->savePoster($backdrop, $avatarUrl, $this->businessName, $logo); |
| | | } |
| | | |
| | | /** |
| | | * 名片图文件路径 |
| | | * @return string |
| | | */ |
| | | private function getPosterPath($name) |
| | | public function getPosterPath($name) |
| | | { |
| | | // 保存路径 |
| | | $tempPath = $_SERVER['DOCUMENT_ROOT']. '/temp/'.$this->template['app_id'] . '/'.$name.'/'; |
| | |
| | | $this->addImagecopy($newImage, $value); |
| | | } |
| | | } |
| | | |
| | | // 脱敏处理 |
| | | if($this->businessName=='desensitization'){ |
| | | // 保存原始数据以便后续可能需要使用 |
| | | $originalDealer = $this->dealer; |
| | | |
| | | // 手机号脱敏:保留前3位和后4位 |
| | | if(!empty($this->dealer['mobile'])){ |
| | | $this->dealer['mobile'] = $this->maskPhoneNumber($this->dealer['mobile']); |
| | | } |
| | | if(!empty($this->dealer['mobile_phone'])){ |
| | | $this->dealer['mobile_phone'] = $this->maskPhoneNumber($this->dealer['mobile_phone']); |
| | | } |
| | | |
| | | // 微信脱敏:保留前2位和后2位 |
| | | if(!empty($this->dealer['wechat'])){ |
| | | $this->dealer['wechat'] = $this->maskWechat($this->dealer['wechat']); |
| | | } |
| | | |
| | | // 邮箱脱敏:保留域名和前2位用户名 |
| | | if(!empty($this->dealer['mailbox'])){ |
| | | $this->dealer['mailbox'] = $this->maskEmail($this->dealer['mailbox']); |
| | | } |
| | | |
| | | // 电话脱敏:保留前3位和后4位 |
| | | if(!empty($this->dealer['phone'])){ |
| | | $this->dealer['phone'] = $this->maskPhoneNumber($this->dealer['phone']); |
| | | } |
| | | } |
| | | // 写入地址 |
| | | //$this->addText($newImage, 'address', '地址:', 0, false, $width); |
| | | $this->addText($newImage, 'address', '地址:', 0, false, $width); |
| | | if ($this->config['avatar']['display'] == 1) { |
| | | // 生成圆形用户头像 |
| | | $this->config['avatar']['style'] === 'circle' && $this->circular($avatarUrl, $avatarUrl); |
| | |
| | | $logoImage = $this->imagEcr($logo); |
| | | imagecopy($newImage, $logoImage, $logoX, $logoY, 0, 0, $logoWidth, $logoHeight); |
| | | } |
| | | |
| | | // 写入用户昵称 |
| | | $this->addText($newImage, 'name'); |
| | | foreach ($this->dealer['unit'] as $key => $value) { |
| | | // 写入公司 |
| | | $this->addText($newImage, 'unit', '', $key, true); |
| | | } |
| | | foreach ($this->dealer['address'] as $key => $value) { |
| | | // 写入地址 |
| | | $this->addText($newImage, 'address', '', $key, true); |
| | | if (!empty($this->dealer['duties']) && !empty($this->config['duties'])) { |
| | | // 写入职位 |
| | | $this->addText($newImage, 'duties'); |
| | | } |
| | | foreach ($this->dealer['duties'] as $key => $value) { |
| | | // 写入职务 |
| | | $this->addText($newImage, 'duties', '', $key, true); |
| | | } |
| | | // 写入职位 |
| | | //$this->addText($newImage, 'duties'); |
| | | |
| | | if (!empty($this->dealer['position']) && !empty($this->config['position'])) { |
| | | foreach ($this->dealer['position'] as $key => $value) { |
| | | // 写入公司 |
| | |
| | | } |
| | | // 写入手机号 |
| | | $this->addText($newImage, 'mobile', '手机:'); |
| | | |
| | | // 写入微信 |
| | | if (!empty($this->dealer['wechat']) && !empty($this->config['wechat'])) { |
| | | // 写入微信 |
| | | $this->addText($newImage, 'wechat', '微信:'); |
| | | } |
| | | // 写入邮箱 |
| | | if ($this->dealer['mailbox']) { |
| | | // 写入邮箱 |
| | | $this->addText($newImage, 'mailbox', '邮箱:'); |
| | |
| | | } else if ($name == 'mobile') { |
| | | list($fontSize, $fontX,$fontY) = self::SizeLeftTop($this->config[$name]['fontSize'], $this->config[$name]['left'],$this->config[$name]['top']); |
| | | $text = $text . $this->dealer['mobile']; |
| | | |
| | | if (!empty($this->dealer['mobile_phone'])) { |
| | | $text = $text . ' / ' . $this->dealer['mobile_phone']; |
| | | } |
| | | $colorResource=self::colorResource($this->config[$name]['color'],$editor); |
| | | return imagettftext($editor, $fontSize, 0, $fontX, $fontY, $colorResource, $fontPath, $text); |
| | | } /*else if ($name == 'duties') { |
| | | } else if ($name == 'duties') { |
| | | list($fontSize, $fontX,$fontY) = self::SizeLeftTop($this->config[$name][$key]['fontSize'], $this->config[$name][$key]['left'],$this->config[$name][$key]['top']); |
| | | $duties = $this->dealer['duties'][$key]; |
| | | if (!empty($this->dealer['duties'][1])) { |
| | | if (!empty($this->dealer['duties'][1])) { |
| | | $duties = $duties . ' / ' . $this->dealer['duties'][1]; |
| | | } |
| | | if (!empty($this->dealer['duties'][2])) { |
| | | $duties = $duties . ' / ' . $this->dealer['duties'][2]; |
| | | } |
| | | $colorResource=self::colorResource($this->config['duties'][$key]['color'],$editor); |
| | | $colorResource=self::colorResource($this->config['duties'][0]['color'],$editor); |
| | | return imagettftext($editor, $fontSize, 0, $fontX, $fontY, $colorResource, $fontPath, $text . $duties); |
| | | }*/ else if ($name == 'address') { |
| | | } else if ($name == 'address') { |
| | | list($fontSize, $fontX,$fontY) = self::SizeLeftTop($this->config[$name][$key]['fontSize'], $this->config[$name][$key]['left'],$this->config[$name][$key]['top']); |
| | | $title = $this->dealer['address'][$key]; |
| | | $title = $this->dealer['address'][0]; |
| | | if(!empty($this->dealer['region'])){ |
| | | $title = $this->dealer['region']['province'] . $this->dealer['region']['city']. $this->dealer['region']['region'] . $title; |
| | | } |
| | | $strlen = mb_strlen($title, 'utf-8'); |
| | | $left = $width - $this->config['address'][$key]['left'] - $fontSize; |
| | | $titleNum = bcdiv($left, $this->config['address'][$key]['fontSize']); |
| | | $the_box = $this->config['address'][$key]['fontSize'] * 3; |
| | | while ($width < ($titleNum * $this->config['address'][$key]['fontSize'] + $the_box + $fontX)) { |
| | | $left = $width - $this->config['address'][0]['left'] - $fontSize; |
| | | $titleNum = bcdiv($left, $this->config['address'][0]['fontSize']); |
| | | $the_box = $this->config['address'][0]['fontSize'] * 3; |
| | | while ($width < ($titleNum * $this->config['address'][0]['fontSize'] + $the_box + $fontX)) { |
| | | $titleNum--; |
| | | }; |
| | | if ($strlen > $titleNum && $titleNum) { |
| | | $strArr = self::mbStrSplit($title, $titleNum); |
| | | } |
| | | $colorResource=self::colorResource($this->config['address'][$key]['color'],$editor); |
| | | $colorResource=self::colorResource($this->config['address'][0]['color'],$editor); |
| | | if ($strlen > $titleNum && $titleNum) { |
| | | $y = $fontY + 10; |
| | | foreach ($strArr as $k => $v) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 手机号/座机号脱敏处理 |
| | | * @param $phone |
| | | * @return string |
| | | */ |
| | | private function maskPhoneNumber($phone){ |
| | | $len = strlen($phone); |
| | | if($len <= 7) return $phone; // 太短的号码不脱敏 |
| | | |
| | | // 检查是否是带区号的座机号(包含-或空格) |
| | | if(strpos($phone, '-') !== false || strpos($phone, ' ') !== false){ |
| | | // 座机号脱敏:保留区号和最后4位 |
| | | $parts = preg_split('/[-\s]/', $phone); |
| | | |
| | | // 确保有至少两部分(区号和号码) |
| | | if(count($parts) >= 2){ |
| | | $areaCode = $parts[0]; // 区号 |
| | | $number = end($parts); // 号码部分 |
| | | $separator = strpos($phone, '-') !== false ? '-' : ' '; // 保持原始分隔符 |
| | | |
| | | $numLen = strlen($number); |
| | | if($numLen <= 4) return $phone; // 号码太短不脱敏 |
| | | |
| | | $numPrefix = substr($number, 0, 0); // 号码部分前半段不显示 |
| | | $numSuffix = substr($number, -4); // 保留号码后4位 |
| | | $stars = str_repeat('*', $numLen - 4); |
| | | |
| | | // 重新组合:区号 + 分隔符 + 掩码 + 后4位 |
| | | return $areaCode . $separator . $stars . $numSuffix; |
| | | } |
| | | } |
| | | |
| | | // 普通手机号脱敏:保留前3位和后4位 |
| | | $prefix = substr($phone, 0, 3); |
| | | $suffix = substr($phone, -4); |
| | | $stars = str_repeat('*', $len - 7); |
| | | |
| | | return $prefix . $stars . $suffix; |
| | | } |
| | | |
| | | /** |
| | | * 微信脱敏处理 |
| | | * @param $wechat |
| | | * @return string |
| | | */ |
| | | private function maskWechat($wechat){ |
| | | $len = strlen($wechat); |
| | | if($len <= 4) return $wechat; // 太短的微信号不脱敏 |
| | | |
| | | $prefix = substr($wechat, 0, 2); |
| | | $suffix = substr($wechat, -2); |
| | | $stars = str_repeat('*', $len - 4); |
| | | |
| | | return $prefix . $stars . $suffix; |
| | | } |
| | | |
| | | /** |
| | | * 邮箱脱敏处理 |
| | | * @param $email |
| | | * @return string |
| | | */ |
| | | private function maskEmail($email){ |
| | | $parts = explode('@', $email); |
| | | if(count($parts) != 2) return $email; |
| | | |
| | | $username = $parts[0]; |
| | | $domain = $parts[1]; |
| | | |
| | | $len = strlen($username); |
| | | if($len <= 2) return $email; // 太短的用户名不脱敏 |
| | | |
| | | $prefix = substr($username, 0, 2); |
| | | $stars = str_repeat('*', $len - 2); |
| | | |
| | | return $prefix . $stars . '@' . $domain; |
| | | } |
| | | |
| | | /** |
| | | * 获取颜色 |
| | | * @param $color |
| | | * @param $editor |