fix(genex-mobile): 升级 fluwx 3.x → 5.x,适配新版 API
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 <noreply@anthropic.com>
This commit is contained in:
parent
7aea49a0c9
commit
2e66db08ef
|
|
@ -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<WelcomePage> {
|
|||
// '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<WelcomePage> {
|
|||
// ── 微信 ─────────────────────────────────────────────────────────────────
|
||||
|
||||
Future<void> _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<WelcomePage> {
|
|||
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<void> _handleWechatAuthResp(WXAuthResp resp) async {
|
||||
Future<void> _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');
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ Future<void> 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/');
|
||||
}
|
||||
// ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue