Android开发集成支付宝支付

释放双眼,带上耳机,听听看~!

前面的步骤查看https://blog.csdn.net/sunshine_0707/article/details/85272568

第一步:添加jar包到libs文件夹下

2.在APP工程的build.gradle中配置jniLibs的目录

    sourceSets {
main {
jniLibs.srcDirs = ['libs']
}
}  

3.添加gradle依赖

//支付宝支付新版
implementation(name: 'alipaySdk-15.6.2-20190416165036', ext: 'aar')
//支付宝支付旧版
// implementation files('libs/alipaySdk-20170922.jar')

4.添加权限

android.permission.INTERNET
android.permission.ACCESS_NETWORK_STATE
android.permission.ACCESS_WIFI_STATE

5.在项目的主build.gradle不是app下的build.gradle的allprojects 下添加

allprojects {
repositories {
google()
jcenter()
//集成阿里推送添加的
maven {
url 'http://maven.aliyun.com/nexus/content/repositories/releases/'
}
//集成支付宝添加的
flatDir {
dirs 'libs'
}
maven { url 'https://dl.bintray.com/umsdk/release' } //友盟统计
maven { url 'https://jitpack.io' }
}
}

6.通过订单id获取到订单的详情,将订单的详情作为参数,调起支付宝支付

void aLiPay(final String orderInfo, final Context context, final PreAuthorizedPaymentContract.PreAuthorizedPaymentReasonListener preAuthorizedPaymentReasonListener, final PreAauthorizedPaymentService preAauthorizedPaymentService, final String id, final PreAuthorizedPaymentContract.PreAuthorizedPaymentSerachReasonListener preAuthorizedPaymentSerachReasonListener) {
//阿里预授权支付
Runnable payRunnable = new Runnable() {
@Override
public void run() {
if (context != null) {
PayTask alipay = new PayTask((Activity) context);
Map<String, String> result = alipay.payV2(orderInfo, true);
if (result.get("resultStatus") != null && !"".equals(result.get("resultStatus").toString())) {
switch (result.get("resultStatus").toString()) {
case "4000":
if (preAuthorizedPaymentReasonListener != null)
preAuthorizedPaymentReasonListener.onResponse("订单支付失败");
break;
case "5000":
if (preAuthorizedPaymentReasonListener != null)
preAuthorizedPaymentReasonListener.onResponse("请勿重复操作");
break;
case "6001":
if (preAuthorizedPaymentReasonListener != null)
preAuthorizedPaymentReasonListener.onResponse("操作已取消");
break;
case "6002":
if (preAuthorizedPaymentReasonListener != null)
preAuthorizedPaymentReasonListener.onResponse("网络连接出错");
break;
case "6004":
if (preAuthorizedPaymentReasonListener != null)
preAuthorizedPaymentReasonListener.onResponse("正在处理中,请稍后在订单详情查看支付结果");
Constants.WEI_XIN_PAY_RESULT = 0;
Constants.WEI_XIN_PAY_RESULT = 3;
aLiPaySuccess(id, preAuthorizedPaymentSerachReasonListener);
break;
case "8000":
if (preAuthorizedPaymentReasonListener != null)
preAuthorizedPaymentReasonListener.onResponse("支付结果未知,请稍后在订单详情查看支付结果");
Constants.WEI_XIN_PAY_RESULT = 0;
Constants.WEI_XIN_PAY_RESULT = 3;
aLiPaySuccess(id, preAuthorizedPaymentSerachReasonListener);
break;
case "9000":
if (preAuthorizedPaymentReasonListener != null)
preAuthorizedPaymentReasonListener.onResponse("支付成功");
Constants.WEI_XIN_PAY_RESULT = 0;
Constants.WEI_XIN_PAY_RESULT = 3;
aLiPaySuccess(id, preAuthorizedPaymentSerachReasonListener);
break;
case "其它":
if (preAuthorizedPaymentReasonListener != null)
preAuthorizedPaymentReasonListener.onResponse("其他支付错误");
break;
default:
break;
}
}
} else {
if (preAuthorizedPaymentReasonListener != null)
preAuthorizedPaymentReasonListener.onFail("网络错误");
}
}
};
// 必须异步调用
Thread payThread = new Thread(payRunnable);
payThread.start();
}

这是测试服务器的,订单金额方便测试

人已赞赏
Android文章

Android开发百度离线人脸识别小案例

2021-2-1 17:39:53

Android文章

Android开发集成微信支付

2021-2-1 18:22:22

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索