diff --git a/application/job/SyncContentJob.php b/application/job/SyncContentJob.php index 522368e..ec70b52 100644 --- a/application/job/SyncContentJob.php +++ b/application/job/SyncContentJob.php @@ -5,12 +5,75 @@ use app\chukebao\model\Reply; use app\chukebao\model\ReplyGroup; use think\Db; use think\queue\Job; +use app\api\controller\WebSocketController; +use think\facade\Env; class SyncContentJob { public function fire(Job $job, $data) { + $toAccountId = ''; + $username = Env::get('api.username', ''); + $password = Env::get('api.password', ''); + if (!empty($username) || !empty($password)) { + $toAccountId = Db::name('users')->where('account', $username)->value('s2_accountId'); + } + + // 建立WebSocket + $wsController = new WebSocketController(['userName' => $username, 'password' => $password, 'accountId' => $toAccountId]); + + + + // 为了便于改写 appattach,这里用 heredoc 先生成 contentXml,再 json_encode 成 msgType=49 的 content + $contentXml = <<<'XML' +wxid_480es52qsj2812: + + + + 性格测试 - 快来测测你的MBTI性格类型 + 性格测试 - 快来测测你的MBTI性格类型 + 33 + 0 + 0 + 0 + gh_5c672bbbc96f@app + + + + 2 + 50 + + + + 0 + + + + 0 + + + 0 + + + +XML; + + $contentPayload = [ + 'contentXml' => $contentXml, + 'previewImage' => 'https://ac-weremote-s2.oss-cn-shenzhen.aliyuncs.com/weremote/chat-logs/5E2C38F5A275450D935F3ECEC076124E/57fbafda482b09e1ac93f39fe4f34d47/3/192c0acf93b4b106e7d2eafdd278b0cc14e6693b', + 'type' => 'miniprogram', + ]; + + $ddd = $wsController->sendPersonal([ + 'wechatFriendId' => 17453058, + 'wechatAccountId' => 300745, + 'msgType' => 49, + 'content' => json_encode($contentPayload, JSON_UNESCAPED_UNICODE), + ]); + +exit_data($ddd); + $ddd= Db::table('s2_wechat_friend')->where('ownerWechatId','wxid_h7nsh7vxseyn29')->select(); foreach ($ddd as $v) { $d = Db::table('ck_task_customer')->where('task_id','167')->where('phone',$v['wechatId'])->find(); diff --git a/config/task_scheduler.php b/config/task_scheduler.php index e95f93e..1f0629c 100644 --- a/config/task_scheduler.php +++ b/config/task_scheduler.php @@ -81,6 +81,17 @@ return [ // 中频任务(每 2-5 分钟) // =========================== + // 内容库同步 + 'content_collect' => [ + 'name' => '同步内容库', + 'command' => 'content:collect', + 'schedule' => '*/5 * * * *', // 每5分钟 + 'options' => [], + 'enabled' => true, + 'max_concurrent' => 1, + 'log_file' => 'content_collect.log', + ], + // 同步微信设备列表(未删除设备),用于设备管理与监控 'device_active' => [ 'name' => '同步微信设备列表(未删除)', @@ -354,16 +365,6 @@ return [ 'log_file' => 'crontab_department.log', ], - // 同步内容库,将外部内容同步到系统内容库 - 'content_sync' => [ - 'name' => '同步内容库', - 'command' => 'content:sync', - 'schedule' => '0 2 * * *', // 每天2点 - 'options' => [], - 'enabled' => true, - 'max_concurrent' => 1, - 'log_file' => 'crontab_content_sync.log', - ], // 朋友圈采集任务,采集好友朋友圈内容 'moments_collect' => [ diff --git a/extend/WeChatDeviceApi/Adapters/ChuKeBao/Adapter.php b/extend/WeChatDeviceApi/Adapters/ChuKeBao/Adapter.php index a0b85f2..61f46ba 100644 --- a/extend/WeChatDeviceApi/Adapters/ChuKeBao/Adapter.php +++ b/extend/WeChatDeviceApi/Adapters/ChuKeBao/Adapter.php @@ -592,6 +592,14 @@ class Adapter implements WeChatServiceInterface // 建立WebSocket $wsController = new WebSocketController(['userName' => $username, 'password' => $password, 'accountId' => $toAccountId]); + // 获取发送方 wechatId(例如 wxid_xxx),用于拼接 miniprogram 的 contentXml + $senderWxid = ''; + if (!empty($wechatAccountId)) { + $senderWxid = Db::table('s2_wechat_account') + ->where('id', $wechatAccountId) + ->value('wechatId') ?? ''; + } + $gap = 0; foreach ($msgConf as $messages) { @@ -626,7 +634,73 @@ class Adapter implements WeChatServiceInterface case 'miniprogram': $msgType = 49; - $detail = ''; + $title = $content['title'] ?? ''; + $des = $content['des'] ?? ($content['description'] ?? ''); + $gh = $content['gh'] ?? ($content['miniProgramId'] ?? ($content['nativeId'] ?? '')); + $pagepath = $content['pagepath'] ?? ($content['pagePath'] ?? ''); + $previewImage = $content['previewImage'] ?? ($content['cover'] ?? ($content['thumbPath'] ?? '')); + + $senderWxidLocal = $content['wxid'] ?? ($content['senderWxid'] ?? $senderWxid); + + // 兼容:如果外部已经直接传了 contentXml,就不再按字段拼 xml + if (!empty($content['contentXml']) && !empty($previewImage) && !empty($senderWxidLocal)) { + $detailArray = [ + 'contentXml' => $content['contentXml'], + 'previewImage' => $previewImage, + 'type' => 'miniprogram', + ]; + $detail = json_encode($detailArray, JSON_UNESCAPED_UNICODE); + break; + } + + if (empty($senderWxidLocal) || empty($title) || empty($des) || empty($gh) || empty($pagepath) || empty($previewImage)) { + $detail = ''; + break; + } + + $ghUsername = (string)$gh; + if (strpos($ghUsername, '@app') === false) { + $ghUsername .= '@app'; + } + + $contentXml = $senderWxidLocal . ":\n" . << + + + {$title} + {$des} + 33 + 0 + 0 + 0 + {$ghUsername} + + + + 2 + 50 + + + + 0 + + + + 0 + + + 0 + + + +XML; + + $detailArray = [ + 'contentXml' => $contentXml, + 'previewImage' => $previewImage, + 'type' => 'miniprogram', + ]; + $detail = json_encode($detailArray, JSON_UNESCAPED_UNICODE); break; case 'link':