This commit is contained in:
wong
2026-04-09 12:30:38 +08:00
parent 29413f57c7
commit 3bf1b2aee9
3 changed files with 149 additions and 11 deletions

View File

@@ -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" . <<<XML
<?xml version="1.0"?>
<msg>
<appmsg appid="" sdkver="0">
<title>{$title}</title>
<des>{$des}</des>
<type>33</type>
<showtype>0</showtype>
<soundtype>0</soundtype>
<contentattr>0</contentattr>
<sourceusername>{$ghUsername}</sourceusername>
<weappinfo>
<username><![CDATA[{$ghUsername}]]></username>
<appid><![CDATA[]]></appid>
<type>2</type>
<version>50</version>
<weappiconurl><![CDATA[]]></weappiconurl>
<pagepath><![CDATA[{$pagepath}]]></pagepath>
<pkginfo>
<type>0</type>
<md5><![CDATA[]]></md5>
</pkginfo>
<wadynamicpageinfo>
<shouldUseDynamicPage>0</shouldUseDynamicPage>
<cacheKey><![CDATA[]]></cacheKey>
</wadynamicpageinfo>
<appservicetype>0</appservicetype>
</weappinfo>
</appmsg>
</msg>
XML;
$detailArray = [
'contentXml' => $contentXml,
'previewImage' => $previewImage,
'type' => 'miniprogram',
];
$detail = json_encode($detailArray, JSON_UNESCAPED_UNICODE);
break;
case 'link':