From 50908a274bb88902ae612431365672f3ea212972 Mon Sep 17 00:00:00 2001 From: ZF sun <34314687@qq.com> Date: Wed, 6 May 2026 11:13:08 +0800 Subject: [PATCH] =?UTF-8?q?refactor(ai-service):=20=E4=BD=BF=E7=94=A8getUn?= =?UTF-8?q?iacid=E6=96=B9=E6=B3=95=E7=BB=9F=E4=B8=80=E8=8E=B7=E5=8F=96unia?= =?UTF-8?q?cid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/js/ai-service.js | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/common/js/ai-service.js b/common/js/ai-service.js index 41b442f..b2d8bbe 100644 --- a/common/js/ai-service.js +++ b/common/js/ai-service.js @@ -27,6 +27,14 @@ try { } export default { + /** + * 获取uniacid + * @returns {number} uniacid + */ + getUniacid() { + return uni.getStorageSync('uniacid') || Config.uniacid; // 从缓存中获取uniacid,或使用默认uniacid + }, + /** * 发送普通消息(blocking 模式) */ @@ -35,7 +43,7 @@ export default { // 调试:打印关键状态 console.log('[AI Service] sendMessage 开始执行'); console.log('[AI Service] store.state.memberInfo:', store.state.memberInfo); - console.log('[AI Service] store.state.uniacid:', store.state.uniacid); + console.log('[AI Service] uniacid:', this.getUniacid()); console.log('[AI Service] currentConversationId:', this.getConversationId()); const aiConfig = store.getters.globalAIKefuConfig; @@ -79,7 +87,7 @@ export default { // 打印更多信息帮助调试 console.error('[AI Service] store 状态:', { memberInfo: store.state.memberInfo, - uniacid: store.state.uniacid, + uniacid: this.getUniacid(), token: store.state.token }); throw new Error('AI服务暂时不可用,请稍后重试'); @@ -110,7 +118,7 @@ export default { socketTask.send({ data: JSON.stringify({ action: 'auth', - uniacid: store.state.uniacid || '1', + uniacid: this.getUniacid(), token: store.state.token || 'test_token', user_id: store.state.memberInfo?.id || 'anonymous' }) @@ -128,7 +136,7 @@ export default { socketTask.send({ data: JSON.stringify({ action: 'chat', - uniacid: store.state.uniacid || '1', + uniacid: this.getUniacid(), query: message, user_id: store.state.memberInfo?.id || 'anonymous', conversation_id: this.getConversationId() || '', @@ -209,7 +217,8 @@ export default { 'Accept': 'text/event-stream', }, body: JSON.stringify({ - uniacid: store.state.uniacid || '1', + uniacid: this.getUniacid(), + token: store.state.token || 'test_token', inputs: {}, query: message, response_mode: 'streaming', @@ -352,7 +361,8 @@ export default { const params = { url: '/api/kefu/createConversation', data: { - uniacid: store.state.uniacid, + uniacid: this.getUniacid(), + token: store.state.token || 'test_token', user_id: store.state.memberInfo?.id || 'anonymous', member_id: store.state.memberInfo?.id || '', ...getDomainParams() @@ -422,7 +432,7 @@ export default { throw new Error('会话ID(conversation_id)是必填参数'); } const requestData = { - uniacid: params.uniacid || store.state.uniacid || '1', + uniacid: params.uniacid || this.getUniacid(), conversation_id: params.conversation_id, user_id: params.user_id || store.state.memberInfo?.id || 'anonymous', limit: params.limit || 20, @@ -469,8 +479,8 @@ export default { window.currentEventSource.close(); } const paramsObj = { - uniacid: store.state.uniacid || '1', - user_id: store.state.memberInfo?.id || '123456', + uniacid: this.getUniacid(), + user_id: store.state.memberInfo?.id, query: message, conversation_id: conversationId || '', stream: 'true',