diff --git a/.gitignore b/.gitignore index c080ae3..9efc2d9 100644 --- a/.gitignore +++ b/.gitignore @@ -42,6 +42,8 @@ captures/ .idea/gradle.xml .idea/dictionaries .idea/libraries +.idea/ +.dart_tool/ # External native build folder generated in Android Studio 2.2 and later .externalNativeBuild diff --git a/example/ios/Runner/AppDelegate.m b/example/ios/Runner/AppDelegate.m index 8100581..62487fb 100644 --- a/example/ios/Runner/AppDelegate.m +++ b/example/ios/Runner/AppDelegate.m @@ -37,7 +37,9 @@ return @{ // @"domain": @"http://120.76.175.204:8989" @"domain": @"http://inapi.izhyin.cn", - @"token": @"cc455e0c0b6a75ff09aeb966c211fb967d69b63d" + @"master_id":@"123456", + @"secret_key":@"123456" + // @"token": @"cc455e0c0b6a75ff09aeb966c211fb967d69b63d" }; } diff --git a/example/ios/Runner/Info.plist b/example/ios/Runner/Info.plist index bb21462..0e1a57a 100644 --- a/example/ios/Runner/Info.plist +++ b/example/ios/Runner/Info.plist @@ -114,6 +114,16 @@ kd920070801.open.fleetingpower.com + + CFBundleTypeRole + Editor + CFBundleURLName + alipay + CFBundleURLSchemes + + tobiasexample + + CFBundleVersion $(FLUTTER_BUILD_NUMBER) @@ -190,6 +200,20 @@ NSAllowsArbitraryLoads + NSCameraUsageDescription + 获取相机权限更换头像或者扫码 + NSContactsUsageDescription + 获取访问通信录权限添加联系人信息 + NSLocationAlwaysUsageDescription + 获取定位权限用于搜索附近的网点和查找附近的油站信息 + NSLocationWhenInUseUsageDescription + 获取定位权限用于搜索附近的网点和查找附近的油站信息 + NSMicrophoneUsageDescription + 获取访问麦克风权限录制语音或视频 + NSPhotoLibraryAddUsageDescription + 获取访问相册权限更换头像 + NSPhotoLibraryUsageDescription + 获取访问相册权限更换头像 UILaunchStoryboardName LaunchScreen UIMainStoryboardFile @@ -211,19 +235,5 @@ io.flutter.embedded_views_preview YES - NSCameraUsageDescription - 获取相机权限更换头像或者扫码 - NSContactsUsageDescription - 获取访问通信录权限添加联系人信息 - NSLocationAlwaysUsageDescription - 获取定位权限用于搜索附近的网点和查找附近的油站信息 - NSLocationWhenInUseUsageDescription - 获取定位权限用于搜索附近的网点和查找附近的油站信息 - NSMicrophoneUsageDescription - 获取访问麦克风权限录制语音或视频 - NSPhotoLibraryAddUsageDescription - 获取访问相册权限更换头像 - NSPhotoLibraryUsageDescription - 获取访问相册权限更换头像 diff --git a/example/lib/main.dart b/example/lib/main.dart index b7b12ad..7ea6f91 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,3 +1,4 @@ + import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:flutter_alibc/flutter_alibc.dart'; @@ -21,10 +22,7 @@ class _MyAppState extends State { @override void initState() { BaseWidgetRegister.init(); - Jdsdk.init( - appKey: '9fc3dec00b9b40cc950dfba5262cd6d3', - appSecret: 'f785613e5fd54a129d0f0359a4e25c23') - .then((result) { + Jdsdk.init(appKey: '9fc3dec00b9b40cc950dfba5262cd6d3', appSecret: 'f785613e5fd54a129d0f0359a4e25c23').then((result) { Logger.debug('京东初始化:${result.toString()}'); }); FlutterAlibc.initAlibc(version: "", appName: "").then((result) { @@ -44,8 +42,7 @@ class _MyAppState extends State { class HomePage extends StatelessWidget { netPost() async { - dynamic result = - await NetUtil.post('/api/v1/rec/featured?page=1', params: null); + dynamic result = await NetUtil.post('/api/v1/rec/featured?page=1', params: null); print("result === ${result?.toString()}"); } @@ -64,29 +61,25 @@ class HomePage extends StatelessWidget { onPressed: () { // d75d2fc6592f4526e297643446416581bd89e837 // cc455e0c0b6a75ff09aeb966c211fb967d69b63d - SharedPreferencesUtil.setStringValue( - GlobalConfig.SHARED_KEY_TOKEN, - 'd75d2fc6592f4526e297643446416581bd89e837'); + SharedPreferencesUtil.setStringValue(GlobalConfig.SHARED_KEY_TOKEN, 'd75d2fc6592f4526e297643446416581bd89e837'); }, child: Text('登录'), ), RaisedButton( onPressed: () { - SharedPreferencesUtil.setStringValue( - GlobalConfig.SHARED_KEY_TOKEN, ''); + SharedPreferencesUtil.setStringValue(GlobalConfig.SHARED_KEY_TOKEN, ''); }, child: Text('退出登录'), ), RaisedButton( onPressed: () { - NetUtil.request('/api/v1/rec/featured?page=1', params: null, - onError: (msg) { - print('onERROR = ${msg?.toString() ?? 'onError'}'); - }, onSuccess: (json) { - print('onSuccess = ${json?.toString() ?? 'onSuccess'}'); - }, onCache: (json) { - print('onCache = ${json?.toString() ?? 'onCache'}'); - }); + NetUtil.request('/api/v1/rec/featured?page=1', params: null, onError: (msg) { + print('onERROR = ${msg?.toString() ?? 'onError'}'); + }, onSuccess: (json) { + print('onSuccess = ${json?.toString() ?? 'onSuccess'}'); + }, onCache: (json) { + print('onCache = ${json?.toString() ?? 'onCache'}'); + }); }, child: Text('网络异步请求(带缓存)'), ), @@ -142,8 +135,9 @@ class HomePage extends StatelessWidget { onPressed: () { // Dio dio = Dio(); - dio.get( - 'http://www.hairuyi.com/?mod=appapi&act=gotojingdong&gid=60291609161&yhq_url=http%3A%2F%2Fcoupon.m.jd.com%2Fcoupons%2Fshow.action%3Fkey%3Dd97e1472a8a24c39a9463dbe72b3fa32%26roleId%3D38088450%26to%3Ditem.jd.com%2F60291609161.html') + dio + .get( + 'http://www.hairuyi.com/?mod=appapi&act=gotojingdong&gid=60291609161&yhq_url=http%3A%2F%2Fcoupon.m.jd.com%2Fcoupons%2Fshow.action%3Fkey%3Dd97e1472a8a24c39a9463dbe72b3fa32%26roleId%3D38088450%26to%3Ditem.jd.com%2F60291609161.html') .then((value) { Logger.debug(value.realUri.toString()); }); @@ -153,7 +147,8 @@ class HomePage extends StatelessWidget { RaisedButton( onPressed: () { Jdsdk.openUrl( - url: 'http://www.hairuyi.com/?mod=appapi&act=gotojingdong&gid=60291609161&yhq_url=http%3A%2F%2Fcoupon.m.jd.com%2Fcoupons%2Fshow.action%3Fkey%3Dd97e1472a8a24c39a9463dbe72b3fa32%26roleId%3D38088450%26to%3Ditem.jd.com%2F60291609161.html'); + url: + 'http://www.hairuyi.com/?mod=appapi&act=gotojingdong&gid=60291609161&yhq_url=http%3A%2F%2Fcoupon.m.jd.com%2Fcoupons%2Fshow.action%3Fkey%3Dd97e1472a8a24c39a9463dbe72b3fa32%26roleId%3D38088450%26to%3Ditem.jd.com%2F60291609161.html'); }, child: Text('打开京东详情'), ), @@ -200,14 +195,13 @@ class HomePage extends StatelessWidget { previewImageDatas.add(PreviewImageData( previewImageType: PreviewImageType.netUrl, data: - "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1604924972652&di=2849a989df574db3fbb7a8994ea87fc3&imgtype=0&src=http%3A%2F%2Fpic1.win4000.com%2Fwallpaper%2Fc%2F574420055d0b9.jpg")); + "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1604924972652&di=2849a989df574db3fbb7a8994ea87fc3&imgtype=0&src=http%3A%2F%2Fpic1.win4000.com%2Fwallpaper%2Fc%2F574420055d0b9.jpg")); } - PhotoPreview.showPhotoPreview(context, previewImageDatas,currentIndex: 0); + PhotoPreview.showPhotoPreview(context, previewImageDatas, currentIndex: 0); }, child: Text('预览图片'), ), - RaisedButton( onPressed: () async { Navigator.push(context, MaterialPageRoute(builder: (_) { @@ -216,7 +210,12 @@ class HomePage extends StatelessWidget { }, child: Text('打开登录'), ), - + RaisedButton( + onPressed: () async { + toPay(); + }, + child: Text('支付宝支付'), + ), ], ), ), @@ -236,4 +235,20 @@ class HomePage extends StatelessWidget { method: NetMethod.POST); print('apapapsdjfdsjf: ${param?.toString()}'); } + + ///支付宝支付 + void toPay() async { + var result = await AliPayUtil.toPay('app_id=2016120103683451\u0026biz_content=%7B%22out_trade_no%22%3A%22706160993071863177%22%2C%22passback_params%22%3A%22706160993071863177%22%2C%22subject%22%3A%22%E6%B5%8B%E8%AF%95%22%2C%22total_amount%22%3A%220.01%22%7D\u0026charset=utf-8\u0026format=JSON\u0026method=alipay.trade.app.pay\u0026notify_url=inapi.izhyin.cn%2Fapi%2Fv1%2Falipay%2Fcallback%3Fmaster_id%3D123456\u0026sign=juCL4eFWKDdpis0EEb8AHgazPql1QXODJ4K%2BglffzxkdUKhuPXBzkI4Fcull3RZ94kD63qlXAhGnbcPIYiUnxoec1sR5xEvEk3rxFJcmEBhPXMIX6nyh8Z2IdzeRzEjypidPR3U5T6OgdabaXADKjGd%2BKDH%2FhzCRSOyMf7TNazyoKAWX3D10R4QQjChDrBLXY6WTqrEcJVZVg8IgC1znZPuG3pO%2BtPFpiwjbT0rAcxWqj5ZbwddyDpfSM7gvpmBymDDvW3bUUQ8h4wszTClyvCQ6fXSeHX%2BgsFhqhkK01U4OhzDH4ipsMTe1Jz6fJveCICtdGd4c6Sikk%2Bhzn8br1w%3D%3D\u0026sign_type=RSA2\u0026timestamp=2021-01-06+18%3A58%3A38\u0026version=1.0'); + // var params = {'subject': '测试', 'amount': "0.01"}; + // print("请求数据"); + // NetUtil.request("/api/v1/user/alipay", params: params, method: NetMethod.POST, onSuccess: (data) async { + // print(data); + // var result = await AliPayUtil.toPay(data); + // if(result){ + // print("支付成功"); + // } + // },onError: (err){ + // print(err); + // }); + } } diff --git a/lib/models/base/base_setting_model.dart b/lib/models/base/base_setting_model.dart index 3586463..dc3cb01 100644 --- a/lib/models/base/base_setting_model.dart +++ b/lib/models/base/base_setting_model.dart @@ -1,4 +1,5 @@ import 'dart:io'; +import 'dart:convert'; import 'package:zhiying_comm/util/net_util.dart'; import 'package:zhiying_comm/util/shared_prefe_util.dart'; @@ -20,8 +21,7 @@ class BaseSettingModel { return _setting; } - BaseSettingModel( - {this.fileProvider, this.fileBucketHost, this.fileBucketHostProtocol}); + BaseSettingModel({this.fileProvider, this.fileBucketHost, this.fileBucketHostProtocol}); BaseSettingModel.fromJson(Map json) { fileProvider = json['file_provider']; @@ -41,21 +41,42 @@ class BaseSettingModel { return data; } - static Future init() async { - Map result = - await NetUtil.post('/api/v1/new/config.json', method: NetMethod.GET); + static Future init({bool isGetCache}) async { try { - var data = result['data']; - _setting = BaseSettingModel.fromJson(Map.from(data)); - if(Platform.isIOS) { - if (null != _setting && _setting.isIosReview == '1') { - SharedPreferencesUtil.setStringValue(GlobalConfig.IS_IOS_REVIEW, '1'); - } else { - SharedPreferencesUtil.setStringValue(GlobalConfig.IS_IOS_REVIEW, '0'); + ///判断是否获取缓存 + if (isGetCache != null && isGetCache) { + String configData = await SharedPreferencesUtil.getStringValue(GlobalConfig.MAIN_CONFIG, defaultVal: '1'); + if (configData != "1") { + _setting = BaseSettingModel.fromJson(Map.from(json.decode(configData))); + if (Platform.isIOS) { + if (null != _setting && _setting.isIosReview == '1') { + SharedPreferencesUtil.setStringValue(GlobalConfig.IS_IOS_REVIEW, '1'); + } else { + SharedPreferencesUtil.setStringValue(GlobalConfig.IS_IOS_REVIEW, '0'); + } + } + Logger.debug('基础设置初始化'); + } + NetUtil.request('/api/v1/new/config.json',onSuccess: (data){ + + }); + + + } else { + Map result = + await NetUtil.post('/api/v1/new/config.json', method: NetMethod.GET); + var data = result['data']; + _setting = BaseSettingModel.fromJson(Map.from(data)); + if (Platform.isIOS) { + if (null != _setting && _setting.isIosReview == '1') { + SharedPreferencesUtil.setStringValue(GlobalConfig.IS_IOS_REVIEW, '1'); + } else { + SharedPreferencesUtil.setStringValue(GlobalConfig.IS_IOS_REVIEW, '0'); + } } + Logger.debug('基础设置初始化'); + return _setting; } - Logger.debug('基础设置初始化'); - return _setting; } catch (err) { Logger.error(err); } diff --git a/lib/util/alipay_util.dart b/lib/util/alipay_util.dart new file mode 100644 index 0000000..d739200 --- /dev/null +++ b/lib/util/alipay_util.dart @@ -0,0 +1,24 @@ +import 'package:tobias/tobias.dart' as tobias; +///支付宝支付 +class AliPayUtil{ + + ///orderCode 为后端返回支付Code字符串 + ///返回true表示支付成功,false表示支付失败 + static Future toPay(String orderCode)async{ + + Map result= await tobias.aliPay(orderCode); + if(result!=null&&result['resultStatus']!=null&&result['resultStatus'].toString()=="9000"){ + print("支付宝支付结果"); + print(result); + return true; + }else{ + return false; + } + } + + ///检查是否安装了支付宝 + static Future isInstallAliPay() async { + return await tobias.isAliPayInstalled(); + } + +} \ No newline at end of file diff --git a/lib/util/global_config.dart b/lib/util/global_config.dart index 840379e..cfc754e 100644 --- a/lib/util/global_config.dart +++ b/lib/util/global_config.dart @@ -44,4 +44,7 @@ class GlobalConfig { /// 苹果审核 static final String IS_IOS_REVIEW = 'is_ios_review'; + ///主要配置 + static final String MAIN_CONFIG='sp_main_config'; + } diff --git a/lib/util/mob_util/secverify/quick_login_util.dart b/lib/util/mob_util/secverify/quick_login_util.dart index 0f5d827..e2fa811 100644 --- a/lib/util/mob_util/secverify/quick_login_util.dart +++ b/lib/util/mob_util/secverify/quick_login_util.dart @@ -93,7 +93,7 @@ class QuickLoginUtil { } // 需要自己实现这部分 - void _doLogin(Map ret, BuildContext context) async { + Future _doLogin(Map ret, BuildContext context) async { var opToken = ret.containsKey("opToken") ? ret["opToken"] : ""; var token = ret.containsKey("token") ? ret["token"] : ""; var operator = ret.containsKey("operator") ? ret["operator"] : ""; @@ -110,8 +110,12 @@ class QuickLoginUtil { // params["appkey"] = appKey; try { + BuildContext context1 = navigatorKey.currentState.overlay.context; + Loading.show(context1,msg: "加载中..."); + print("加载中..."); var result = await NetUtil.post('/api/v1/sign/mob/in', params: params, method: NetMethod.POST); if (NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) { + Loading.dismiss(); UserInfoModel model = UserInfoModel.fromJson(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]); if (!EmptyUtil.isEmpty(model)) { if (model.registerInviteCodeEnable == '1') { @@ -126,8 +130,11 @@ class QuickLoginUtil { return; } } + }else{ + Loading.dismiss(); } } catch (e, s) { + Loading.dismiss(); Logger.error(e, s); } Fluttertoast.showToast(msg: '登录失败'); @@ -182,14 +189,14 @@ class QuickLoginUtil { // 取号接口 void _verify(BuildContext context) { - Secverify.preVerify((ret, err) { + Secverify.preVerify((ret, err) async { if (err != null) { // showAlert(err.toString(),context); Logger.log(err.toString()); _openSMSLoginPage(context); Loading.dismiss(); } else { - Secverify.verify((Map ret, Map err) { + Secverify.verify((Map ret, Map err) async { if (err != null) { //打印错误信息 // showAlert(err.toString(), context); @@ -214,7 +221,7 @@ class QuickLoginUtil { Secverify.finshOauthPage(); } else if (ret.containsKey("opToken")) { //如果登录成功,将返回的信息提交给自己的服务器 - _doLogin(ret, context); + await _doLogin(ret, context); //调用此方法手动关闭授权页面 Loading.dismiss(); Secverify.finshOauthPage(); diff --git a/lib/util/net_util.dart b/lib/util/net_util.dart index deea733..0ccbde6 100644 --- a/lib/util/net_util.dart +++ b/lib/util/net_util.dart @@ -55,7 +55,7 @@ class NetUtil { if (_dio == null) { var setting = await NativeUtil.getSetting(); String domain = setting['domain']; //'http://www.hairuyi.com/'; - _config(domain, proxyUrl: '');// 192.168.0.66:8866 + _config(domain, proxyUrl: '192.168.0.102:8866');// 192.168.0.66:8866 } return _dio; } @@ -355,6 +355,15 @@ class NetUtil { // token 读取SP缓存中的用户token String token = await SharedPreferencesUtil.getStringValue(GlobalConfig.SHARED_KEY_TOKEN); + + if(EmptyUtil.isEmpty(token)&&!bool.fromEnvironment("dart.vm.product")){ + try{ + token=setting['token']; + }catch(e,s){ + print(s); + print(e); + } + } if (!EmptyUtil.isEmpty(token)) { // params['token'] = token; params['Authorization'] = 'Bearer ' + token; diff --git a/lib/util/update/app_update_util.dart b/lib/util/update/app_update_util.dart index 2b411b4..283f371 100644 --- a/lib/util/update/app_update_util.dart +++ b/lib/util/update/app_update_util.dart @@ -71,7 +71,7 @@ class AppUpdateUtil { /// @needToast 是否需要提示最新版本 /// @mustShowDialog 是否必须弹窗(检查更新页面要弹窗) /// - static void updateApp(BuildContext context, {bool needToast = false, bool mustShowDialog = false}) async { + static Future updateApp(BuildContext context, {bool needToast = false, bool mustShowDialog = false}) async { UpdateEntity updateEntity = await _checkAppUpdate(); // 有新版本,进行更新 if (!EmptyUtil.isEmpty(updateEntity) && updateEntity.hasUpdate) { @@ -99,6 +99,7 @@ class AppUpdateUtil { } else { if (needToast) Fluttertoast.showToast(msg: '已经是最新版本了~'); } + return null; } /// 检查是否有新版本 diff --git a/lib/zhiying_comm.dart b/lib/zhiying_comm.dart index 556b447..01851fd 100644 --- a/lib/zhiying_comm.dart +++ b/lib/zhiying_comm.dart @@ -37,4 +37,5 @@ export 'util/photo_preview/photo_preview.dart'; export 'models/base/base_change_notifier.dart'; export 'util/parse_util.dart'; export 'util/download/download.dart'; +export 'util/alipay_util.dart'; diff --git a/pubspec.lock b/pubspec.lock index abe153a..4173433 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -577,6 +577,15 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "0.2.15" + tobias: + dependency: "direct main" + description: + path: "." + ref: "0.0.1" + resolved-ref: cbd12d0ea1df08062fbd06e3a04986f86c7cf1ef + url: "http://192.168.0.138:3000/FnuoOS_ZhiYing/tobias.git" + source: git + version: "1.7.1+1" typed_data: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index d654ccd..7e20efa 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -77,7 +77,12 @@ dependencies: #保存文件到相册 save_image: ^1.0.1 - dio_cookie_manager: 1.0.0 + dio_cookie_manager: ^1.0.0 + #支付宝支付flutterSDK + tobias: + git: + url: 'http://192.168.0.138:3000/FnuoOS_ZhiYing/tobias.git' + ref: '0.0.1' event_bus: 1.1.1