diff --git a/example/android/app/src/main/java/cn/zhios/zhiying_comm_example/MainActivity.java b/example/android/app/src/main/java/cn/zhios/zhiying_comm_example/MainActivity.java index 488f076..317b067 100644 --- a/example/android/app/src/main/java/cn/zhios/zhiying_comm_example/MainActivity.java +++ b/example/android/app/src/main/java/cn/zhios/zhiying_comm_example/MainActivity.java @@ -1,16 +1,13 @@ package cn.zhios.zhiying_comm_example; -import cn.zhios.zhiying_comm.ZhiyingCommPlugin; -import cn.zhios.zhiying_comm.ZhiyingFlutterCommHandler; -import cn.zhios.zhiying_comm.ZhiyingFlutterCommNativable; -import cn.zhios.zhiying_comm.ZhiyingFlutterCommNative; -import cn.zhios.zhiying_comm.ZhiyingFlutterCommNativeResult; +import androidx.annotation.NonNull; import java.util.HashMap; import java.util.Map; -import androidx.annotation.NonNull; - +import cn.zhios.zhiying_comm.ZhiyingFlutterCommHandler; +import cn.zhios.zhiying_comm.ZhiyingFlutterCommNativable; +import cn.zhios.zhiying_comm.ZhiyingFlutterCommNative; import io.flutter.embedding.android.FlutterActivity; import io.flutter.embedding.engine.FlutterEngine; import io.flutter.plugins.GeneratedPluginRegistrant; @@ -38,10 +35,10 @@ public class MainActivity extends FlutterActivity implements ZhiyingFlutterCommN @Override public Map getSetting() { Map map = new HashMap(); - map.put("domain", "http://192.168.0.113:5000"); //"http://120.76.175.204:8989"); + map.put("domain", "http://inapi.izhyin.cn"); //"http://120.76.175.204:8989"); map.put("master_id", "123456"); map.put("secret_key", "123456"); - map.put("token", "123465"); + map.put("token", "cc455e0c0b6a75ff09aeb966c211fb967d69b63d"); return map; } diff --git a/example/ios/Runner/AppDelegate.m b/example/ios/Runner/AppDelegate.m index f35c199..8100581 100644 --- a/example/ios/Runner/AppDelegate.m +++ b/example/ios/Runner/AppDelegate.m @@ -36,7 +36,8 @@ - (NSDictionary*)getSetting { return @{ // @"domain": @"http://120.76.175.204:8989" - @"domain": @"http://192.168.0.113:5000" + @"domain": @"http://inapi.izhyin.cn", + @"token": @"cc455e0c0b6a75ff09aeb966c211fb967d69b63d" }; } diff --git a/example/lib/main.dart b/example/lib/main.dart index c9d2bcf..a0df0ec 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -4,6 +4,7 @@ import 'package:flutter_alibc/flutter_alibc.dart'; import 'package:jdsdk/jdsdk.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:zhiying_comm/register.dart'; +import 'package:zhiying_comm/util/shared_prefe_util.dart'; import 'package:zhiying_comm/zhiying_comm.dart'; import 'taobao_image_viewer.dart'; @@ -60,28 +61,20 @@ class HomePage extends StatelessWidget { children: [ RaisedButton( onPressed: () { - Navigator.push(context, MaterialPageRoute(builder: (_) { - // return DeviceInfoPage(); - })); + // d75d2fc6592f4526e297643446416581bd89e837 + // cc455e0c0b6a75ff09aeb966c211fb967d69b63d + SharedPreferencesUtil.setStringValue( + GlobalConfig.SHARED_KEY_TOKEN, + 'd75d2fc6592f4526e297643446416581bd89e837'); }, - child: Text('设备信息'), + child: Text('登录'), ), RaisedButton( onPressed: () { - Navigator.push(context, MaterialPageRoute(builder: (_) { - // return PackageInfoPage(); - })); - }, - child: Text('应用信息'), - ), - RaisedButton( - onPressed: () { - NetUtil.post('/siteapi/v1/ucenter/login/', params: { - 'username': 'xiangguohui', - 'password': 'fnuo123com' - }); + SharedPreferencesUtil.setStringValue( + GlobalConfig.SHARED_KEY_TOKEN, ''); }, - child: Text('登录请求'), + child: Text('退出登录'), ), RaisedButton( onPressed: () { diff --git a/lib/models/profile/profile_model.dart b/lib/models/profile/profile_model.dart new file mode 100644 index 0000000..9a3ab31 --- /dev/null +++ b/lib/models/profile/profile_model.dart @@ -0,0 +1,15 @@ +class ProfileModel { + bool isAuth; // 是否淘宝授权 + + ProfileModel({this.isAuth}); + + ProfileModel.fromJson(Map json) { + isAuth = json['is_taobao_auth']; + } + + Map toJson() { + final Map data = new Map(); + data['is_taobao_auth'] = this.isAuth; + return data; + } +} diff --git a/lib/util/extension/color.dart b/lib/util/extension/color.dart index 342d612..e79d9bf 100644 --- a/lib/util/extension/color.dart +++ b/lib/util/extension/color.dart @@ -16,12 +16,15 @@ import 'package:zhiying_comm/util/log/let_log.dart'; extension HexColor on Color { /// String is in the format "aabbcc" or "ffaabbcc" with an optional leading "#". static Color fromHex(String hexString) { - try{ + if (hexString == null || hexString == '') { + return Colors.transparent; + } + try { final buffer = StringBuffer(); if (hexString.length == 6 || hexString.length == 7) buffer.write('ff'); buffer.write(hexString.replaceFirst('#', '')); return Color(int.tryParse(buffer.toString(), radix: 16)); - }catch(e){ + } catch (e) { Logger.log(e); } return Colors.white; diff --git a/lib/util/taobao/taobao_auth.dart b/lib/util/taobao/taobao_auth.dart index f4ffc9a..429f515 100644 --- a/lib/util/taobao/taobao_auth.dart +++ b/lib/util/taobao/taobao_auth.dart @@ -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 isAuth() { - return Future.delayed(Duration.zero, () => false); + static Future isAuth() async { + if (_profile != null) { + return _profile.isAuth; + } + Map data = Map.from( + await NetUtil.post('/api/v1/user/profile', method: NetMethod.GET)); + if (data['code'] == 1) { + _profile = ProfileModel.fromJson(Map.from(data['data'])); + return _profile.isAuth; + } + return false; } }