This commit is contained in:
Kit 2020-06-04 20:35:31 +08:00
parent 9bb9918421
commit e83c62824b
16 changed files with 371 additions and 166 deletions

View File

@ -0,0 +1,246 @@
package com.foxinmy.weixin4j.pay;
import com.alibaba.fastjson.JSON;
import com.foxinmy.weixin4j.pay.payment.mch.MchPayPackage;
import com.foxinmy.weixin4j.pay.payment.mch.SceneInfo;
import com.foxinmy.weixin4j.pay.payment.mch.SceneInfoApp;
import com.foxinmy.weixin4j.pay.payment.mch.SceneInfoStore;
import com.foxinmy.weixin4j.pay.type.TradeType;
import java.util.Date;
/**
* MchPayPackage生成器
*
* 微信支付中很多新增的支付产品或功能不定期的在原来各种支付API中添加参数项导致MchPayPackage类会不断更新
* MchPayPackage构造方法参数会越来越多不断增加的参数项也不好继续改构造方法
* PayApi中一些特定的支付api如JSAPIMACROPAY等都是直接传入参数然后在API内构造MchPayPackage而不是传入MchPayPackage
* 一旦增加新参数就需要改API影响正在使用SDK的工程但如果改为直接使用MchPayPackag的createPayRequest方法
* MchPayPackage的构造方式又太难看开发者需要对着微信文档然后看着构造函数里边一大堆的参数一一匹配
* 所以最终有了PayPackageBuilder这个类通过一些链式的API构造MchPayPackage既提供最小参数的各种支付构造方法又能让代码看上去直观一些
*
* @author kit (kit.li@qq.com)
* @date 2020年06月02日
*/
public class PayPackageBuilder {
private static final String Y = "Y";
private MchPayPackage mchPayPackage;
private PayPackageBuilder(){
}
/**
* 使用MchPayPackage初始化
*
* @param payPackage
* @return
*/
public static PayPackageBuilder init(MchPayPackage payPackage){
PayPackageBuilder instance = new PayPackageBuilder();
instance.mchPayPackage = payPackage;
return instance;
}
/**
* 付款码支付/人脸支付
*
* @param body
* 商品描述
* @param outTradeNo
* 商户订单号
* @param totalFee
* 支付金额
* @param createIp
* 终端IP
* @param authCode
* 用户付款码
* @return
*/
public static PayPackageBuilder microPay(String body, String outTradeNo, double totalFee, String createIp,
String authCode){
PayPackageBuilder instance = new PayPackageBuilder();
instance.mchPayPackage = new MchPayPackage(body, outTradeNo, totalFee, null, createIp, TradeType.MICROPAY,
null, authCode, null, null);
return instance;
}
/**
* JSAPI支付/小程序支付
*
* @param body
* 商品描述
* @param outTradeNo
* 商户订单号
* @param totalFee
* 支付金额
* @param createIp
* 终端IP
* @param notifyUrl
* 回调通知地址
* @param openid
* 用户标识
* @return
*/
public static PayPackageBuilder jsapiPay(String body, String outTradeNo, double totalFee, String createIp,
String notifyUrl, String openid){
PayPackageBuilder instance = new PayPackageBuilder();
instance.mchPayPackage = new MchPayPackage(body, outTradeNo, totalFee, notifyUrl, createIp, TradeType.JSAPI,
openid, null, null, null);
return instance;
}
/**
* native支付
*
* @param body
* 商品描述
* @param outTradeNo
* 商户订单号
* @param totalFee
* 支付金额
* @param createIp
* 终端IP
* @param notifyUrl
* 回调通知地址
* @param productId
* 产品ID
* @return
*/
public static PayPackageBuilder nativePay(String body, String outTradeNo, double totalFee, String createIp,
String notifyUrl, String productId){
PayPackageBuilder instance = new PayPackageBuilder();
instance.mchPayPackage = new MchPayPackage(body, outTradeNo, totalFee, notifyUrl, createIp, TradeType.NATIVE,
null, null, productId, null);
return instance;
}
/**
* APP支付
*
* @param body
* 商品描述
* @param outTradeNo
* 商户订单号
* @param totalFee
* 支付金额
* @param createIp
* 终端IP
* @param notifyUrl
* 回调通知地址
* @return
*/
public static PayPackageBuilder appPay(String body, String outTradeNo, double totalFee, String createIp, String notifyUrl){
PayPackageBuilder instance = new PayPackageBuilder();
instance.mchPayPackage = new MchPayPackage(body, outTradeNo, totalFee, notifyUrl, createIp, TradeType.APP,
null, null, null, null);
return instance;
}
/**
* H5支付
*
* @param body
* 商品描述
* @param outTradeNo
* 商户订单号
* @param totalFee
* 支付金额
* @param createIp
* 终端IP
* @param notifyUrl
* 回调通知地址
* @param wapUrl
* wap网站URL地址
* @param wapName
* wap网站名
* @return
*/
public static PayPackageBuilder h5Pay(String body, String outTradeNo, double totalFee, String createIp,
String notifyUrl, String wapUrl, String wapName){
PayPackageBuilder instance = new PayPackageBuilder();
instance.mchPayPackage = new MchPayPackage(body, outTradeNo, totalFee, notifyUrl, createIp, TradeType.APP,
null, null, null, null);
SceneInfoApp app = SceneInfoApp.createWapAPP(wapName, wapUrl);
instance.mchPayPackage.setSceneInfo(String.format("{\"h5_info\":\"%s\"}", app.getSceneInfo()));
return instance;
}
public PayPackageBuilder detail(String detail){
this.mchPayPackage.setDetail(detail);
return this;
}
public PayPackageBuilder attach(String attach){
this.mchPayPackage.setAttach(attach);
return this;
}
public PayPackageBuilder goodsTag(String goodsTag){
this.mchPayPackage.setGoodsTag(goodsTag);
return this;
}
public PayPackageBuilder limitPay(){
this.mchPayPackage.setLimitPay("no_credit");
return this;
}
public PayPackageBuilder timeStart(Date date){
this.mchPayPackage.setTimeStart(date);
return this;
}
public PayPackageBuilder timeStart(String date){
this.mchPayPackage.setTimeStart(date);
return this;
}
public PayPackageBuilder timeExpire(Date date){
this.mchPayPackage.setTimeExpire(date);
return this;
}
public PayPackageBuilder timeExpire(String date){
this.mchPayPackage.setTimeExpire(date);
return this;
}
public PayPackageBuilder receipt(){
this.mchPayPackage.setReceipt(Y);
return this;
}
public PayPackageBuilder sceneInfo(SceneInfo info){
this.mchPayPackage.setSceneInfo(info.toJson());
return this;
}
public PayPackageBuilder deposit(){
this.mchPayPackage.setDeposit(Y);
return this;
}
public PayPackageBuilder profitSharing(){
this.mchPayPackage.setProfitSharing(Y);
return this;
}
public PayPackageBuilder subOpenId(String subOpenId){
this.mchPayPackage.setSubOpenId(subOpenId);
return this;
}
public PayPackageBuilder totalFee(double totalFee){
this.mchPayPackage.setTotalFee(totalFee);
return this;
}
public PayPackageBuilder totalFee(int totalFee){
this.mchPayPackage.setTotalFee(totalFee);
return this;
}
public MchPayPackage build(){
return this.mchPayPackage;
}
}

