基础库
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 

64 行
2.1 KiB

  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. }