- 代码
public void getAliOrderInfo(String money) {
String url = Contacts.SHAir_SERVICE + Contacts.ServiceConstant.CACHE_PAY;
HashMap<String, String> params = new HashMap<>();
params.put("", "");
params.put("", );
//通过后台给的接口请求数据
OkGo.post(url).tag(getContext())
.params(params, false)
.execute(new StringCallback() {
@Override
public void onSuccess(String s, Call call, Response response) {
try {
AliPay_bean aliPay_bean = new Gson().fromJson(s, AliPay_bean.class);
if (aliPay_bean.getCode().equals("1")) {
final String orderInfo = aliPay_bean.getData();
Runnable payRunnable = new Runnable() {
@Override
public void run() {
PayTask alipayTask = new PayTask(activity);
Map<String, String> result = alipayTask.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();
} else{
ToastUtil.showToastShort(getContext(), "调用失败");
}
} catch (Exception e) {
e.printStackTrace();
Log.e("Fragment_Cost_imme", e.toString());
ToastUtil.showToastShort(getContext(), "请求异常");
}
}
});
}
private Handler mHandler = new Handler() {
@SuppressWarnings("unused")
public void handleMessage(Message msg) {
switch (msg.what) {
case SDK_PAY_FLAG: {
PayResult payResult = new PayResult((Map<String, String>) msg.obj);
//同步通知支付结果。
String resultInfo = payResult.getResult();
String resultStatus = payResult.getResultStatus();
// 判断resultStatus 为9000则代表支付成功
if (TextUtils.equals(resultStatus, "9000")) {
Toast.makeText(getContext(), "支付成功", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getContext(), "支付失败", Toast.LENGTH_SHORT).show();
}
break;
}
}
}
};
- 混淆
-libraryjars libs/alipaySDK-20150602.jar
-keep class com.alipay.android.app.IAlixPay{;}
-keep class com.alipay.android.app.IAlixPay$Stub{;}
-keep class com.alipay.android.app.IRemoteServiceCallback{;}
-keep class com.alipay.android.app.IRemoteServiceCallback$Stub{;}
-keep class com.alipay.sdk.app.PayTask{ public *;}
-keep class com.alipay.sdk.app.AuthTask{ public *;}
- 配置
<activity
android:name="com.alipay.sdk.app.H5PayActivity"
android:configChanges="orientation|keyboardHidden|navigation"
android:exported="false"
android:screenOrientation="behind"></activity>
<activity
android:name="com.alipay.sdk.auth.AuthActivity"
android:configChanges="orientation|keyboardHidden|navigation"
android:exported="false"
android:screenOrientation="behind"></activity>
- 权限
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
- gradle
compile files('libs/alipaySingle-20170510.jar')
网友评论