View File

@ -279,7 +279,7 @@ public class WeixinPayProxy {
* @param attach
* 附加数据 非必填
* @param store
* 门店信息 非必填
* APP支付已无门店信息不需要再传
* @return APP支付对象
* @see PayApi
* @see SceneInfoStore
@ -366,41 +366,9 @@ public class WeixinPayProxy {
totalFee, createIp, attach, store);
}
/**
* 旧版刷脸支付接口
*
* @param faceCode
* 人脸凭证
* @param body
* 商品或支付单简要描述格式要求门店品牌名-城市分店名-实际商品名称
* @param outTradeNo
* 商户系统内部的订单号,32个字符内可包含字母更换授权码必须要换新的商户订单号
* @param totalFee
* 订单总金额单位元
* @param createIp
* 调用微信支付API的机器IP
* @param openId
* 用户在商户appid 下的唯一标识
* @param attach
* 附加数据在查询API和支付通知中原样返回该字段主要用于商户携带订单的自定义数据
* @return
* @throws WeixinException
* @see <a href=
* "https://pay.weixin.qq.com/wiki/doc/wxfacepay/develop/backend.html#刷脸支付后端接口">
* 刷脸支付后端接口</a>
* @see <a href=
* "https://pay.weixin.qq.com/wiki/doc/wxfacepay/develop/sdk-android.html#人脸支付凭证-getwxpayfacecode"
* 获取人脸支付凭证</a>
*/
public MchPayRequest createFacePayRequest(String faceCode, String body,
String outTradeNo, double totalFee, String createIp, String openId,
String attach) throws WeixinException {
return payApi.createFacePayRequest(faceCode, body, outTradeNo,
totalFee, createIp, openId, attach);
}
/**
* 押金支付请求
* 注意此功能微信已下架改为邀请开通因此暂未使用
*
* @param code
* 授权码/人脸凭证

View File

@ -35,7 +35,7 @@ public class MchApi extends BaseApi {
private final static String PEM_CERT_PREFIX = "-----BEGIN CERTIFICATE-----";
static {
WEIXIN_BUNDLE = ResourceBundle.getBundle("com/foxinmy/weixin4j/payment/weixin");
WEIXIN_BUNDLE = ResourceBundle.getBundle("com/foxinmy/weixin4j/pay/weixin");
}
protected final WeixinPayAccount weixinAccount;

View File

@ -33,6 +33,8 @@ import java.util.Map;
*/
public class PayApi extends MchApi {
private final static String Y = "Y";
public PayApi(WeixinPayAccount weixinAccount) {
super(weixinAccount);
}
@ -87,14 +89,14 @@ public class PayApi extends MchApi {
null, payPackage.getCreateIp(), null, payPackage.getOpenId(),
payPackage.getAuthCode(), null, payPackage.getAttach(),
null, null, payPackage.getGoodsTag(),
payPackage.getLimitPay(), payPackage.getSubAppId(), payPackage.getFaceCode(),
payPackage.getLimitPay(), payPackage.getSubAppId(), payPackage.getReceipt(),
payPackage.getDeposit(), payPackage.getProfitSharing());
// 默认为MD5签名
SignType signType= SignType.MD5;
super.declareMerchant(_payPackage);
// 默认为刷卡支付付款码支付的API地址
String url = getRequestUri("micropay_uri");
if(payPackage.getDeposit()==YesNoType.Y){
if(Y.equals(payPackage.getDeposit())){
// 押金支付只支持HMAC-SHA256签名
signType = SignType.HMAC$SHA256;
_payPackage.setSignType("HMAC-SHA256");
@ -275,7 +277,7 @@ public class PayApi extends MchApi {
* @param attach
* 附加数据 非必填
* @param store
* 门店信息 非必填
* APP支付已无门店信息不需要再传
* @return APP支付对象
* @see SceneInfoStore
* @see APPPayRequest
@ -290,11 +292,6 @@ public class PayApi extends MchApi {
MchPayPackage payPackage = new MchPayPackage(body, outTradeNo,
totalFee, notifyUrl, createIp, TradeType.APP, null, null, null,
attach);
if (store != null) {
payPackage.setSceneInfo(String.format(
"{\"store_id\": \"%s\", \"store_name\":\"%s\"}",
store.getId(), store.getName()));
}
return createPayRequest(payPackage);
}
@ -331,8 +328,7 @@ public class PayApi extends MchApi {
totalFee, notifyUrl, createIp, TradeType.MWEB, null, null,
null, attach);
if (app != null) {
payPackage.setSceneInfo(String.format("{\"h5_info\":\"%s\"}",
app.getSceneInfo()));
payPackage.setSceneInfo(app.toJson());
}
return createPayRequest(payPackage);
}
@ -370,8 +366,7 @@ public class PayApi extends MchApi {
totalFee, null, createIp, TradeType.MICROPAY, null, authCode,
null, attach);
if (store != null) {
payPackage.setSceneInfo(String.format("{\"store_info\":\"%s\"}",
JSON.toJSONString(store)));
payPackage.setSceneInfo(store.toJson());
}
return createPayRequest(payPackage);
}
@ -767,29 +762,6 @@ public class PayApi extends MchApi {
return response.getAsObject(new TypeReference<PayfaceAuthinfo>() {});
}
/**
* 微信旧版刷脸支付
*
* @param faceCode
* @param body
* @param outTradeNo
* @param totalFee
* @param createIp
* @param openId
* @param attach
* @return
* @throws WeixinException
*/
public MchPayRequest createFacePayRequest(String faceCode, String body,
String outTradeNo, double totalFee, String createIp, String openId,
String attach) throws WeixinException {
MchPayPackage payPackage = new MchPayPackage(body, outTradeNo,
totalFee, null, createIp, TradeType.FACEPAY, openId, null,
null, attach);
payPackage.setFaceCode(faceCode);
return createPayRequest(payPackage);
}
/**
* 创建押金支付
*
@ -814,16 +786,15 @@ public class PayApi extends MchApi {
if(isFacePay) {
payPackage = new MchPayPackage(body, outTradeNo, totalFee, null, createIp, TradeType.FACEPAY,
openId, null, null, attach);
payPackage.setFaceCode(code);
payPackage.setDeposit(YesNoType.Y);
payPackage.setAuthCode(code);
payPackage.setDeposit(Y);
return createPayRequest(payPackage);
}else{
payPackage = new MchPayPackage(body, outTradeNo, totalFee, null, createIp, TradeType.MICROPAY,
openId, code, null, attach);
payPackage.setDeposit(YesNoType.Y);
payPackage.setDeposit(Y);
if (store != null) {
payPackage.setSceneInfo(String.format("{\"store_info\":\"%s\"}",
JSON.toJSONString(store)));
payPackage.setSceneInfo(store.toJson());
}
return createPayRequest(payPackage);
}

View File

@ -8,6 +8,7 @@ import com.foxinmy.weixin4j.pay.profitsharing.*;
import com.foxinmy.weixin4j.pay.type.ProfitIdType;
import com.foxinmy.weixin4j.pay.type.SignType;
import com.foxinmy.weixin4j.pay.type.profitsharing.ReturnAccountType;
import com.foxinmy.weixin4j.util.RandomUtil;
import com.foxinmy.weixin4j.xml.XmlStream;
import java.util.List;
@ -109,7 +110,9 @@ public class ProfitSharingApi extends MchApi {
*/
public ProfitSharingResult profitSharingQuery(String transactionId, String outOrderNo) throws WeixinException {
ProfitSharingRequest request = new ProfitSharingRequest(transactionId, outOrderNo, null);
super.declareMerchant(request);
request.setMchId(weixinAccount.getMchId());
request.setNonceStr(RandomUtil.generateString(16));
request.setSubMchId(weixinAccount.getSubMchId());
String url = getRequestUri("profit_sharing_query_uri");
request.setSign(weixinSignature.sign(request, SignType.HMAC$SHA256));
String para = XmlStream.toXML(request);

View File

@ -4,7 +4,6 @@ import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.pay.payment.PayPackage;
import com.foxinmy.weixin4j.pay.type.CurrencyType;
import com.foxinmy.weixin4j.pay.type.TradeType;
import com.foxinmy.weixin4j.pay.type.YesNoType;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
@ -77,18 +76,15 @@ public class MchPayPackage extends PayPackage {
@XmlElement(name = "scene_info")
@JSONField(name = "scene_info")
private String sceneInfo;
/**
* 人脸凭证用于旧版人脸支付
* 电子发票入口开放标识
*/
@XmlElement(name = "face_code")
@JSONField(name = "face_code")
private String faceCode;
private String receipt;
/**
* 是否押金人脸支付Y-,N-普通人脸支付
*/
@XmlElement(name = "deposit")
@JSONField(name = "deposit")
private YesNoType deposit;
private String deposit;
/**
* 是否需要分帐非必传默认为不分帐
@ -96,7 +92,7 @@ public class MchPayPackage extends PayPackage {
*/
@XmlElement(name = "profit_sharing")
@JSONField(name = "profit_sharing")
private YesNoType profitSharing;
private String profitSharing;
protected MchPayPackage() {
// jaxb required
@ -172,9 +168,9 @@ public class MchPayPackage extends PayPackage {
* @param subOpenId
* 用户在子商户appid下的唯一标识 非必填
* openid和sub_openid可以选传其中之一如果选择传sub_openid ,则必须传sub_appid
* @param faceCode
* 人脸凭证用于旧版刷脸支付
* @param depositType
* @param receipt
* 电子发票入口开放标识
* @param deposit
* 是否押金支付
* @param profitSharing
* 是否需要分账
@ -183,20 +179,20 @@ public class MchPayPackage extends PayPackage {
double totalFee, CurrencyType feeType, String notifyUrl,
String createIp, TradeType tradeType, String openId,
String authCode, String productId, String attach, Date timeStart,
Date timeExpire, String goodsTag, String limitPay, String subOpenId, String faceCode,
YesNoType depositType, YesNoType profitSharing) {
Date timeExpire, String goodsTag, String limitPay, String subOpenId, String receipt,
String deposit, String profitSharing) {
super(body, detial, outTradeNo, totalFee, notifyUrl, createIp, attach,
timeStart, timeExpire, goodsTag);
this.tradeType = tradeType != null ? tradeType.name() : null;
this.feeType = feeType == null ? CurrencyType.CNY.name() : feeType
.name();
this.feeType = feeType == null ? CurrencyType.CNY.name() : feeType.name();
this.openId = openId;
this.authCode = authCode;
this.productId = productId;
this.limitPay = limitPay;
this.subOpenId = subOpenId;
this.faceCode = faceCode;
this.deposit = depositType;
this.receipt = receipt;
this.deposit = deposit;
this.profitSharing = profitSharing;
}
public String getTradeType() {
@ -263,27 +259,27 @@ public class MchPayPackage extends PayPackage {
this.sceneInfo = sceneInfo;
}
public String getFaceCode() {
return faceCode;
public String getReceipt() {
return receipt;
}
public void setFaceCode(String faceCode) {
this.faceCode = faceCode;
public void setReceipt(String receipt) {
this.receipt = receipt;
}
public YesNoType getDeposit() {
public String getDeposit() {
return deposit;
}
public void setDeposit(YesNoType deposit) {
public void setDeposit(String deposit) {
this.deposit = deposit;
}
public YesNoType getProfitSharing() {
public String getProfitSharing() {
return profitSharing;
}
public void setProfitSharing(YesNoType profitSharing) {
public void setProfitSharing(String profitSharing) {
this.profitSharing = profitSharing;
}
@ -298,7 +294,7 @@ public class MchPayPackage extends PayPackage {
", limitPay='" + limitPay + '\'' +
", subOpenId='" + subOpenId + '\'' +
", sceneInfo='" + sceneInfo + '\'' +
", faceCode='" + faceCode + '\'' +
", receipt='" + receipt + '\'' +
", deposit=" + deposit +
", profitSharing=" + profitSharing +
'}';

View File

@ -0,0 +1,16 @@
package com.foxinmy.weixin4j.pay.payment.mch;
/**
* 支付场景信息接口
*
* @author kit
* @date 2020年06月03日
*/
public interface SceneInfo {
/**
* 格式化为Json字符串
*
* @return
*/
String toJson();
}

View File

@ -1,24 +1,34 @@
package com.foxinmy.weixin4j.pay.payment.mch;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class SceneInfoApp {
public class SceneInfoApp implements SceneInfo {
/**
* 终端类型
*/
private String type;
/**
* 应用名称
* WAP 网站名
*/
@XmlElement(name = "wap_name")
@JSONField(name = "wap_name")
private String name;
/**
* 应用路径
* WAP网站URL地址
*/
@XmlElement(name = "wap_url")
@JSONField(name = "wap_url")
private String path;
@JSONField(serialize = false)
private String sceneInfo;
protected SceneInfoApp(){
@ -55,21 +65,25 @@ public class SceneInfoApp {
this.path = path;
}
@Deprecated
public String getSceneInfo() {
return sceneInfo;
}
@Deprecated
public void setSceneInfo(String sceneInfo) {
this.sceneInfo = sceneInfo;
}
/**
* IOS应用
* APP环境直接使用APP支付此方法将作废
*
* @param appName 应用名
* @param bundleId 模块ID
* @return
* @deprecated
*/
@Deprecated
public static SceneInfoApp createIOSAPP(String appName, String bundleId) {
SceneInfoApp app = new SceneInfoApp("IOS", appName, bundleId);
String sceneInfo = String
@ -81,11 +95,14 @@ public class SceneInfoApp {
/**
* Android应用
* APP环境直接使用APP支付此方法将作废
*
* @param appName 应用名
* @param packageName 包名
* @return
* @deprecated
*/
@Deprecated
public static SceneInfoApp createAndroidAPP(String appName, String packageName) {
SceneInfoApp app = new SceneInfoApp("Android", appName, packageName);
String sceneInfo = String
@ -112,4 +129,9 @@ public class SceneInfoApp {
app.setSceneInfo(sceneInfo);
return app;
}
@Override
public String toJson() {
return String.format("{\"h5_info\": %s}", JSON.toJSONString(this));
}
}

View File

@ -1,5 +1,6 @@
package com.foxinmy.weixin4j.pay.payment.mch;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import javax.xml.bind.annotation.XmlAccessType;
@ -9,7 +10,7 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class SceneInfoStore {
public class SceneInfoStore implements SceneInfo {
/**
* SZTX001 门店唯一标识
*/
@ -67,9 +68,22 @@ public class SceneInfoStore {
this.name = name;
}
public SceneInfoStore(String id, String name, String areaCode, String address) {
super();
this.id = id;
this.name = name;
this.areaCode = areaCode;
this.address = address;
}
@Override
public String toString() {
return "SceneInfoStore [id=" + id + ", name=" + name + ", areaCode="
+ areaCode + ", address=" + address + "]";
}
@Override
public String toJson() {
return String.format("{\"store_info\": %s}", JSON.toJSONString(this));
}
}

View File

@ -1,5 +1,6 @@
package com.foxinmy.weixin4j.pay.profitsharing;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.pay.payment.mch.MerchantResult;
@ -29,13 +30,13 @@ public class ProfitSharingRequest extends MerchantResult {
/**
* 商户订单号
*/
@XmlElement(name = "out_trade_no")
@JSONField(name = "out_trade_no")
@XmlElement(name = "out_order_no")
@JSONField(name = "out_order_no")
private String outOrderNo;
/**
* 分账接收方列表不超过50个
*/
private List<ReceiverProfit> receivers;
private String receivers;
/**
* 分账完结描述
*/
@ -44,7 +45,7 @@ public class ProfitSharingRequest extends MerchantResult {
public ProfitSharingRequest(String transactionId, String outOrderNo, List<ReceiverProfit> receivers){
this.transactionId = transactionId;
this.outOrderNo = outOrderNo;
this.receivers = receivers;
this.receivers = receivers!=null && receivers.size()>0 ? JSON.toJSONString(receivers) : null;
}
public String getTransactionId() {
@ -63,11 +64,11 @@ public class ProfitSharingRequest extends MerchantResult {
this.outOrderNo = outOrderNo;
}
public List<ReceiverProfit> getReceivers() {
public String getReceivers() {
return receivers;
}
public void setReceivers(List<ReceiverProfit> receivers) {
public void setReceivers(String receivers) {
this.receivers = receivers;
}

View File

@ -1,5 +1,6 @@
package com.foxinmy.weixin4j.pay.profitsharing;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.pay.payment.mch.MerchantResult;
@ -49,7 +50,8 @@ public class ProfitSharingResult extends MerchantResult {
/**
* 分账接收方列表分帐查询
*/
private List<ReceiverProfitResult> receivers;
@JSONField(serialize = false)
private String receivers;
/**
* 分账金额分帐查询
* 分账完结的分账金额单位为分 仅当查询分账完结的执行结果时存在本字段
@ -101,11 +103,11 @@ public class ProfitSharingResult extends MerchantResult {
this.closeReason = closeReason;
}
public List<ReceiverProfitResult> getReceivers() {
public String getReceivers() {
return receivers;
}
public void setReceivers(List<ReceiverProfitResult> receivers) {
public void setReceivers(String receivers) {
this.receivers = receivers;
}
@ -124,4 +126,9 @@ public class ProfitSharingResult extends MerchantResult {
public void setDescription(String description) {
this.description = description;
}
@JSONField(name = "receivers")
public List<ReceiverProfitResult> getProfitResult(){
return JSON.parseArray(this.receivers, ReceiverProfitResult.class);
}
}

View File

@ -13,6 +13,13 @@ public class ReceiverProfit extends Receiver {
private int amount;
private String description;
/**
* json deserialize need
*/
public ReceiverProfit(){
super();
}
public ReceiverProfit(ReceiverType type, String account, int amount, String description){
super(type, account, null);
this.amount = amount;

View File

@ -1,6 +1,7 @@
package com.foxinmy.weixin4j.pay.profitsharing;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.foxinmy.weixin4j.pay.payment.mch.MerchantResult;
/**
@ -15,6 +16,7 @@ public class ReceiverResult extends MerchantResult {
/**
* 分账接收方对象json格式字符串
*/
@JSONField(serialize = false)
private String receiver;
public String getReceiver() {
@ -28,6 +30,7 @@ public class ReceiverResult extends MerchantResult {
/**
* 返回接收方java对象
*/
@JSONField(name = "receiver")
public Receiver getReceiverObject(){
try {
return JSON.parseObject(receiver, Receiver.class);

View File

@ -1,19 +0,0 @@
package com.foxinmy.weixin4j.pay.type;
/**
* 通用的是或否参数
*
* @author kit (kit.li@qq.com)
* @date 2020年05月22日
* @since weixin4j-pay 1.1.0
*/
public enum YesNoType {
/**
*
*/
Y,
/**
*
*/
N
}

View File

@ -1,30 +0,0 @@
package com.foxinmy.weixin4j.pay.test;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.foxinmy.weixin4j.exception.WeixinException;
import com.foxinmy.weixin4j.pay.WeixinPayProxy;
import com.foxinmy.weixin4j.pay.model.WeixinPayAccount;
import com.foxinmy.weixin4j.pay.payment.mch.MchPayRequest;
import org.junit.Test;
public class TestFacePay {
@Test
public void test() throws WeixinException {
String appid = "";
String mchid = "";
String paySignKey = "";
WeixinPayAccount payAccount = new WeixinPayAccount(appid, paySignKey, mchid);
WeixinPayProxy proxy = new WeixinPayProxy(payAccount);
String orderNo = "TESTORDER2019092001";
String openId = "oguJRswolIOGg7Vd1VaqGJuDBFAE";
String faceCode = "0f879a6c-5fff-421c-a233-5fac0f4aad12";
MchPayRequest rsp = proxy.createFacePayRequest(faceCode, "测试的人脸支付",
orderNo, 1,
"127.0.0.1", openId, null);
JSONObject obj = (JSONObject) JSON.toJSON(rsp);
}
}