Closed EvanJin closed 3 months ago
这个开发必备的选项竟然没实现。也没有人回复?其实很简单: 1、下载源代码 2、打开项目。 修改以下代码:
alipay_kit/lib/src/alipay_kit_platform_interface.dart
/// 支付
Future<void> pay({
required String orderInfo,
bool isShowLoading = true,
bool sandbox = false /// 沙箱模式
}) {
throw UnimplementedError(
'pay({required orderInfo, isShowLoading}) has not been implemented.');
}
alipay_kit/lib/src/alipay_kit_method_channel.dart
@override
Future<void> pay({
required String orderInfo,
bool isShowLoading = true,
bool sandbox = false /// 沙箱模式
}) {
return methodChannel.invokeMethod<void>(
'pay',
<String, dynamic>{
'orderInfo': orderInfo,
'isShowLoading': isShowLoading,
'sandbox': sandbox,
},
);
}
alipay_kit_android/android/src/main/java/io/github/v7lin/alipay_kit/AlipayKitPlugin.java
import com.alipay.sdk.app.EnvUtils;
...
...
...
else if ("pay".equals(call.method)) {
final String orderInfo = call.argument("orderInfo");
final boolean isShowLoading = call.argument("isShowLoading");
final boolean sandbox = call.argument("sandbox"); // 沙箱模式支持
final WeakReference<Activity> activityRef = new WeakReference<>(activity);
final WeakReference<MethodChannel> channelRef = new WeakReference<>(channel);
//noinspection deprecation
new AsyncTask<String, String, Map<String, String>>() {
@Override
protected Map<String, String> doInBackground(String... params) {
final Activity activity = activityRef.get();
if (activity != null && !activity.isFinishing()) {
// 沙箱模式支持
if(sandbox){
EnvUtils.setEnv(EnvUtils.EnvEnum.SANDBOX);
}
// 沙箱模式支持
final PayTask task = new PayTask(activity);
return task.payV2(orderInfo, isShowLoading);
}
return null;
}
在项目中引用
pubspec.yaml
# 支付宝
# alipay_kit: ^4.0.0
alipay_kit:
path: \alipay_kit-master\alipay_kit
///调用方法
Alipay.instance.pay(
orderInfo: ***,
isShowLoading: true,
sandbox: true
);
AlipayKitPlatform.instance.setEnv(env: AlipayEnv.sandbox); 这段代码,可以切换成沙箱模式
API中貌似没有看到沙箱环境的接口,请问一下,可以APP支付可以设置沙箱环境吗?