|
|
@@ -3,12 +3,22 @@ import 'dart:io'; |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
import 'package:flutter_alibc/alibc_model.dart'; |
|
|
|
import 'package:flutter_alibc/flutter_alibc.dart'; |
|
|
|
import 'package:fluttertoast/fluttertoast.dart'; |
|
|
|
import 'package:zhiying_comm/models/profile/profile_model.dart'; |
|
|
|
import 'package:zhiying_comm/util/taobao/taobao_auth_alert.dart'; |
|
|
|
import 'package:zhiying_comm/zhiying_comm.dart'; |
|
|
|
|
|
|
|
class TaobaoAuth { |
|
|
|
static ProfileModel _profile; |
|
|
|
|
|
|
|
// 淘宝授权 |
|
|
|
static auth(BuildContext context) async { |
|
|
|
bool isAuth = await TaobaoAuth.isAuth(); |
|
|
|
if (isAuth) { |
|
|
|
Fluttertoast.showToast(msg: '你已经授权过了'); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
bool isConfirm = await showDialog( |
|
|
|
context: context, |
|
|
|
builder: (BuildContext context) { |
|
|
@@ -19,7 +29,6 @@ class TaobaoAuth { |
|
|
|
await NetUtil.post('/api/v1/taobao/auth', method: NetMethod.GET)); |
|
|
|
Logger.debug(data); |
|
|
|
if (data['code'] != 1) { |
|
|
|
Logger.error(data['msg'], StackTrace.current); |
|
|
|
return; |
|
|
|
} |
|
|
|
String url = data['data']['redirect_url']; |
|
|
@@ -40,7 +49,16 @@ class TaobaoAuth { |
|
|
|
} |
|
|
|
|
|
|
|
// 返回是否授权 |
|
|
|
static Future<bool> isAuth() { |
|
|
|
return Future.delayed(Duration.zero, () => false); |
|
|
|
static Future<bool> isAuth() async { |
|
|
|
if (_profile != null) { |
|
|
|
return _profile.isAuth; |
|
|
|
} |
|
|
|
Map<String, dynamic> data = Map<String, dynamic>.from( |
|
|
|
await NetUtil.post('/api/v1/user/profile', method: NetMethod.GET)); |
|
|
|
if (data['code'] == 1) { |
|
|
|
_profile = ProfileModel.fromJson(Map<String, dynamic>.from(data['data'])); |
|
|
|
return _profile.isAuth; |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |