From 1a28c9ae751c8c2cc68108a2d86ac5d6d9dfc463 Mon Sep 17 00:00:00 2001 From: wong <106998207@qq.com> Date: Wed, 29 Apr 2026 16:33:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + .../common/model/TrafficPoolSource.php | 51 ++++++++-- application/job/WorkbenchGroupPushJob.php | 48 +++++++++- composer.json | 94 ++++++++++++++----- 4 files changed, 161 insertions(+), 33 deletions(-) diff --git a/.gitignore b/.gitignore index 1047f5b..67bbdc2 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ nginx.htaccess thinkphp/ public/static/ *.log +Server.code-workspace diff --git a/application/common/model/TrafficPoolSource.php b/application/common/model/TrafficPoolSource.php index f73f219..bf34fab 100644 --- a/application/common/model/TrafficPoolSource.php +++ b/application/common/model/TrafficPoolSource.php @@ -73,6 +73,43 @@ class TrafficPoolSource extends Model return $value ? json_encode($value, JSON_UNESCAPED_UNICODE) : null; } + /** + * 兼容历史库:s2_wechat_friend 早期可能不存在 headImgUrl 列 + * @param string $wechatId + * @return string + */ + protected static function getFriendHeadImgUrl(string $wechatId): string + { + $wechatId = trim($wechatId); + if ($wechatId === '') { + return ''; + } + + static $hasHeadImgUrl = null; + if ($hasHeadImgUrl === null) { + try { + $cols = Db::query("SHOW COLUMNS FROM s2_wechat_friend LIKE 'headImgUrl'"); + $hasHeadImgUrl = !empty($cols); + } catch (\Throwable $e) { + $hasHeadImgUrl = false; + } + } + + if (!$hasHeadImgUrl) { + return ''; + } + + try { + $val = Db::table('s2_wechat_friend') + ->where('wechatId', $wechatId) + ->value('headImgUrl'); + return $val ? (string)$val : ''; + } catch (\Throwable $e) { + // 兜底:避免因字段缺失导致接口直接 1054 + return ''; + } + } + /** * 获取来源类型名称 * @return string @@ -224,11 +261,10 @@ class TrafficPoolSource extends Model // 尝试获取好友头像 if (!empty($source['sourceWechatId'])) { - $sourceData['sourceAvatar'] = Db::table('ck_traffic_pool') + $avatar = Db::table('ck_traffic_pool') ->where('wechatId', $source['sourceWechatId']) - ->value('avatar') ?: Db::table('s2_wechat_friend') - ->where('wechatId', $source['sourceWechatId']) - ->value('headImgUrl') ?: ''; + ->value('avatar'); + $sourceData['sourceAvatar'] = $avatar ?: self::getFriendHeadImgUrl((string)$source['sourceWechatId']); } } else { $sourceData['chatroomOwners'] = []; @@ -448,11 +484,10 @@ class TrafficPoolSource extends Model $sourceData['chatroomInfo'] = null; // 尝试获取好友头像 if (!empty($source['sourceWechatId'])) { - $sourceData['sourceAvatar'] = Db::table('ck_traffic_pool') + $avatar = Db::table('ck_traffic_pool') ->where('wechatId', $source['sourceWechatId']) - ->value('avatar') ?: Db::table('s2_wechat_friend') - ->where('wechatId', $source['sourceWechatId']) - ->value('headImgUrl') ?: ''; + ->value('avatar'); + $sourceData['sourceAvatar'] = $avatar ?: self::getFriendHeadImgUrl((string)$source['sourceWechatId']); } } else { $sourceData['chatroomOwners'] = []; diff --git a/application/job/WorkbenchGroupPushJob.php b/application/job/WorkbenchGroupPushJob.php index 5594e0b..4cd00c1 100644 --- a/application/job/WorkbenchGroupPushJob.php +++ b/application/job/WorkbenchGroupPushJob.php @@ -333,8 +333,9 @@ class WorkbenchGroupPushJob { $sendData = []; - // 内容处理 - if (!empty($content['content'])) { + // 内容处理(小程序素材 content 为 JSON,不能按文本推送) + $contentTypeNum = (int)($content['contentType'] ?? 0); + if (!empty($content['content']) && $contentTypeNum !== 5) { // 京东转链 if (!empty($config['promotionSiteId'])) { $WorkbenchController = new WorkbenchController(); @@ -430,6 +431,49 @@ class WorkbenchGroupPushJob ]; } break; + case 5: + // 小程序:content 为 JSON,与触客宝快捷语 / 存客宝表单一致(可含 body 内容消息) + $mini = json_decode($content['content'] ?? '', true); + if (is_array($mini) && ($mini['type'] ?? '') === 'miniprogram') { + $body = trim((string)($mini['body'] ?? $mini['contentMessage'] ?? $mini['message'] ?? '')); + if ($body !== '') { + if ($type == 'group') { + $sendData[] = [ + 'content' => $body, + 'msgType' => 1, + 'wechatAccountId' => $wechatAccountId, + 'wechatChatroomId' => $targetId, + ]; + } else { + $sendData[] = [ + 'content' => $body, + 'msgType' => 1, + ]; + } + } + $miniPayload = [ + 'type' => 'miniprogram', + 'title' => $mini['title'] ?? '', + 'des' => $mini['des'] ?? '', + 'gh' => $mini['gh'] ?? '', + 'pagepath' => $mini['pagepath'] ?? '', + 'previewImage' => $mini['previewImage'] ?? '', + ]; + if ($type == 'group') { + $sendData[] = [ + 'content' => $miniPayload, + 'msgType' => 49, + 'wechatAccountId' => $wechatAccountId, + 'wechatChatroomId' => $targetId, + ]; + } else { + $sendData[] = [ + 'content' => $miniPayload, + 'msgType' => 49, + ]; + } + } + break; } return $sendData; diff --git a/composer.json b/composer.json index 9fc48b5..ce1721e 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,6 @@ "aliyuncs/oss-sdk-php": "^2.6", "monolog/monolog": "^1.27", "guzzlehttp/guzzle": "^6.5", - "psr/http-client": "^1.0", "overtrue/wechat": "~4.6", "endroid/qr-code": "^3.9", "phpoffice/phpspreadsheet": "^1.29", @@ -48,25 +47,74 @@ "topthink/think-migration": "^2.0", "phpunit/phpunit": "^5.0|^6.0" }, - "autoload": { - "psr-4": { - "app\\": "application", - "Eison\\": "extend/Eison" - }, - "files": [ - "application/common.php" - ] - }, - "extra": { - "think-path": "thinkphp" - }, - "config": { - "preferred-install": "dist", - "allow-plugins": { - "topthink/think-installer": true, - "easywechat-composer/easywechat-composer": true - } - }, - "minimum-stability": "dev", - "prefer-stable": true -} + "autoload": { + "psr-4": { + "app\\": "application", + "Eison\\": "extend/Eison" + }, + "files": [ + "application/common.php" + ], + "homepage": "http://thinkphp.cn/", + "license": "Apache-2.0", + "authors": [ + { + "name": "liu21st", + "email": "liu21st@gmail.com" + }, + { + "name": "yunwuxin", + "email": "448901948@qq.com" + } + ], + "require": { + "php": ">=5.6.0", + "topthink/framework": "5.1.41", + "topthink/think-installer": "~1.0", + "topthink/think-captcha": "^2.0", + "topthink/think-helper": "^3.0", + "topthink/think-image": "^1.0", + "topthink/think-queue": "^2.0", + "topthink/think-worker": "^2.0", + "textalk/websocket": "^1.2", + "aliyuncs/oss-sdk-php": "^2.3", + "monolog/monolog": "^1.24", + "guzzlehttp/guzzle": "^6.3", + "overtrue/wechat": "~4.0", + "endroid/qr-code": "^3.5", + "phpoffice/phpspreadsheet": "^1.8", + "workerman/workerman": "^3.5", + "workerman/gateway-worker": "^3.0", + "hashids/hashids": "^2.0", + "khanamiryan/qrcode-detector-decoder": "^1.0", + "lizhichao/word": "^2.0", + "adbario/php-dot-notation": "^2.2" + }, + "require-dev": { + "symfony/var-dumper": "^3.4", + "topthink/think-migration": "^2.0" + }, + "autoload": { + "psr-4": { + "app\\": "application", + "Eison\\": "extend/Eison" + }, + "files": [ + "application/common.php" + ], + "classmap": [] + }, + "extra": { + "think-path": "thinkphp" + }, + "config": { + "preferred-install": "dist", + "allow-plugins": { + "topthink/think-installer": true, + "easywechat-composer/easywechat-composer": true + } + }, + "minimum-stability": "dev", + "prefer-stable": true + } +} \ No newline at end of file