fix:商城登录互通问题

This commit is contained in:
jingyun committed 2026-09-08 13:46:45 +08:00
1 parent 7b1852d9a6
commit 1f9a8b67a2
4 files changed
+119 -9

No files matched your search

+15 -5
View File
@@ -1,3 +1,5 @@
import 'dart:typed_data';
import 'package:dio/dio.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
@@ -25,17 +27,25 @@ class MallAuthApi {
Future<AppMallAuthToken> issueAppMallAuthToken() async {
final response = await _dio.post<List<int>>(
'/api/v1/auth/mall/app-token',
data: const <int>[],
// Dio serializes a List<int> as the UTF-8 text "[]". This endpoint
// expects an empty protobuf message, whose wire representation is zero
// bytes; Uint8List keeps the request body binary and untransformed.
data: Uint8List(0),
options: protobufOptions(),
);
final reply = ProtoMessage(response.data ?? const <int>[]);
final token = reply.string(1).trim();
if (token.isEmpty) throw const FormatException('Missing mall auth token');
final expiresIn = reply.integer(2);
final sourceApp = reply.string(3).trim();
final scene = reply.string(4).trim();
if (token.isEmpty || expiresIn <= 0 || sourceApp.isEmpty || scene.isEmpty) {
throw const FormatException('Incomplete mall auth token response');
}
return AppMallAuthToken(
authToken: token,
expiresIn: reply.integer(2),
sourceApp: reply.string(3),
scene: reply.string(4),
expiresIn: expiresIn,
sourceApp: sourceApp,
scene: scene,
);
}
}