ソースを参照

更新app初始化参数

tags/0.0.2+8
杨华轩 4年前
コミット
4b98e83795
2個のファイルの変更158行の追加13行の削除
  1. +136
    -0
      lib/models/app_config_model.dart
  2. +22
    -13
      lib/register.dart

+ 136
- 0
lib/models/app_config_model.dart ファイルの表示

@@ -0,0 +1,136 @@
import 'package:zhiying_comm/zhiying_comm.dart';

// 应用配置信息

class AppConfigModel {
// 应用配置的key
AppConfigKeyModel keys;
// 引导页
AppConfigGuideModel guideImage;

static AppConfigModel _config;

AppConfigModel({this.keys, this.guideImage});
static AppConfigModel getConfig() => _config;

static Future<AppConfigModel> init() async {
Map result =
await NetUtil.post('/api/v1/app/guide', method: NetMethod.GET);
try {
var data = result['data'];
_config = AppConfigModel.fromJson(Map<String, dynamic>.from(data));
Logger.debug('基础设置初始化');
return _config;
} catch (err) {
Logger.error(err);
}
return null;
}

AppConfigModel.fromJson(Map<String, dynamic> json) {
keys = json['keys'] != null ? new AppConfigKeyModel.fromJson(json['keys']) : null;
guideImage = json['guide_image'] != null
? new AppConfigGuideModel.fromJson(json['guide_image'])
: null;
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
if (this.keys != null) {
data['keys'] = this.keys.toJson();
}
if (this.guideImage != null) {
data['guide_image'] = this.guideImage.toJson();
}
return data;
}
}

class AppConfigKeyModel {
AppConfigKeyItemModel weibo;
AppConfigKeyItemModel qq;
AppConfigKeyItemModel weixin;
AppConfigKeyItemModel jdIos;
AppConfigKeyItemModel jdAndroid;

AppConfigKeyModel({this.weibo, this.qq, this.weixin, this.jdIos, this.jdAndroid});

AppConfigKeyModel.fromJson(Map<String, dynamic> json) {
weibo = json['weibo'] != null ? new AppConfigKeyItemModel.fromJson(json['weibo']) : null;
qq = json['qq'] != null ? new AppConfigKeyItemModel.fromJson(json['qq']) : null;
weixin =
json['weixin'] != null ? new AppConfigKeyItemModel.fromJson(json['weixin']) : null;
jdIos = json['jd_ios'] != null ? new AppConfigKeyItemModel.fromJson(json['jd_ios']) : null;
jdAndroid = json['jd_android'] != null
? new AppConfigKeyItemModel.fromJson(json['jd_android'])
: null;
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
if (this.weibo != null) {
data['weibo'] = this.weibo.toJson();
}
if (this.qq != null) {
data['qq'] = this.qq.toJson();
}
if (this.weixin != null) {
data['weixin'] = this.weixin.toJson();
}
if (this.jdIos != null) {
data['jd_ios'] = this.jdIos.toJson();
}
if (this.jdAndroid != null) {
data['jd_android'] = this.jdAndroid.toJson();
}
return data;
}
}

class AppConfigKeyItemModel {
String appId;
String appkey;
String secret;
String redirectUrl;
String universalLink;

AppConfigKeyItemModel({this.appkey, this.secret, this.redirectUrl});

AppConfigKeyItemModel.fromJson(Map<String, dynamic> json) {
appId = json['app_id'];
appkey = json['appkey'];
secret = json['secret'];
redirectUrl = json['redirect_url'];
universalLink = json['universal_link'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['app_id'] = this.appId;
data['appkey'] = this.appkey;
data['secret'] = this.secret;
data['redirect_url'] = this.redirectUrl;
data['universal_link'] = this.universalLink;
return data;
}
}

class AppConfigGuideModel {
String isShowIndicator;
List<String> images;

AppConfigGuideModel({this.isShowIndicator, this.images});

AppConfigGuideModel.fromJson(Map<String, dynamic> json) {
isShowIndicator = json['is_show_indicator'];
images = json['images'].cast<String>();
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['is_show_indicator'] = this.isShowIndicator;
data['images'] = this.images;
return data;
}
}

+ 22
- 13
lib/register.dart ファイルの表示

@@ -3,6 +3,7 @@ import 'dart:io';
import 'package:jdsdk/jdsdk.dart';
import 'package:sharesdk_plugin/sharesdk_interface.dart';
import 'package:sharesdk_plugin/sharesdk_register.dart';
import 'package:zhiying_base_widget/models/app_config_model.dart';
import 'package:zhiying_base_widget/pages/about_us_page/about_us_page.dart';
import 'package:zhiying_base_widget/pages/bil_detail_page/bil_detail_page.dart';
import 'package:zhiying_base_widget/pages/feedback_page/feedback_page.dart';
@@ -95,26 +96,34 @@ class BaseWidgetRegister {
});

Application.addMethod(() async {
AppConfigModel config = await AppConfigModel.init();
if (config == null) {
Logger.debug('app 初始化失败');
return ;
}
ShareSDKRegister register = ShareSDKRegister();
register.setupWechat("wx617c77c82218ea2c",
"c7253e5289986cf4c4c74d1ccc185fb1", "https://www.sandslee.com/");
register.setupSinaWeibo("706709568", "e9e6a24349c91be8ab923af02415782b",
"http://www.sharesdk.cn");
register.setupQQ("1111030588", "XoHKlrBybXy7ORBt");
SharesdkPlugin.regist(register);
});
// ================ Weixin
register.setupWechat(config.keys?.weixin?.appId ?? '',
config.keys?.weixin?.secret ?? '', config.keys?.weixin?.universalLink ?? '');

Application.addMethod(() async {
print('初始化京东~');
// ================ Weibo
register.setupSinaWeibo(config.keys?.weibo?.appkey ?? '', config.keys?.weibo?.secret ?? '',
config.keys?.weibo?.redirectUrl ?? '');

// ================ QQ
register.setupQQ(config.keys?.qq?.appId ?? '', config.keys?.qq?.appkey ?? '');

// ================ jd
if (Platform.isIOS) {
Jdsdk.init(
appKey: 'f17dcdf22df3bd440fac4c3cbcc76bff',
appSecret: 'a60bea3315794ae9bb9b7ea749be8506');
appKey: config.keys?.jdIos?.appkey ?? '',
appSecret: config.keys?.jdIos?.secret ?? '');
} else if (Platform.isAndroid) {
Jdsdk.init(
appKey: 'c0abbe1f201464ee139d613591a1be02',
appSecret: 'a0eeac7105bf4c7cb573972aa03ed95c');
appKey: config.keys?.jdAndroid?.appkey ?? '',
appSecret: config.keys?.jdAndroid?.secret ?? '');
}
SharesdkPlugin.regist(register);
});

Application.addMethod(() async {


読み込み中…
キャンセル
保存