浏览代码

1.优化手机号一键登录

tags/0.0.3+3^0
“yanghuaxuan” 3 年前
父节点
当前提交
428584651b
共有 13 个文件被更改,包括 171 次插入62 次删除
  1. +2
    -0
      .gitignore
  2. +3
    -1
      example/ios/Runner/AppDelegate.m
  3. +24
    -14
      example/ios/Runner/Info.plist
  4. +41
    -26
      example/lib/main.dart
  5. +35
    -14
      lib/models/base/base_setting_model.dart
  6. +24
    -0
      lib/util/alipay_util.dart
  7. +3
    -0
      lib/util/global_config.dart
  8. +11
    -4
      lib/util/mob_util/secverify/quick_login_util.dart
  9. +10
    -1
      lib/util/net_util.dart
  10. +2
    -1
      lib/util/update/app_update_util.dart
  11. +1
    -0
      lib/zhiying_comm.dart
  12. +9
    -0
      pubspec.lock
  13. +6
    -1
      pubspec.yaml

+ 2
- 0
.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


+ 3
- 1
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"
};
}



+ 24
- 14
example/ios/Runner/Info.plist 查看文件

@@ -114,6 +114,16 @@
<string>kd920070801.open.fleetingpower.com</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>alipay</string>
<key>CFBundleURLSchemes</key>
<array>
<string>tobiasexample</string>
</array>
</dict>
</array>
<key>CFBundleVersion</key>
<string>$(FLUTTER_BUILD_NUMBER)</string>
@@ -190,6 +200,20 @@
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSCameraUsageDescription</key>
<string>获取相机权限更换头像或者扫码</string>
<key>NSContactsUsageDescription</key>
<string>获取访问通信录权限添加联系人信息</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>获取定位权限用于搜索附近的网点和查找附近的油站信息</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>获取定位权限用于搜索附近的网点和查找附近的油站信息</string>
<key>NSMicrophoneUsageDescription</key>
<string>获取访问麦克风权限录制语音或视频</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>获取访问相册权限更换头像</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>获取访问相册权限更换头像</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
@@ -211,19 +235,5 @@
<false/>
<key>io.flutter.embedded_views_preview</key>
<string>YES</string>
<key>NSCameraUsageDescription</key>
<string>获取相机权限更换头像或者扫码</string>
<key>NSContactsUsageDescription</key>
<string>获取访问通信录权限添加联系人信息</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>获取定位权限用于搜索附近的网点和查找附近的油站信息</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>获取定位权限用于搜索附近的网点和查找附近的油站信息</string>
<key>NSMicrophoneUsageDescription</key>
<string>获取访问麦克风权限录制语音或视频</string>
<key>NSPhotoLibraryAddUsageDescription</key>
<string>获取访问相册权限更换头像</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>获取访问相册权限更换头像</string>
</dict>
</plist>

+ 41
- 26
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<MyApp> {
@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<MyApp> {

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);
// });
}
}

+ 35
- 14
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<String, dynamic> json) {
fileProvider = json['file_provider'];
@@ -41,21 +41,42 @@ class BaseSettingModel {
return data;
}

static Future<BaseSettingModel> init() async {
Map result =
await NetUtil.post('/api/v1/new/config.json', method: NetMethod.GET);
static Future<BaseSettingModel> init({bool isGetCache}) async {
try {
var data = result['data'];
_setting = BaseSettingModel.fromJson(Map<String, dynamic>.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<String, dynamic>.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<String, dynamic>.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);
}


+ 24
- 0
lib/util/alipay_util.dart 查看文件

@@ -0,0 +1,24 @@
import 'package:tobias/tobias.dart' as tobias;
///支付宝支付
class AliPayUtil{

///orderCode 为后端返回支付Code字符串
///返回true表示支付成功,false表示支付失败
static Future<bool> toPay(String orderCode)async{

Map<dynamic,dynamic> 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<bool> isInstallAliPay() async {
return await tobias.isAliPayInstalled();
}

}

+ 3
- 0
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';

}

+ 11
- 4
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();


+ 10
- 1
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;


+ 2
- 1
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;
}

/// 检查是否有新版本


+ 1
- 0
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';


+ 9
- 0
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:


+ 6
- 1
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



正在加载...
取消
保存