H5调用原生支付逻辑优化
This commit is contained in:
@@ -5,6 +5,7 @@ import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
@@ -60,8 +61,6 @@ import io.reactivex.Single;
|
||||
public class PaymentActivity extends Activity
|
||||
implements IPaymentView, IWXAPIEventHandler {
|
||||
|
||||
private static final String TAG = "PaymentActivity";
|
||||
|
||||
public static final int REQUEST_CODE_PAY = 1000;
|
||||
public static final String KEY_CHANNEL = "key_channel";
|
||||
public static final String KEY_TAROT_JSON = "key_tarot_json";
|
||||
@@ -69,7 +68,7 @@ public class PaymentActivity extends Activity
|
||||
public static final String KEY_PAY_RESULT = "key_pay_result";
|
||||
public static final String KEY_WANNA_GET_ORDER = "key_wanna_get_order";
|
||||
public static final String KEY_PAYMENT_PASSWORD = "key_payment_passowrd";
|
||||
|
||||
private static final String TAG = "PaymentActivity";
|
||||
private String channel;
|
||||
private String chargeProdId;
|
||||
private boolean wannaGetOrder;
|
||||
@@ -107,7 +106,9 @@ public class PaymentActivity extends Activity
|
||||
if (getIntent() != null) {
|
||||
String tarotJson = getIntent().getStringExtra(KEY_TAROT_JSON);
|
||||
if (!TextUtils.isEmpty(tarotJson)) {
|
||||
requestWeChatPay(tarotJson);
|
||||
//这里不加延迟的话,onResume会关闭这个页面,导致收不到微信支付的回调,会出现一个透明WXPayEntryActivity页面
|
||||
final Handler mHandler = new Handler();
|
||||
mHandler.postDelayed(() -> requestWeChatPay(tarotJson), 500);
|
||||
return;
|
||||
}
|
||||
this.channel = getIntent().getStringExtra(KEY_CHANNEL);
|
||||
@@ -183,12 +184,12 @@ public class PaymentActivity extends Activity
|
||||
api.handleIntent(getIntent(), PaymentActivity.this);
|
||||
if (!api.isWXAppInstalled()) {
|
||||
SingleToastUtil.showToast("未安装微信");
|
||||
finish();
|
||||
normalBack();
|
||||
}
|
||||
boolean isPaySupported = api.getWXAppSupportAPI() >= Build.PAY_SUPPORTED_SDK_INT;
|
||||
if (!isPaySupported) {
|
||||
SingleToastUtil.showToast("不支持的微信版本");
|
||||
finish();
|
||||
normalBack();
|
||||
}
|
||||
// 拉起微信,直接支付
|
||||
PayReq req = new PayReq();
|
||||
@@ -199,8 +200,9 @@ public class PaymentActivity extends Activity
|
||||
req.nonceStr = data.getNonceStr();
|
||||
req.timeStamp = data.getTimestamp();
|
||||
req.sign = data.getSign();
|
||||
api.sendReq(req);
|
||||
finish();
|
||||
if (!api.sendReq(req)) {
|
||||
normalBack();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -487,7 +489,7 @@ public class PaymentActivity extends Activity
|
||||
} else if (baseResp.getType() == ConstantsAPI.COMMAND_LAUNCH_WX_MINIPROGRAM) {
|
||||
back(String.valueOf(baseResp.errCode), baseResp.errStr);
|
||||
} else {
|
||||
finish();
|
||||
normalBack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user