From 2e66db08ef1b365aee26ef99a2980c100f0ea0b5 Mon Sep 17 00:00:00 2001 From: hailin Date: Wed, 4 Mar 2026 08:42:56 -0800 Subject: [PATCH] =?UTF-8?q?fix(genex-mobile):=20=E5=8D=87=E7=BA=A7=20fluwx?= =?UTF-8?q?=203.x=20=E2=86=92=205.x=EF=BC=8C=E9=80=82=E9=85=8D=E6=96=B0?= =?UTF-8?q?=E7=89=88=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fluwx 3.x 不含 Android namespace,导致新版 AGP 构建失败。 升级至 5.x 并迁移 API: - registerWxApi → Fluwx().registerApi() - weChatResponseEventHandler → fluwx.addSubscriber() - sendWeChatAuth → fluwx.authBy(NormalAuth) - isWeChatInstalled → fluwx.isWeChatInstalled - WXAuthResp → WeChatAuthResponse Co-Authored-By: Claude Sonnet 4.6 --- .../auth/presentation/pages/welcome_page.dart | 21 +++++++++++-------- frontend/genex-mobile/lib/main.dart | 2 +- frontend/genex-mobile/pubspec.yaml | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/frontend/genex-mobile/lib/features/auth/presentation/pages/welcome_page.dart b/frontend/genex-mobile/lib/features/auth/presentation/pages/welcome_page.dart index 0d9d9bf..5d1e6e6 100644 --- a/frontend/genex-mobile/lib/features/auth/presentation/pages/welcome_page.dart +++ b/frontend/genex-mobile/lib/features/auth/presentation/pages/welcome_page.dart @@ -28,7 +28,7 @@ import '../../../../core/services/auth_service.dart'; /// flutter build apk --dart-define=WECHAT_APP_ID=wx0000000000000000 /// /// ── 登录流程(各平台)──────────────────────────────────── -/// 微信: fluwx.sendWeChatAuth → WXAuthResp(code) → POST /auth/wechat +/// 微信: fluwx.authBy(NormalAuth) → WeChatAuthResponse(code) → POST /auth/wechat /// 支付宝: tobias.aliPayAuth → Map(result 含 auth_code) → POST /auth/alipay /// Google: google_sign_in.signIn → GoogleSignInAuthentication.idToken → POST /auth/google /// Apple: sign_in_with_apple.getAppleIDCredential → identityToken → POST /auth/apple @@ -50,13 +50,16 @@ class _WelcomePageState extends State { // 'profile': 获取用户显示名和头像 URL final _googleSignIn = GoogleSignIn(scopes: ['email', 'profile']); + // fluwx 5.x 使用实例方式调用,registerApi 在 main.dart 中已完成 + final _fluwx = Fluwx(); + @override void initState() { super.initState(); // 监听微信授权回调(用户授权后,微信 App 返回 code) - weChatResponseEventHandler.distinct().listen((res) { - if (res is WXAuthResp && mounted) { - _handleWechatAuthResp(res); + _fluwx.addSubscriber((response) { + if (response is WeChatAuthResponse && mounted) { + _handleWechatAuthResp(response); } }); } @@ -64,7 +67,7 @@ class _WelcomePageState extends State { // ── 微信 ───────────────────────────────────────────────────────────────── Future _onWechatTap() async { - final installed = await isWeChatInstalled; + final installed = await _fluwx.isWeChatInstalled; if (!installed) { if (mounted) { ScaffoldMessenger.of(context).showSnackBar( @@ -74,13 +77,13 @@ class _WelcomePageState extends State { return; } setState(() => _wechatLoading = true); - await sendWeChatAuth(scope: 'snsapi_userinfo', state: 'genex_login'); - // 授权结果通过 weChatResponseEventHandler 异步回调 + await _fluwx.authBy(which: NormalAuth(scope: 'snsapi_userinfo', state: 'genex_login')); + // 授权结果通过 addSubscriber 异步回调 } - Future _handleWechatAuthResp(WXAuthResp resp) async { + Future _handleWechatAuthResp(WeChatAuthResponse resp) async { setState(() => _wechatLoading = false); - if (resp.errCode != 0 || resp.code == null) return; + if ((resp.errCode ?? -1) != 0 || resp.code == null) return; try { await AuthService.instance.loginByWechat(code: resp.code!); if (mounted) Navigator.pushReplacementNamed(context, '/main'); diff --git a/frontend/genex-mobile/lib/main.dart b/frontend/genex-mobile/lib/main.dart index 0cb728f..917b429 100644 --- a/frontend/genex-mobile/lib/main.dart +++ b/frontend/genex-mobile/lib/main.dart @@ -56,7 +56,7 @@ Future main() async { // 详见: https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Universal_Links/Universal_Links.html const wechatAppId = String.fromEnvironment('WECHAT_APP_ID', defaultValue: ''); if (wechatAppId.isNotEmpty) { - await registerWxApi(appId: wechatAppId, universalLink: 'https://www.gogenex.com/wechat/'); + await Fluwx().registerApi(appId: wechatAppId, universalLink: 'https://www.gogenex.com/wechat/'); } // ───────────────────────────────────────────────────────────────────── diff --git a/frontend/genex-mobile/pubspec.yaml b/frontend/genex-mobile/pubspec.yaml index 1c034d5..a6234aa 100644 --- a/frontend/genex-mobile/pubspec.yaml +++ b/frontend/genex-mobile/pubspec.yaml @@ -26,7 +26,7 @@ dependencies: qr_flutter: ^4.1.0 share_plus: ^10.0.2 flutter_secure_storage: ^9.2.2 - fluwx: ^3.10.0 + fluwx: ^5.0.0 tobias: ^3.0.0 google_sign_in: ^6.2.1 sign_in_with_apple: ^6.1.0