基础库
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

taobao_auth.dart 2.1 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import 'dart:io';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_alibc/alibc_model.dart';
  4. import 'package:flutter_alibc/flutter_alibc.dart';
  5. import 'package:fluttertoast/fluttertoast.dart';
  6. import 'package:zhiying_comm/models/profile/profile_model.dart';
  7. import 'package:zhiying_comm/util/taobao/taobao_auth_alert.dart';
  8. import 'package:zhiying_comm/zhiying_comm.dart';
  9. class TaobaoAuth {
  10. static ProfileModel _profile;
  11. // 淘宝授权
  12. static auth(BuildContext context) async {
  13. bool isAuth = await TaobaoAuth.isAuth();
  14. if (isAuth) {
  15. Fluttertoast.showToast(msg: '你已经授权过了');
  16. return;
  17. }
  18. bool isConfirm = await showDialog(
  19. context: context,
  20. builder: (BuildContext context) {
  21. return TaobaoAuthAlert();
  22. });
  23. if (isConfirm != null && isConfirm == true) {
  24. Map<String, dynamic> data = Map<String, dynamic>.from(
  25. await NetUtil.post('/api/v1/taobao/auth', method: NetMethod.GET));
  26. Logger.debug(data);
  27. if (data['code'] != 1) {
  28. return;
  29. }
  30. String url = data['data']['redirect_url'];
  31. print("授权链接" + url);
  32. if (Platform.isAndroid) {
  33. TradeResult result = await FlutterAlibc.openByUrl(
  34. url: url, backUrl: "alisdk://", isAuth: true);
  35. // TradeResult result = await FlutterAlibc.openByUrl(url: '');
  36. Logger.debug('${result.errorCode} ${result.errorMessage} ');
  37. } else if (Platform.isIOS) {
  38. TradeResult result = await FlutterAlibc.openByUrl(url: url);
  39. // TradeResult result = await FlutterAlibc.openByUrl(url: '');
  40. Logger.debug('${result.errorCode} ${result.errorMessage} ');
  41. }
  42. }
  43. }
  44. // 返回是否授权
  45. static Future<bool> isAuth() async {
  46. if (_profile != null) {
  47. return _profile.isAuth;
  48. }
  49. Map<String, dynamic> data = Map<String, dynamic>.from(
  50. await NetUtil.post('/api/v1/user/profile', method: NetMethod.GET));
  51. if (data['code'] == 1) {
  52. _profile = ProfileModel.fromJson(Map<String, dynamic>.from(data['data']));
  53. return _profile.isAuth;
  54. }
  55. return false;
  56. }
  57. }