#392 微信支付增加企业付款到银行卡的相关接口

This commit is contained in:
Binary Wang 2017-12-21 23:49:57 +08:00
parent 34a974bc28
commit 0240fffa1c
10 changed files with 178 additions and 14 deletions

View File

@ -0,0 +1,28 @@
package com.github.binarywang.wxpay.bean.entpay;
import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.*;
import me.chanjar.weixin.common.annotation.Required;
import me.chanjar.weixin.common.util.ToStringUtils;
/**
* <pre>
* 企业付款到银行卡的请求对象
* Created by Binary Wang on 2017/12/21.
* </pre>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@XStreamAlias("xml")
public class EntPayBankQueryRequest extends EntPayQueryRequest {
private static final long serialVersionUID = -479088843124447119L;
@Override
protected boolean ignoreAppid() {
return true;
}
}

View File

@ -0,0 +1,96 @@
package com.github.binarywang.wxpay.bean.entpay;
import com.github.binarywang.wxpay.bean.result.BaseWxPayResult;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
/**
* <pre>
* 企业付款到银行卡查询返回结果.
* Created by Binary Wang on 2017/12/21.
* </pre>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@XStreamAlias("xml")
public class EntPayBankQueryResult extends BaseWxPayResult {
private static final long serialVersionUID = -8336631015989500746L;
/**
* 商户企业付款单号
*/
@XStreamAlias("partner_trade_no")
private String partnerTradeNo;
/**
* 微信企业付款单号.
* 即为微信内部业务单号
*/
@XStreamAlias("payment_no")
private String paymentNo;
/**
* 银行卡号.
* 收款用户银行卡号(MD5加密)
*/
@XStreamAlias("bank_no_md5")
private String bankNoMd5;
/**
* 用户真实姓名.
* 收款人真实姓名MD5加密
*/
@XStreamAlias("true_name_md5")
private String trueNameMd5;
/**
* 付款金额.
*/
@XStreamAlias("amount")
private Integer amount;
/**
* 代付单状态.
* <pre>
* PROCESSING处理中如有明确失败则返回额外失败原因否则没有错误原因
* SUCCESS付款成功
* FAILED付款失败
* BANK_FAIL银行退票订单状态由付款成功流转至退票,退票时付款金额和手续费会自动退还
* </pre>
*/
@XStreamAlias("status")
private String status;
/**
* 手续费金额
*/
@XStreamAlias("cmms_amt")
private Integer cmmsAmount;
/**
* 商户下单时间.
* 微信侧订单创建时间
*/
@XStreamAlias("create_time")
private String createTime;
/**
* 成功付款时间.
* 微信侧付款成功时间但无法保证银行不会退票
*/
@XStreamAlias("pay_succ_time")
private String paySuccessTime;
/**
* 失败原因.
* 订单失败原因余额不足
*/
@XStreamAlias("reason")
private String failReason;
}

View File

@ -8,7 +8,7 @@ import lombok.NoArgsConstructor;
/**
* <pre>
* 企业付款到银行卡的响应结果
* 企业付款到银行卡的响应结果.
* Created by Binary Wang on 2017/12/21.
* </pre>
*
@ -19,6 +19,8 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
@XStreamAlias("xml")
public class EntPayBankResult extends BaseWxPayResult {
private static final long serialVersionUID = 3449707749935227689L;
/**
* 代付金额.
*/

View File

