H5调用原生支付逻辑优化
This commit is contained in:
@@ -589,9 +589,10 @@ public class JSInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
public void openNativeTarotPay(String tarotJson) {
|
public void openNativeTarotPay(String payJson, String url) {
|
||||||
mActivity.runOnUiThread(() -> PaymentActivity.start(mActivity, tarotJson));
|
mActivity.runOnUiThread(() -> {
|
||||||
|
TarotPayWebViewActivity.startForNativePay(mActivity, payJson, url);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,14 +1,17 @@
|
|||||||
package com.nnbc123.app.ui.webview;
|
package com.nnbc123.app.ui.webview;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
|
||||||
import com.netease.nim.uikit.common.util.sys.ScreenUtil;
|
import com.netease.nim.uikit.common.util.sys.ScreenUtil;
|
||||||
import com.nnbc123.app.R;
|
import com.nnbc123.app.R;
|
||||||
|
import com.nnbc123.core.pay.PaymentActivity;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,6 +25,13 @@ public class TarotPayWebViewActivity extends CommonWebViewActivity {
|
|||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void startForNativePay(Context context, String payJson, String url) {
|
||||||
|
Intent intent = new Intent(context, TarotPayWebViewActivity.class);
|
||||||
|
intent.putExtra("url", url);
|
||||||
|
intent.putExtra("payJson", payJson);
|
||||||
|
context.startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -29,6 +39,25 @@ public class TarotPayWebViewActivity extends CommonWebViewActivity {
|
|||||||
getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,ScreenUtil.dip2px(150));
|
getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,ScreenUtil.dip2px(150));
|
||||||
getWindow().setGravity(Gravity.CENTER);
|
getWindow().setGravity(Gravity.CENTER);
|
||||||
layoutTitleBar.setVisibility(View.GONE);
|
layoutTitleBar.setVisibility(View.GONE);
|
||||||
|
String payJson = getIntent().getStringExtra("payJson");
|
||||||
|
if (!TextUtils.isEmpty(payJson)) {
|
||||||
|
requestWeChatPay(payJson);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发起充值(塔罗微信原生支付)
|
||||||
|
*/
|
||||||
|
@SuppressLint("CheckResult")
|
||||||
|
public void requestWeChatPay(String tarotJson) {
|
||||||
|
getDialogManager().showProgressDialog(this);
|
||||||
|
PaymentActivity.start(this, tarotJson);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
||||||
|
super.onActivityResult(requestCode, resultCode, intent);
|
||||||
|
getDialogManager().dismissDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -5,6 +5,7 @@ import android.app.Activity;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@@ -60,8 +61,6 @@ import io.reactivex.Single;
|
|||||||
public class PaymentActivity extends Activity
|
public class PaymentActivity extends Activity
|
||||||
implements IPaymentView, IWXAPIEventHandler {
|
implements IPaymentView, IWXAPIEventHandler {
|
||||||
|
|
||||||
private static final String TAG = "PaymentActivity";
|
|
||||||
|
|
||||||
public static final int REQUEST_CODE_PAY = 1000;
|
public static final int REQUEST_CODE_PAY = 1000;
|
||||||
public static final String KEY_CHANNEL = "key_channel";
|
public static final String KEY_CHANNEL = "key_channel";
|
||||||
public static final String KEY_TAROT_JSON = "key_tarot_json";
|
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_PAY_RESULT = "key_pay_result";
|
||||||
public static final String KEY_WANNA_GET_ORDER = "key_wanna_get_order";
|
public static final String KEY_WANNA_GET_ORDER = "key_wanna_get_order";
|
||||||
public static final String KEY_PAYMENT_PASSWORD = "key_payment_passowrd";
|
public static final String KEY_PAYMENT_PASSWORD = "key_payment_passowrd";
|
||||||
|
private static final String TAG = "PaymentActivity";
|
||||||
private String channel;
|
private String channel;
|
||||||
private String chargeProdId;
|
private String chargeProdId;
|
||||||
private boolean wannaGetOrder;
|
private boolean wannaGetOrder;
|
||||||
@@ -107,7 +106,9 @@ public class PaymentActivity extends Activity
|
|||||||
if (getIntent() != null) {
|
if (getIntent() != null) {
|
||||||
String tarotJson = getIntent().getStringExtra(KEY_TAROT_JSON);
|
String tarotJson = getIntent().getStringExtra(KEY_TAROT_JSON);
|
||||||
if (!TextUtils.isEmpty(tarotJson)) {
|
if (!TextUtils.isEmpty(tarotJson)) {
|
||||||
requestWeChatPay(tarotJson);
|
//这里不加延迟的话,onResume会关闭这个页面,导致收不到微信支付的回调,会出现一个透明WXPayEntryActivity页面
|
||||||
|
final Handler mHandler = new Handler();
|
||||||
|
mHandler.postDelayed(() -> requestWeChatPay(tarotJson), 500);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.channel = getIntent().getStringExtra(KEY_CHANNEL);
|
this.channel = getIntent().getStringExtra(KEY_CHANNEL);
|
||||||
@@ -183,12 +184,12 @@ public class PaymentActivity extends Activity
|
|||||||
api.handleIntent(getIntent(), PaymentActivity.this);
|
api.handleIntent(getIntent(), PaymentActivity.this);
|
||||||
if (!api.isWXAppInstalled()) {
|
if (!api.isWXAppInstalled()) {
|
||||||
SingleToastUtil.showToast("未安装微信");
|
SingleToastUtil.showToast("未安装微信");
|
||||||
finish();
|
normalBack();
|
||||||
}
|
}
|
||||||
boolean isPaySupported = api.getWXAppSupportAPI() >= Build.PAY_SUPPORTED_SDK_INT;
|
boolean isPaySupported = api.getWXAppSupportAPI() >= Build.PAY_SUPPORTED_SDK_INT;
|
||||||
if (!isPaySupported) {
|
if (!isPaySupported) {
|
||||||
SingleToastUtil.showToast("不支持的微信版本");
|
SingleToastUtil.showToast("不支持的微信版本");
|
||||||
finish();
|
normalBack();
|
||||||
}
|
}
|
||||||
// 拉起微信,直接支付
|
// 拉起微信,直接支付
|
||||||
PayReq req = new PayReq();
|
PayReq req = new PayReq();
|
||||||
@@ -199,8 +200,9 @@ public class PaymentActivity extends Activity
|
|||||||
req.nonceStr = data.getNonceStr();
|
req.nonceStr = data.getNonceStr();
|
||||||
req.timeStamp = data.getTimestamp();
|
req.timeStamp = data.getTimestamp();
|
||||||
req.sign = data.getSign();
|
req.sign = data.getSign();
|
||||||
api.sendReq(req);
|
if (!api.sendReq(req)) {
|
||||||
finish();
|
normalBack();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -487,7 +489,7 @@ public class PaymentActivity extends Activity
|
|||||||
} else if (baseResp.getType() == ConstantsAPI.COMMAND_LAUNCH_WX_MINIPROGRAM) {
|
} else if (baseResp.getType() == ConstantsAPI.COMMAND_LAUNCH_WX_MINIPROGRAM) {
|
||||||
back(String.valueOf(baseResp.errCode), baseResp.errStr);
|
back(String.valueOf(baseResp.errCode), baseResp.errStr);
|
||||||
} else {
|
} else {
|
||||||
finish();
|
normalBack();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user