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