@ -8,7 +8,7 @@ import me.chanjar.weixin.common.util.ToStringUtils;
/**
* <pre>
* 企业付款请求对象
* 企业付款请求对象.
* Created by Binary Wang on 2016/10/19.
* </pre>
*
@ -21,6 +21,8 @@ import me.chanjar.weixin.common.util.ToStringUtils;
@AllArgsConstructor
@XStreamAlias("xml")
public class EntPayQueryRequest extends BaseWxPayRequest {
private static final long serialVersionUID = 1972288742207813985L;
/**
* <pre>
* 字段名商户订单号.

View File

@ -19,6 +19,7 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
@XStreamAlias("xml")
public class EntPayQueryResult extends BaseWxPayResult {
private static final long serialVersionUID = 3948485732447456947L;
/**
* 商户订单号

View File

@ -12,20 +12,23 @@ import me.chanjar.weixin.common.util.ToStringUtils;
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
import org.apache.commons.lang3.StringUtils;
import java.io.Serializable;
import java.math.BigDecimal;
import static com.github.binarywang.wxpay.constant.WxPayConstants.SignType.ALL_SIGN_TYPES;
/**
* <pre>
* Created by Binary Wang on 2016-10-24.
* 微信支付请求对象共用的参数存放类
* Created by Binary Wang on 2016-10-24.
* </pre>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@Data
public abstract class BaseWxPayRequest {
public abstract class BaseWxPayRequest implements Serializable {
private static final long serialVersionUID = -4766915659779847060L;
/**
* <pre>
* 字段名公众账号ID
@ -117,7 +120,7 @@ public abstract class BaseWxPayRequest {
*
* @param yuan 将要转换的元的数值字符串
*/
public static Integer yuanToFee(String yuan) {
public static Integer yuanToFen(String yuan) {
return new BigDecimal(yuan).setScale(2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).intValue();
}

View File

@ -2,7 +2,6 @@ package com.github.binarywang.wxpay.bean.result;
import com.github.binarywang.wxpay.exception.WxPayException;
import com.github.binarywang.wxpay.service.WxPayService;
import com.github.binarywang.wxpay.service.impl.BaseWxPayServiceImpl;
import com.github.binarywang.wxpay.util.SignUtils;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
@ -26,20 +25,23 @@ import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
/**
* <pre>
* 微信支付结果共用属性类
* 微信支付结果共用属性类.
* Created by Binary Wang on 2016-10-24.
* </pre>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
*/
@Data
public abstract class BaseWxPayResult {
public abstract class BaseWxPayResult implements Serializable {
private static final long serialVersionUID = 2416778827989487412L;
/**
* 返回状态码
*/

View File

@ -68,5 +68,17 @@ public interface EntPayService {
*
* @param request 请求对象
*/
EntPayBankResult payToBankCard(EntPayBankRequest request) throws WxPayException;
EntPayBankResult payBank(EntPayBankRequest request) throws WxPayException;
/**
* 企业付款到银行卡查询.
* <pre>
* 用于对商户企业付款到银行卡操作进行结果查询返回付款操作详细结果
* 文档详见https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=24_3
* 接口链接https://api.mch.weixin.qq.com/mmpaysptrans/query_bank
* </pre>
*
* @param partnerTradeNo 商户订单号
*/
EntPayBankQueryResult queryPayBank(String partnerTradeNo) throws WxPayException;
}

View File

@ -75,7 +75,7 @@ public class EntPayServiceImpl implements EntPayService {
}
@Override
public EntPayBankResult payToBankCard(EntPayBankRequest request) throws WxPayException {
public EntPayBankResult payBank(EntPayBankRequest request) throws WxPayException {
File publicKeyFile = this.buildPublicKeyFile();
request.setEncBankNo(this.encryptRSA(publicKeyFile, request.getEncBankNo()));
request.setEncTrueName(this.encryptRSA(publicKeyFile, request.getEncTrueName()));
@ -90,6 +90,19 @@ public class EntPayServiceImpl implements EntPayService {
return result;
}
@Override
public EntPayBankQueryResult queryPayBank(String partnerTradeNo) throws WxPayException {
EntPayBankQueryRequest request = new EntPayBankQueryRequest();
request.setPartnerTradeNo(partnerTradeNo);
request.checkAndSign(this.payService.getConfig());
String url = this.payService.getPayBaseUrl() + "/mmpaysptrans/query_bank";
String responseContent = this.payService.post(url, request.toXML(), true);
EntPayBankQueryResult result = BaseWxPayResult.fromXML(responseContent, EntPayBankQueryResult.class);
result.checkResult(this.payService, request.getSignType(), true);
return result;
}
private String encryptRSA(File publicKeyFile, String srcString) throws WxPayException {
try {
Security.addProvider(new BouncyCastleProvider());

View File

@ -1,8 +1,8 @@
package com.github.binarywang.wxpay.service.impl;
import com.github.binarywang.wxpay.bean.entpay.EntPayRequest;
import com.github.binarywang.wxpay.bean.entpay.EntPayBankRequest;
import com.github.binarywang.wxpay.bean.entpay.EntPayBankResult;
import com.github.binarywang.wxpay.bean.entpay.EntPayRequest;
import com.github.binarywang.wxpay.bean.request.WxEntPayRequest;
import com.github.binarywang.wxpay.constant.WxPayConstants;
import com.github.binarywang.wxpay.exception.WxPayException;
@ -16,7 +16,7 @@ import org.testng.annotations.Test;
/**
* <pre>
* 企业付款测试类
* 企业付款测试类.
* Created by BinaryWang on 2017/12/19.
* </pre>
*
@ -72,8 +72,8 @@ public class EntPayServiceImplTest {
}
@Test
public void testPayToBankCard() throws Exception {
EntPayBankResult result = this.payService.getEntPayService().payToBankCard(EntPayBankRequest.builder()
public void testPayBank() throws Exception {
EntPayBankResult result = this.payService.getEntPayService().payBank(EntPayBankRequest.builder()
.bankCode("aa")
.amount(1)
.encBankNo("1")
@ -83,4 +83,9 @@ public class EntPayServiceImplTest {
.build());
this.logger.info(result.toString());
}
@Test
public void testQueryPayBank() throws Exception {
this.logger.info(this.payService.getEntPayService().queryPayBank("123").toString());
}
}