|
|
@@ -12,6 +12,8 @@ interface FAQItem {
|
|
|
answer: string;
|
|
|
}
|
|
|
|
|
|
+import { api_cozeAgent } from '../../api/login';
|
|
|
+
|
|
|
const FAQ_LIST: FAQItem[] = [
|
|
|
{ question: '产品价格是多少?', answer: '我们的产品价格根据不同的套餐有所不同。基础版¥99/月,专业版¥199/月,企业版¥499/月。您可以根据自己的需求选择合适的套餐。' },
|
|
|
{ question: '如何购买课程?', answer: '您可以通过以下步骤购买课程:1. 在首页浏览课程列表;2. 点击心仪的课程进入详情页;3. 点击"立即购买"按钮;4. 选择支付方式完成支付。' },
|
|
|
@@ -190,38 +192,49 @@ Page({
|
|
|
},
|
|
|
|
|
|
// 发送消息到服务器
|
|
|
- sendMessageToServer(content: string, contentType: 'text' | 'image') {
|
|
|
+ async sendMessageToServer(content: string, contentType: 'text' | 'image') {
|
|
|
this.setData({ isLoading: true });
|
|
|
|
|
|
- // 模拟API响应
|
|
|
- setTimeout(() => {
|
|
|
- let reply = '';
|
|
|
+ // 获取用户ID(优先使用openid,其次使用token中的用户ID)
|
|
|
+ const userInfo = wx.getStorageSync('userInfo') || {};
|
|
|
+ const userId = userInfo.openId || userInfo.userId || wx.getStorageSync('openid') || '';
|
|
|
+
|
|
|
+ // 构建消息内容(图片发送固定提示语)
|
|
|
+ const messageContent = contentType === 'image' ? '我发送了一张图片' : content;
|
|
|
|
|
|
- if (contentType === 'image') {
|
|
|
- reply = '我已收到您的图片,请问有什么可以帮助您的吗?';
|
|
|
+ try {
|
|
|
+ // 调用客服消息接口
|
|
|
+ const res: any = await api_cozeAgent({
|
|
|
+ message: messageContent,
|
|
|
+ userId: userId
|
|
|
+ });
|
|
|
+
|
|
|
+ if (res.code === 200 && res.data) {
|
|
|
+ // 使用接口返回的回复内容
|
|
|
+ const reply = res.data.reply || res.data.content || res.data.message || '您好,我已经收到您的问题。';
|
|
|
+ this.addReplyMessage(reply);
|
|
|
} else {
|
|
|
- // 简单的关键词匹配回复
|
|
|
- const keyword = content.toLowerCase();
|
|
|
- if (keyword.includes('价格') || keyword.includes('多少钱')) {
|
|
|
- reply = '我们的产品价格根据不同的套餐有所不同。基础版¥99/月,专业版¥199/月,企业版¥499/月。您可以根据自己的需求选择合适的套餐。';
|
|
|
- } else if (keyword.includes('购买') || keyword.includes('怎么买')) {
|
|
|
- reply = '您可以通过以下步骤购买课程:1. 在首页浏览课程列表;2. 点击心仪的课程进入详情页;3. 点击"立即购买"按钮;4. 选择支付方式完成支付。';
|
|
|
- } else if (keyword.includes('设备') || keyword.includes('支持')) {
|
|
|
- reply = '我们的产品支持多种设备:iOS设备(iPhone、iPad)、Android设备(手机、平板)、Windows电脑、Mac电脑,以及主流的智能电视。';
|
|
|
- } else if (keyword.includes('试用') || keyword.includes('体验')) {
|
|
|
- reply = '有的!我们为所有新用户提供7天免费试用期。试用期间您可以体验全部专业版功能,无需绑定支付方式。试用期结束后,您可以选择是否订阅。';
|
|
|
- } else if (keyword.includes('发票')) {
|
|
|
- reply = '我们可以为您开具增值税普通发票或专用发票。请在购买后30天内,在"我的订单"页面点击"申请开票",填写相关信息后,我们会在5个工作日内将发票发送至您的邮箱。';
|
|
|
- } else if (keyword.includes('售后') || keyword.includes('退款')) {
|
|
|
- reply = '我们提供完善的售后服务:1. 7天无理由退款;2. 产品问题30天内免费换新;3. 终身技术支持;4. 专属客服一对一服务。如有任何问题,请随时联系我们。';
|
|
|
- } else {
|
|
|
- reply = '您好,我已经收到您的问题。我们的客服人员会尽快为您解答。如果您有其他问题,也可以继续提问。';
|
|
|
- }
|
|
|
+ // 接口返回错误,使用默认回复
|
|
|
+ this.handleDefaultReply(contentType);
|
|
|
}
|
|
|
-
|
|
|
- this.addReplyMessage(reply);
|
|
|
+ } catch (err) {
|
|
|
+ console.error('客服接口调用失败:', err);
|
|
|
+ // 接口调用失败,使用默认回复
|
|
|
+ this.handleDefaultReply(contentType);
|
|
|
+ } finally {
|
|
|
this.setData({ isLoading: false });
|
|
|
- }, 1500);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ // 处理默认回复(当接口调用失败时使用)
|
|
|
+ handleDefaultReply(contentType: 'text' | 'image') {
|
|
|
+ let reply = '';
|
|
|
+ if (contentType === 'image') {
|
|
|
+ reply = '我已收到您的图片,请问有什么可以帮助您的吗?';
|
|
|
+ } else {
|
|
|
+ reply = '您好,我已经收到您的问题。我们的客服人员会尽快为您解答。如果您有其他问题,也可以继续提问。';
|
|
|
+ }
|
|
|
+ this.addReplyMessage(reply);
|
|
|
},
|
|
|
|
|
|
// 添加AI回复消息
|