Flutter金融借贷服务插件finbox_lending_plugin的使用
Flutter金融借贷服务插件finbox_lending_plugin的使用
该插件可以用于集成FinBox借贷SDK。
注意事项
以下信息将在集成时由FinBox团队提供:
ACCESS_KEY
SECRET_KEY
LENDING_SDK_VERSION
DC_SDK_VERSION
COMMON_SDK_VERSION
COMMON_FLAVOR
LOGGER_SDK_VERSION
CLIENT_API_KEY
添加插件
在local.properties
文件中指定以下内容:
ACCESS_KEY=<ACCESS_KEY>
SECRET_KEY=<SECRET_KEY>
LENDING_SDK_VERSION=<LENDING_SDK_VERSION>
DC_SDK_VERSION=<DC_SDK_VERSION>
COMMON_SDK_VERSION=<COMMON_SDK_VERSION>
COMMON_FLAVOR=<COMMON_FLAVOR>
LOGGER_SDK_VERSION=<LOGGER_SDK_VERSION>
在pubspec.yaml
文件中添加插件依赖:
dependencies:
finbox_lending_plugin: any
初始化SDK
调用initSdk
方法并传递所需参数:
FinBoxLendingPlugin.initSdk(
"环境类型", // Environment
"API密钥", // Api key
"客户ID", // Customer ID
"客户令牌", // Customer token
"信用额度提款金额"); // Credit Line withdrawl amount
打开借贷屏幕
调用startLending
方法开始借贷流程:
FinBoxLendingPlugin.startLending();
处理SDK旅程结果
在主页面的build
方法内设置方法处理器:
FinBoxLendingPlugin.platform.setMethodCallHandler(_getJourneyResult);
创建一个方法来处理回调:
static Future<void> _getJourneyResult(MethodCall call) async {
if (call.method == 'getJourneyResult') {
var json = call.arguments;
}
}
接收到的JSON格式如下:
{
"code": "code",
"screen": "screen",
"message": "message"
}
错误代码
以下是错误代码及其描述:
错误类型 | 描述 |
---|---|
MU002 | 开发凭证试用期已过 |
MU003 | PDF密码不正确 |
MU004 | 指定银行与检测到的银行不符 |
MU006 | 非可解析PDF - PDF文件损坏或没有可选择的文本(只有扫描图像) |
MU020 | 不是有效的声明或银行不受支持 |
MU021 | 无效的日期范围 |
NB000 | 网上银行失败 |
NB003 | 网上银行登录错误 |
NB004 | 验证码错误 |
NB005 | 安全错误 |
完整示例Demo
以下是一个完整的示例Demo,展示了如何使用finbox_lending_plugin
插件。
example/lib/main.dart
import 'package:flutter/material.dart';
import 'package:finbox_flutter_lending_example/lending.dart'; // 假设这是插件的示例页面
void main() {
runApp(const MyApp());
}
TextEditingController envController = new TextEditingController(text: "UAT10");
TextEditingController apiKeyController = new TextEditingController(text: "TGCNfiXhYBSaPiRFwXveljpcCkgJihPbbtVElQxW");
TextEditingController customerIdController = new TextEditingController(text: "demo_lender_user_11221538");
TextEditingController tokenController = new TextEditingController(text: "QELthnsBwjVnmVJAdAzsZQeIKGHvlXidqmLdQOILSmJriNnhFnmeJxTWaPJhpwxz");
TextEditingController creditLineAmountController = new TextEditingController(text: "");
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Bank Connect Hybrid'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
[@override](/user/override)
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
void _navigateToLendingScreen(BuildContext context) {
Navigator.of(context).push(MaterialPageRoute(builder: (context) =>
LendingPage(env: envController.text, apiKey: apiKeyController.text,
customerId: customerIdController.text, token: tokenController.text,
creditLineAmount: creditLineAmountController.text)));
}
[@override](/user/override)
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Container(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
TextField(
controller: envController,
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: '环境类型',
),
),
TextField(
controller: apiKeyController,
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'API密钥',
),
),
TextField(
controller: customerIdController,
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: '客户ID',
),
),
TextField(
controller: tokenController,
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: '客户令牌',
),
),
TextField(
controller: creditLineAmountController,
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: '信用额度提款金额',
),
),
ElevatedButton(
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(Colors.blue),
),
onPressed: () {_navigateToLendingScreen(context); },
child: Text('开始'),
)
],
),
),
);
}
}
更多关于Flutter金融借贷服务插件finbox_lending_plugin的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
更多关于Flutter金融借贷服务插件finbox_lending_plugin的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
当然,以下是一个关于如何在Flutter项目中集成和使用finbox_lending_plugin
插件的示例代码案例。这个插件假设是用于提供金融借贷服务的集成。请注意,由于这是一个假设性的插件,实际的API和功能可能会有所不同,你需要根据插件的官方文档进行调整。
1. 添加依赖
首先,你需要在pubspec.yaml
文件中添加finbox_lending_plugin
的依赖:
dependencies:
flutter:
sdk: flutter
finbox_lending_plugin: ^x.y.z # 替换为实际的版本号
然后运行flutter pub get
来安装依赖。
2. 导入插件
在你的Dart文件中(例如main.dart
),导入finbox_lending_plugin
:
import 'package:flutter/material.dart';
import 'package:finbox_lending_plugin/finbox_lending_plugin.dart';
3. 初始化插件
在应用程序启动时,初始化finbox_lending_plugin
。这通常在你的MainApplication
或main.dart
的入口函数中完成。
void main() {
WidgetsFlutterBinding.ensureInitialized();
FinboxLendingPlugin.instance.initialize("YOUR_API_KEY"); // 替换为你的API密钥
runApp(MyApp());
}
4. 使用插件功能
以下是一个示例,展示如何使用插件提供的一些假设性功能,如获取贷款额度、申请贷款等。
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Finbox Lending Plugin Example'),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ElevatedButton(
onPressed: _getLoanLimit,
child: Text('Get Loan Limit'),
),
SizedBox(height: 20),
ElevatedButton(
onPressed: _applyForLoan,
child: Text('Apply for Loan'),
),
],
),
),
),
);
}
Future<void> _getLoanLimit() async {
try {
double loanLimit = await FinboxLendingPlugin.instance.getLoanLimit();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("Your loan limit is \$loanLimit"),
),
);
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("Failed to get loan limit: ${e.message}"),
backgroundColor: Colors.red,
),
);
}
}
Future<void> _applyForLoan() async {
try {
Map<String, dynamic> loanDetails = {
'amount': 1000.0,
'purpose': 'Home Improvement',
'duration': 24, // in months
};
bool isApproved = await FinboxLendingPlugin.instance.applyForLoan(loanDetails);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("Loan application approved: $isApproved"),
),
);
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text("Failed to apply for loan: ${e.message}"),
backgroundColor: Colors.red,
),
);
}
}
}
注意事项
- API密钥:确保你替换了
YOUR_API_KEY
为实际从Finbox Lending服务获取的API密钥。 - 错误处理:在实际应用中,你可能需要更详细的错误处理逻辑。
- UI/UX:上述示例中的UI非常简单,你可能需要根据实际需求进行改进。
- 文档:始终参考
finbox_lending_plugin
的官方文档,因为插件的API和功能可能会更新。
希望这个示例代码能帮助你集成和使用finbox_lending_plugin
插件。