支付宝增加H5支付

This commit is contained in:
huangjian
2021-02-27 15:24:13 +08:00
parent 86d39df0c9
commit 9bf9321ec9
8 changed files with 84 additions and 37 deletions

View File

@@ -155,6 +155,7 @@ import com.yizhuan.xchat_android_core.miniworld.bean.OpenAudioPartyAttachment;
import com.yizhuan.xchat_android_core.patriarch.event.CloseMinRoomEvent;
import com.yizhuan.xchat_android_core.patriarch.event.ImPushMsgPmLimitTimeEvent;
import com.yizhuan.xchat_android_core.patriarch.event.PmDismissAllLimitDialogEvent;
import com.yizhuan.xchat_android_core.pay.bean.ShowCommonWebEvent;
import com.yizhuan.xchat_android_core.public_chat_hall.attachment.AitMeAttachment;
import com.yizhuan.xchat_android_core.recall.bean.CheckLostUserInfo;
import com.yizhuan.xchat_android_core.recall.event.CheckLostUserEvent;
@@ -276,7 +277,7 @@ public class MainActivity extends BaseMvpActivity<IMainView, MainPresenter>
@Override
public void onError(Throwable e) {
onNeedLogin();
toast(e.getMessage());
//toast(e.getMessage());
}
});
@@ -1146,6 +1147,10 @@ public class MainActivity extends BaseMvpActivity<IMainView, MainPresenter>
checkBindPhone();
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onShowCommonWebEvent(ShowCommonWebEvent event) {
CommonWebViewActivity.start(event.getContext(), event.getUrl());
}
@Override
public void onClick(View v) {

View File

@@ -207,6 +207,7 @@ public class CommonWebViewActivity extends BaseActivity implements ShareDialog.O
mHandler.post(mProgressRunnable);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setLoadWithOverviewMode(true);
// 设置 WebView 可以在 HTTPS 通道上加载 HTTP 资源Android 4.4 后的暗坑
// 因为 Android 4.4 后默认不允许在 HTTPS 通道上加载 HTTP 资源
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

View File

@@ -59,7 +59,7 @@ public class Constants {
public static final String CHARGE_WX = "wx";
public static final String CHARGE_ALIPAY = "alipay";
public static final String CHARGE_ALIPAY = "alipay_v2";
public static final String CHARGE_UNION_PAY = "fastpay";
public static final String CHARGE_WX_MP = "wx_mp";

View File

@@ -4,9 +4,10 @@ import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;
import com.alipay.sdk.app.EnvUtils;
import com.alipay.sdk.app.PayTask;
import com.tencent.mm.opensdk.constants.Build;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
@@ -25,9 +26,11 @@ import com.yizhuan.xchat_android_core.exception.NullDataException;
import com.yizhuan.xchat_android_core.pay.bean.NotRealNameYetException;
import com.yizhuan.xchat_android_core.pay.bean.PaymentResult;
import com.yizhuan.xchat_android_core.pay.bean.PmChargeLimitException;
import com.yizhuan.xchat_android_core.pay.bean.ShowCommonWebEvent;
import com.yizhuan.xchat_android_core.pay.bean.WxPayType;
import com.yizhuan.xchat_android_core.pay.bean.alipay.AliPayResponseResult;
import com.yizhuan.xchat_android_core.pay.bean.alipay.AliPayResult;
import com.yizhuan.xchat_android_core.pay.bean.alipay.AlipayInfo;
import com.yizhuan.xchat_android_core.pay.bean.unionpay.UnionPayOrder;
import com.yizhuan.xchat_android_core.pay.bean.wechatpay.WeChatAppParam;
import com.yizhuan.xchat_android_core.pay.model.alipay.AliPayModel;
@@ -38,7 +41,10 @@ import com.yizhuan.xchat_android_core.utils.net.RxHelper;
import com.yizhuan.xchat_android_library.utils.ListUtils;
import com.yizhuan.xchat_android_library.utils.SingleToastUtil;
import org.greenrobot.eventbus.EventBus;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.TimeZone;
@@ -331,6 +337,35 @@ public class PaymentActivity extends Activity
public void requestAliPay(Activity context, String chargeProdId) {
AliPayModel.get()
.requestAliPay(context, chargeProdId)
.flatMap(jsonObjectServiceResult -> {
if (jsonObjectServiceResult == null) return Single.error(new Throwable());
if (jsonObjectServiceResult.isSuccess()) {
AlipayInfo alipayInfo = jsonObjectServiceResult.getData();
if ("native".equals(alipayInfo.getPayType())) {
// 收到订单号之后,发起支付
PayTask alipay = new PayTask(context);
Map<String, String> result = alipay.payV2(alipayInfo.getOrderData(), true);
return Single.just(result);
} else if ("h5".equals(alipayInfo.getPayType())) {
EventBus.getDefault().post(new ShowCommonWebEvent(this,alipayInfo.getOrderData()));
return Single.error(new Throwable());
} else {
return Single.error(new Throwable());
}
} else {
if (jsonObjectServiceResult.getCode() == PayModel.NOT_REAL_NAME_BEFORE_CHARGING) {
return Single.error(new NotRealNameYetException(
jsonObjectServiceResult.getMessage(),
jsonObjectServiceResult.getCode()));
} else if (jsonObjectServiceResult.getCode() == PmChargeLimitException.ERROR_CODE) {
return Single.error(new PmChargeLimitException(
RxHelper.getValidMessage(jsonObjectServiceResult),
jsonObjectServiceResult.getCode()));
} else {
return Single.error(new Throwable(jsonObjectServiceResult.getMessage()));
}
}
})
.subscribe((stringStringMap, throwable) -> {
if (throwable == null) {
AliPayResult aliPayResult = new AliPayResult(stringStringMap);

View File

@@ -0,0 +1,17 @@
package com.yizhuan.xchat_android_core.pay.bean;
import android.content.Context;
import lombok.Data;
@Data
public class ShowCommonWebEvent {
public ShowCommonWebEvent(Context context, String url) {
this.context = context;
this.url = url;
}
private Context context;
private String url;
}

View File

@@ -0,0 +1,10 @@
package com.yizhuan.xchat_android_core.pay.bean.alipay;
import lombok.Data;
@Data
public class AlipayInfo {
private String payType;
private String orderData;
}

View File

@@ -12,6 +12,7 @@ import com.yizhuan.xchat_android_core.exception.NullDataException;
import com.yizhuan.xchat_android_core.pay.PayModel;
import com.yizhuan.xchat_android_core.pay.bean.NotRealNameYetException;
import com.yizhuan.xchat_android_core.pay.bean.PmChargeLimitException;
import com.yizhuan.xchat_android_core.pay.bean.alipay.AlipayInfo;
import com.yizhuan.xchat_android_core.utils.net.RxHelper;
import com.yizhuan.xchat_android_library.net.rxnet.RxNet;
import com.yizhuan.xchat_android_library.utils.LogUtil;
@@ -48,39 +49,15 @@ public class AliPayModel extends BaseModel implements IAliPayModel {
* @return
*/
@Override
public Single<Map<String, String>> requestAliPay(Activity context, String chargeProdId) {
public Single<ServiceResult<AlipayInfo>> requestAliPay(Activity context, String chargeProdId) {
return api.requestAilPayOrder(
String.valueOf(AuthModel.get().getCurrentUid()),
chargeProdId,
Constants.CHARGE_ALIPAY,
NetworkUtils.getIPAddress(context),
AuthModel.get().getTicket()
)
.flatMap(jsonObjectServiceResult -> {
if (jsonObjectServiceResult == null) return Single.error(new Throwable());
if (jsonObjectServiceResult.isSuccess()) {
String data = jsonObjectServiceResult.getData();
if (TextUtils.isEmpty(data)) return Single.error(new NullDataException());
// 收到订单号之后,发起支付
PayTask alipay = new PayTask(context);
Map<String, String> result = alipay.payV2(data, true);
// LogUtil.print(Arrays.toString(result.entrySet().toArray()));
return Single.just(result);
} else {
if (jsonObjectServiceResult.getCode() == PayModel.NOT_REAL_NAME_BEFORE_CHARGING) {
return Single.error(new NotRealNameYetException(
jsonObjectServiceResult.getMessage(),
jsonObjectServiceResult.getCode()));
} else if (jsonObjectServiceResult.getCode() == PmChargeLimitException.ERROR_CODE) {
return Single.error(new PmChargeLimitException(
RxHelper.getValidMessage(jsonObjectServiceResult),
jsonObjectServiceResult.getCode()));
} else {
return Single.error(new Throwable(jsonObjectServiceResult.getMessage()));
}
}
})
AuthModel.get().getTicket())
.compose(RxHelper.handleSchedulers());
}
interface Api {
@@ -95,11 +72,11 @@ public class AliPayModel extends BaseModel implements IAliPayModel {
* @return
*/
@POST("/charge/pay/apply")
Single<ServiceResult<String>> requestAilPayOrder(@Query("uid") String uid,
@Query("chargeProdId") String chargeProdId,
@Query("payChannel") String payChannel,
@Query("clientIp") String clientIp,
@Query("ticket") String ticket);
Single<ServiceResult<AlipayInfo>> requestAilPayOrder(@Query("uid") String uid,
@Query("chargeProdId") String chargeProdId,
@Query("payChannel") String payChannel,
@Query("clientIp") String clientIp,
@Query("ticket") String ticket);
}
}

View File

@@ -3,6 +3,8 @@ package com.yizhuan.xchat_android_core.pay.model.alipay;
import android.app.Activity;
import com.yizhuan.xchat_android_core.base.IModel;
import com.yizhuan.xchat_android_core.bean.response.ServiceResult;
import com.yizhuan.xchat_android_core.pay.bean.alipay.AlipayInfo;
import java.util.Map;
@@ -11,11 +13,11 @@ import io.reactivex.Single;
public interface IAliPayModel extends IModel {
/**
* 支付宝充值,通过此接口获取订单号并发起支付
* 支付宝充值,通过此接口获取订单号
*
* @param context
* @param chargeProdId
* @return
*/
public Single<Map<String, String>> requestAliPay(Activity context, String chargeProdId);
public Single<ServiceResult<AlipayInfo>> requestAliPay(Activity context, String chargeProdId);
}