diff --git a/lib/models/app_config_model.dart b/lib/models/app_config_model.dart new file mode 100644 index 0000000..3a71ade --- /dev/null +++ b/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 init() async { + Map result = + await NetUtil.post('/api/v1/app/guide', method: NetMethod.GET); + try { + var data = result['data']; + _config = AppConfigModel.fromJson(Map.from(data)); + Logger.debug('基础设置初始化'); + return _config; + } catch (err) { + Logger.error(err); + } + return null; + } + + AppConfigModel.fromJson(Map json) { + keys = json['keys'] != null ? new AppConfigKeyModel.fromJson(json['keys']) : null; + guideImage = json['guide_image'] != null + ? new AppConfigGuideModel.fromJson(json['guide_image']) + : null; + } + + Map toJson() { + final Map data = new Map(); + 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 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 toJson() { + final Map data = new Map(); + 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 json) { + appId = json['app_id']; + appkey = json['appkey']; + secret = json['secret']; + redirectUrl = json['redirect_url']; + universalLink = json['universal_link']; + } + + Map toJson() { + final Map data = new Map(); + 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 images; + + AppConfigGuideModel({this.isShowIndicator, this.images}); + + AppConfigGuideModel.fromJson(Map json) { + isShowIndicator = json['is_show_indicator']; + images = json['images'].cast(); + } + + Map toJson() { + final Map data = new Map(); + data['is_show_indicator'] = this.isShowIndicator; + data['images'] = this.images; + return data; + } +} diff --git a/lib/register.dart b/lib/register.dart index 7e8d4cd..f036261 100644 --- a/lib/register.dart +++ b/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 {