From b5fb681ceea0c14e9efa9057ff422d5ce7a8b329 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Tue, 2 Dec 2025 15:16:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=9B=B4=E6=96=B0vip?= =?UTF-8?q?=E8=BF=87=E6=9C=9F=E6=97=B6=E9=97=B4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/data/services/pay_service.dart | 11 +++++++++ .../controllers/goods_base_controller.dart | 12 ++++++++++ .../agent_service/AgentService.kt | 12 ++++++++-- .../agent_service/AgentServicePlugin.kt | 15 +++++++++++- .../agent_service/AgentServiceImpl.swift | 8 ++++++- .../agent_service/AgentServicePlugin.swift | 9 ++++++- .../agent_service/lib/agent_service.dart | 24 +++++++++++++++++++ 7 files changed, 86 insertions(+), 5 deletions(-) diff --git a/lib/data/services/pay_service.dart b/lib/data/services/pay_service.dart index 7d1f92dcd..4417446a9 100644 --- a/lib/data/services/pay_service.dart +++ b/lib/data/services/pay_service.dart @@ -1,5 +1,6 @@ import 'dart:async'; import 'dart:convert'; +import 'package:agent_service/agent_service.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:get/get.dart'; @@ -335,6 +336,7 @@ class PayService extends GetxService { final bool ok = status == 1 || user != null; if (ok && user != null) { User.instance.updateUserInfo(user); + setVipExptime(User.instance.vipexptime); } if (!ok) { final code = (resp is Map) ? resp['code'] : null; @@ -1157,4 +1159,13 @@ class PayService extends GetxService { return null; } } + + /// 请求蓝牙权限 + void setVipExptime(int vipexptime) { + try { + AgentService.setVipExptime(vipexptime); + } catch (e) { + print('请求蓝牙权限失败: ${e.toString()}'); + } + } } diff --git a/lib/modules/goods/controllers/goods_base_controller.dart b/lib/modules/goods/controllers/goods_base_controller.dart index e36dfadbe..14a779abc 100644 --- a/lib/modules/goods/controllers/goods_base_controller.dart +++ b/lib/modules/goods/controllers/goods_base_controller.dart @@ -446,6 +446,8 @@ abstract class GoodsBaseController extends GetxController { ); if (paymentData == null) { onResult?.call(false, '创建微信订单失败'); + isPaying.value = false; + _cancelPayingTimeout(); return false; } final orderId = @@ -481,6 +483,8 @@ abstract class GoodsBaseController extends GetxController { ); if (orderInfo == null) { onResult?.call(false, '创建支付宝订单失败'); + isPaying.value = false; + _cancelPayingTimeout(); return false; } final orderId = _payService.lastOrderId; // 创建订单时已缓存 @@ -514,6 +518,8 @@ abstract class GoodsBaseController extends GetxController { ); if (orderId == null || orderId.isEmpty) { onResult?.call(false, '创建 Apple 订单失败'); + isPaying.value = false; + _cancelPayingTimeout(); return false; } // 使用商品id作为内购的 productId(与后台保持一致) @@ -568,6 +574,8 @@ abstract class GoodsBaseController extends GetxController { ); if (orderId == null || orderId.isEmpty) { onResult?.call(false, '创建 Google 订单失败'); + isPaying.value = false; + _cancelPayingTimeout(); return false; } isPaying.value = true; @@ -650,6 +658,7 @@ abstract class GoodsBaseController extends GetxController { final orderStatus = order["status"]; if (orderStatus == 1) { User.instance.updateUserInfo(user); + _payService.setVipExptime(User.instance.vipexptime); success = true; break; } @@ -685,6 +694,7 @@ abstract class GoodsBaseController extends GetxController { final orderStatus = order['status']; if (orderStatus == 1 && user != null) { User.instance.updateUserInfo(user); + _payService.setVipExptime(User.instance.vipexptime); Get.snackbar('提示', '订单已确认,额度已刷新', snackPosition: SnackPosition.BOTTOM, margin: const EdgeInsets.all(12)); @@ -808,6 +818,8 @@ abstract class GoodsBaseController extends GetxController { ); if (approvalUrl == null) { onResult?.call(false, '创建 PayPal 订单失败'); + isPaying.value = false; + _cancelPayingTimeout(); return false; } final orderId = _payService.lastOrderId; // 创建订单时已缓存 diff --git a/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt b/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt index e3dd57cee..e931fc06c 100644 --- a/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt +++ b/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentService.kt @@ -296,12 +296,13 @@ object AgentService : CoroutineScope { usertoken = config["usertoken"]?.toString() ?: usertoken callingToolText = config["callingToolText"]?.toString() ?: callingToolText insufficientIntegralText = config["insufficientIntegralText"]?.toString() ?: insufficientIntegralText - vipExptime = config["vipexptime"]?.toString()?.toIntOrNull() ?: 0; + vipExptime = config["vipexptime"]?.toString()?.toIntOrNull() ?: vipExptime; navigationMode = config["navigationMode"]?.toString() ?: navigationMode } catch (e: Exception) { - Log.e(TAG, "应用配置更新失败: ${e.message}") + Log.e(TAG, "应用配置更新失败 config: $config Exception:${e.message}") } } + /** * 释放所有资源 @@ -1374,6 +1375,7 @@ object AgentService : CoroutineScope { } } + /** * 更新TTS语言设置 * @@ -1408,6 +1410,12 @@ object AgentService : CoroutineScope { } } + + fun setvipExptime(vipexptime: Int): Boolean { + vipExptime = vipexptime + return true + } + /** * 根据ASR语言代码获取对应的TTS语音角色名称 * 与LanguageManager中的映射保持一致 diff --git a/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentServicePlugin.kt b/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentServicePlugin.kt index 3a70cd868..d53768ecd 100644 --- a/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentServicePlugin.kt +++ b/local_plugins/agent_service/android/src/main/kotlin/com/yunqiinnovation/agent_service/AgentServicePlugin.kt @@ -267,7 +267,20 @@ class AgentServicePlugin : FlutterPlugin, MethodCallHandler, EventChannel.Stream result.error("SET_LANGUAGES_ERROR", "设置支持语言失败: ${e.message}", null) } } - + "setVipExptime" -> { + try { + val vipexptime = call.argument("vipexptime") + if (vipexptime == null) { + result.error("INVALID_ARGUMENTS", "vipexptime参数不能为空", null) + return + } + val isSuccess = AgentService.setvipExptime(vipexptime) + result.success(isSuccess) + } catch (e: Exception) { + Log.e(TAG, "更新用户信息失败", e) + result.error("UPDATE_USER_INFO_ERROR", "更新用户信息失败: ${e.message}", null) + } + } "stopAiSteam" -> { try { AgentService.stopAiStream() diff --git a/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift b/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift index e12c85485..abefc56bc 100644 --- a/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift +++ b/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServiceImpl.swift @@ -1524,7 +1524,13 @@ private func jsonToString(_ json: [String: Any]) -> String? { return false } } - + /* + * 设置vip过期时间 + */ + func setVipExptime(_ vipexptime:Int) -> Bool { + self.vipexptime = vipexptime + return true + } /** * 根据ASR语言代码获取对应的TTS语音角色名称 * 与LanguageManager中的映射保持一致 diff --git a/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServicePlugin.swift b/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServicePlugin.swift index 0877ab63e..cad33bcb4 100644 --- a/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServicePlugin.swift +++ b/local_plugins/agent_service/ios/agent_service/Sources/agent_service/AgentServicePlugin.swift @@ -178,7 +178,14 @@ public class AgentServicePlugin: NSObject, FlutterPlugin { let success = impl.setSupportedLanguages(languages) result(success) - + case "setVipExptime": + guard let arguments = call.arguments as? [String: Any], + let vipexptime = arguments["vipexptime"] as? Int else { + result(FlutterError(code: "INVALID_ARGUMENTS", message: "vipexptime参数不能为空", details: nil)) + return + } + let success = impl.setVipExptime(vipexptime) + result(success) default: result(FlutterMethodNotImplemented) } diff --git a/local_plugins/agent_service/lib/agent_service.dart b/local_plugins/agent_service/lib/agent_service.dart index bf54a27b7..6d1017ae9 100644 --- a/local_plugins/agent_service/lib/agent_service.dart +++ b/local_plugins/agent_service/lib/agent_service.dart @@ -1,5 +1,6 @@ import 'dart:async'; import 'dart:convert'; +import 'dart:ffi'; import 'package:flutter/services.dart'; @@ -489,6 +490,29 @@ class AgentService { } } + /// 更新用户信息 + /// + /// 更新用户信息,包括姓名、手机号、邮箱等 + /// [config] 配置参数,应包含以下参数: + /// - azureSpeechKey: Azure语音服务密钥 + /// - azureSpeechRegion: Azure语音服务区域 + /// - openaiApiKey: OpenAI API密钥 + /// - openaiBaseUrl: (可选) OpenAI API 基础URL + /// - openaiModel: (可选) OpenAI模型名称,默认为"gpt-3.5-turbo" + /// - mcpServer: (可选) MCP服务器地址 + /// + /// 返回是否成功启动服务 + static Future setVipExptime(int vipexptime) async { + try { + final bool result = await _channel.invokeMethod('setVipExptime', { + 'vipexptime': vipexptime, + }); + return result; + } on PlatformException catch (e) { + throw AgentServiceException(e.code, e.message ?? '更新用户信息失败', e.details); + } + } + /// 释放资源 static Future dispose() async { try {