Android对接SDK不需要任何参数,只需要依赖官方aar即可
导入支付宝 SDK
allprojects {
repositories {
// 添加下面的内容
mavenCentral()
// ... jcenter() 等其他仓库
}
}
dependencies {
api 'com.alipay.sdk:alipaysdk-android:+@aar'
}
付宝 SDK 开发资源导入完成。
运行权限
android.permission.INTERNET
android.permission.ACCESS_NETWORK_STATE
android.permission.ACCESS_WIFI_STATE
支付接口调用
final String orderInfo = info; // 订单信息(由后台生成并返回)
Runnable payRunnable = new Runnable() {
@Override
public void run() {
PayTask alipay = new PayTask(DemoActivity.this);
Map <String,String> result = alipay.payV2(orderInfo,true);
Message msg = new Message();
msg.what = SDK_PAY_FLAG;
msg.obj = result;
mHandler.sendMessage(msg);
}
};
// 必须异步调用
Thread payThread = new Thread(payRunnable);
payThread.start();
String orderInfo
app 支付请求参数字符串,主要包含商户的订单信息,key=value 形式,以&连接。
boolean isShowPayLoading
用户在商户 app 内部点击付款,是否需要一个 loading 做为在钱包唤起之前的过渡,这个值设置为 true,将会在调用 pay 接口的时候直接唤起一个 loading,直到唤起 H5 支付页面或者唤起外部的钱包付款页面 loading 才消失。(建议将该值设置为 true,优化点击付款到支付唤起支付页面的过渡过程。)orderInfo示例
app_id=2015052600090779&biz_content=%7B%22timeout_express%22%3A%2230m%22%2C%22seller_id%22%3A%22%22%2C%22product_code%22%3A%22QUICK_MSecurity_PAY%22%2C%22total_amount%22%3A%220.02%22%2C%22subject%22%3A%221%22%2C%22body%22%3A%22%E6%88%91%E6%98%AF%E6%B5%8B%E8%AF%95%E6%95%B0%E6%8D%AE%22%2C%22out_Trade_no%22%3A%22314VYGIAGG7ZOYY%22%7D&charset=utf-8&method=alipay.Trade.app.pay&sign_type=RSA2×tamp=2016-08-15%2012%3A12%3A15&version=1.0&sign=MsbylYkCzlfYLy9PeRwUUIg9nZPeN9SfXPNavUCroGKR5Kqvx0nEnd3eRmKxJuthNUx4ERCXe552EV9PfwexqW%2B1wbKOdYtDIb4%2B7PL3Pc94RZL0zKaWcaY3tSL89%2FuAVUsQuFqEJdhIukuKygrXucvejOUgTCfoUdwTi7z%2BZzQ%3D
支付结果获取和处理
private Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
Result result = new Result((String) msg.obj);
Toast.makeText(DemoActivity.this, result.getResult(),
Toast.LENGTH_LONG).show();
};
};