增加微信小程序支付(草莓的逻辑)
This commit is contained in:
@@ -7,6 +7,7 @@ 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.ChargeBean;
|
||||
import com.yizhuan.xchat_android_core.pay.bean.WalletInfo;
|
||||
import com.yizhuan.xchat_android_core.pay.bean.WxPayType;
|
||||
import com.yizhuan.xchat_android_library.coremanager.IBaseCore;
|
||||
|
||||
import java.util.List;
|
||||
@@ -82,6 +83,8 @@ public interface IPayModel extends IModel {
|
||||
|
||||
Single<String> getSmsBindAli();
|
||||
|
||||
Single<WxPayType> getWxpayType();
|
||||
|
||||
/**
|
||||
* 是否首次充值
|
||||
*/
|
||||
|
@@ -15,6 +15,7 @@ import com.yizhuan.xchat_android_core.manager.IMNetEaseManager;
|
||||
import com.yizhuan.xchat_android_core.manager.RoomEvent;
|
||||
import com.yizhuan.xchat_android_core.pay.bean.ChargeBean;
|
||||
import com.yizhuan.xchat_android_core.pay.bean.WalletInfo;
|
||||
import com.yizhuan.xchat_android_core.pay.bean.WxPayType;
|
||||
import com.yizhuan.xchat_android_core.pay.event.ChargeCustomNotificationEvent;
|
||||
import com.yizhuan.xchat_android_core.pay.event.FirstRechargeEvent;
|
||||
import com.yizhuan.xchat_android_core.pay.event.GetWalletInfoEvent;
|
||||
@@ -345,6 +346,13 @@ public class PayModel extends BaseModel implements IPayModel {
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public Single<WxPayType> getWxpayType() {
|
||||
return api.getWxpayType()
|
||||
.compose(RxHelper.handleBeanData())
|
||||
.compose(RxHelper.handleSchedulers());
|
||||
}
|
||||
|
||||
/**
|
||||
* 主要是为了兼容旧版的walletInfo
|
||||
*
|
||||
@@ -513,6 +521,14 @@ public class PayModel extends BaseModel implements IPayModel {
|
||||
*/
|
||||
@GET("/chargeRecord/isFirstCharge")
|
||||
Single<ServiceResult<Boolean>> apiIsFirstCharge();
|
||||
|
||||
/**
|
||||
* 获取微信支付方式
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GET("/charge/v2/wxpay/type")
|
||||
Single<ServiceResult<WxPayType>> getWxpayType();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,33 @@
|
||||
package com.yizhuan.xchat_android_core.pay.bean;
|
||||
|
||||
public class WxPayType {
|
||||
private String wxPayType;
|
||||
//微信小程序对应的appId
|
||||
private String wxminiAppid;
|
||||
//微信小程序原始id
|
||||
private String wxminiId;
|
||||
|
||||
public String getWxPayType() {
|
||||
return wxPayType;
|
||||
}
|
||||
|
||||
public void setWxPayType(String wxPayType) {
|
||||
this.wxPayType = wxPayType;
|
||||
}
|
||||
|
||||
public String getWxminiAppid() {
|
||||
return wxminiAppid;
|
||||
}
|
||||
|
||||
public void setWxminiAppid(String wxminiAppid) {
|
||||
this.wxminiAppid = wxminiAppid;
|
||||
}
|
||||
|
||||
public String getWxminiId() {
|
||||
return wxminiId;
|
||||
}
|
||||
|
||||
public void setWxminiId(String wxminiId) {
|
||||
this.wxminiId = wxminiId;
|
||||
}
|
||||
}
|
@@ -15,6 +15,7 @@ import com.tencent.mm.opensdk.modelpay.PayReq;
|
||||
import com.tencent.mm.opensdk.openapi.IWXAPI;
|
||||
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
|
||||
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
|
||||
import com.yizhuan.xchat_android_core.BuildConfig;
|
||||
import com.yizhuan.xchat_android_core.Constants;
|
||||
import com.yizhuan.xchat_android_core.auth.AuthModel;
|
||||
import com.yizhuan.xchat_android_core.bank_card.bean.BankCardBean;
|
||||
@@ -23,6 +24,7 @@ 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.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.unionpay.UnionPayOrder;
|
||||
@@ -99,7 +101,16 @@ public class PaymentActivity extends Activity
|
||||
break;
|
||||
|
||||
case Constants.CHARGE_WX:
|
||||
requestWeChatPay(this, chargeProdId);
|
||||
PayModel.get().getWxpayType()
|
||||
.subscribe(wxPayType -> {
|
||||
if ("APP".equalsIgnoreCase(wxPayType.getWxPayType())) {
|
||||
requestWeChatPay(this, chargeProdId);
|
||||
} else {
|
||||
requestWeChatMiniPay(wxPayType);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
break;
|
||||
|
||||
case Constants.CHARGE_UNION_PAY:
|
||||
@@ -290,6 +301,25 @@ public class PaymentActivity extends Activity
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发起充值(微信小程序支付)
|
||||
*/
|
||||
@SuppressLint("CheckResult")
|
||||
public void requestWeChatMiniPay(WxPayType wxPayType) {
|
||||
//微信小程序支付的微信appid和微信登录&支付的appid是不同的...
|
||||
IWXAPI api = WXAPIFactory.createWXAPI(this, wxPayType.getWxminiAppid());
|
||||
api.handleIntent(getIntent(), this);
|
||||
WXLaunchMiniProgram.Req req = new WXLaunchMiniProgram.Req();
|
||||
req.userName = wxPayType.getWxminiId(); // 填小程序原始id
|
||||
//拉起小程序页面的可带参路径,不填默认拉起小程序首页,对于小游戏,可以只传入 query 部分,来实现传参效果,如:传入 "?foo=bar"。
|
||||
req.path = "pages/index/index?ticket=" + AuthModel.get().getTicket() + "&chargeProductId=" + chargeProdId + "&uid=" + AuthModel.get().getCurrentUid();
|
||||
req.miniprogramType = BuildConfig.DEBUG ? WXLaunchMiniProgram.Req.MINIPROGRAM_TYPE_TEST : WXLaunchMiniProgram.Req.MINIPTOGRAM_TYPE_RELEASE;// 可选打开 开发版,体验版和正式版
|
||||
api.sendReq(req);
|
||||
finish();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发起充值(支付宝支付)
|
||||
*
|
||||
|
Reference in New Issue
Block a user