@@ -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; | |||
} | |||
@@ -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" | |||
}; | |||
} | |||
@@ -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: <Widget>[ | |||
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: () { | |||
@@ -0,0 +1,15 @@ | |||
class ProfileModel { | |||
bool isAuth; // 是否淘宝授权 | |||
ProfileModel({this.isAuth}); | |||
ProfileModel.fromJson(Map<String, dynamic> json) { | |||
isAuth = json['is_taobao_auth']; | |||
} | |||
Map<String, dynamic> toJson() { | |||
final Map<String, dynamic> data = new Map<String, dynamic>(); | |||
data['is_taobao_auth'] = this.isAuth; | |||
return data; | |||
} | |||
} |
@@ -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; | |||
@@ -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; | |||
} | |||
} |