From 1ecfacce49f10d04dae1ba8fd256febbde315fdb Mon Sep 17 00:00:00 2001
From: wong <106998207@qq.com>
Date: Fri, 3 Apr 2026 16:53:50 +0800
Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E9=80=81=E5=B0=8F=E7=A8=8B=E5=BA=8F?=
=?UTF-8?q?=E6=89=93=E9=80=9A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Server/application/job/SyncContentJob.php | 63 +++++++++++++++
.../Adapters/ChuKeBao/Adapter.php | 76 ++++++++++++++++++-
.../src/store/module/websocket/msgManage.ts | 20 +++--
3 files changed, 150 insertions(+), 9 deletions(-)
diff --git a/Server/application/job/SyncContentJob.php b/Server/application/job/SyncContentJob.php
index 522368e6c..ec70b5220 100644
--- a/Server/application/job/SyncContentJob.php
+++ b/Server/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/Server/extend/WeChatDeviceApi/Adapters/ChuKeBao/Adapter.php b/Server/extend/WeChatDeviceApi/Adapters/ChuKeBao/Adapter.php
index a0b85f264..61f46bac5 100644
--- a/Server/extend/WeChatDeviceApi/Adapters/ChuKeBao/Adapter.php
+++ b/Server/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':
diff --git a/Touchkebao/src/store/module/websocket/msgManage.ts b/Touchkebao/src/store/module/websocket/msgManage.ts
index 9235c73a0..2ba36b3a1 100644
--- a/Touchkebao/src/store/module/websocket/msgManage.ts
+++ b/Touchkebao/src/store/module/websocket/msgManage.ts
@@ -71,6 +71,16 @@ const messageHandlers: Record = {
//异步传新消息给数据库
goAsyncServiceData(message);
+
+ // 立即更新本地消息状态,不依赖 API 轮询结果
+ if (msg) {
+ console.log("CmdSendMessageResp 发送消息响应, 更新sendStatus", msg.id);
+ updateMessage(msg.id, {
+ sendStatus: 0,
+ id: message.friendMessage?.id || message.chatroomMessage?.id,
+ });
+ }
+
asyncMessageStatus({
messageId: message.friendMessage?.id || message.chatroomMessage?.id,
wechatFriendId: message.friendMessage?.wechatFriendId,
@@ -78,14 +88,8 @@ const messageHandlers: Record = {
wechatAccountId:
message.friendMessage?.wechatAccountId ||
message.chatroomMessage?.wechatAccountId,
- }).then(res => {
- if (msg) {
- console.log("CmdSendMessageResp 发送消息响应", res);
- updateMessage(message.seq, {
- sendStatus: 0,
- id: message.friendMessage?.id || message.chatroomMessage?.id,
- });
- }
+ }).catch(err => {
+ console.error("asyncMessageStatus 查询消息状态失败:", err);
});
},
CmdSendMessageResult: message => {