mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-08-24 16:18:51 +08:00
#392 微信支付增加企业付款到银行卡的相关接口
This commit is contained in:
parent
34a974bc28
commit
0240fffa1c
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
|
||||||
|
}
|
@ -8,7 +8,7 @@ import lombok.NoArgsConstructor;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* 企业付款到银行卡的响应结果
|
* 企业付款到银行卡的响应结果.
|
||||||
* Created by Binary Wang on 2017/12/21.
|
* Created by Binary Wang on 2017/12/21.
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
@ -19,6 +19,8 @@ import lombok.NoArgsConstructor;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@XStreamAlias("xml")
|
@XStreamAlias("xml")
|
||||||
public class EntPayBankResult extends BaseWxPayResult {
|
public class EntPayBankResult extends BaseWxPayResult {
|
||||||
|
private static final long serialVersionUID = 3449707749935227689L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 代付金额.
|
* 代付金额.
|
||||||
*/
|
*/
|
||||||
|
@ -8,7 +8,7 @@ import me.chanjar.weixin.common.util.ToStringUtils;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* 企业付款请求对象
|
* 企业付款请求对象.
|
||||||
* Created by Binary Wang on 2016/10/19.
|
* Created by Binary Wang on 2016/10/19.
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
@ -21,6 +21,8 @@ import me.chanjar.weixin.common.util.ToStringUtils;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@XStreamAlias("xml")
|
@XStreamAlias("xml")
|
||||||
public class EntPayQueryRequest extends BaseWxPayRequest {
|
public class EntPayQueryRequest extends BaseWxPayRequest {
|
||||||
|
private static final long serialVersionUID = 1972288742207813985L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* 字段名:商户订单号.
|
* 字段名:商户订单号.
|
||||||
|
@ -19,6 +19,7 @@ import lombok.NoArgsConstructor;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@XStreamAlias("xml")
|
@XStreamAlias("xml")
|
||||||
public class EntPayQueryResult extends BaseWxPayResult {
|
public class EntPayQueryResult extends BaseWxPayResult {
|
||||||
|
private static final long serialVersionUID = 3948485732447456947L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商户订单号
|
* 商户订单号
|
||||||
|
@ -12,20 +12,23 @@ import me.chanjar.weixin.common.util.ToStringUtils;
|
|||||||
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
|
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
import static com.github.binarywang.wxpay.constant.WxPayConstants.SignType.ALL_SIGN_TYPES;
|
import static com.github.binarywang.wxpay.constant.WxPayConstants.SignType.ALL_SIGN_TYPES;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* Created by Binary Wang on 2016-10-24.
|
|
||||||
* 微信支付请求对象共用的参数存放类
|
* 微信支付请求对象共用的参数存放类
|
||||||
|
* Created by Binary Wang on 2016-10-24.
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public abstract class BaseWxPayRequest {
|
public abstract class BaseWxPayRequest implements Serializable {
|
||||||
|
private static final long serialVersionUID = -4766915659779847060L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* 字段名:公众账号ID
|
* 字段名:公众账号ID
|
||||||
@ -117,7 +120,7 @@ public abstract class BaseWxPayRequest {
|
|||||||
*
|
*
|
||||||
* @param yuan 将要转换的元的数值字符串
|
* @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();
|
return new BigDecimal(yuan).setScale(2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).intValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package com.github.binarywang.wxpay.bean.result;
|
|||||||
|
|
||||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||||
import com.github.binarywang.wxpay.service.WxPayService;
|
import com.github.binarywang.wxpay.service.WxPayService;
|
||||||
import com.github.binarywang.wxpay.service.impl.BaseWxPayServiceImpl;
|
|
||||||
import com.github.binarywang.wxpay.util.SignUtils;
|
import com.github.binarywang.wxpay.util.SignUtils;
|
||||||
import com.google.common.base.Joiner;
|
import com.google.common.base.Joiner;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
@ -26,20 +25,23 @@ import javax.xml.xpath.XPathExpressionException;
|
|||||||
import javax.xml.xpath.XPathFactory;
|
import javax.xml.xpath.XPathFactory;
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.Serializable;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* 微信支付结果共用属性类
|
* 微信支付结果共用属性类.
|
||||||
* Created by Binary Wang on 2016-10-24.
|
* Created by Binary Wang on 2016-10-24.
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public abstract class BaseWxPayResult {
|
public abstract class BaseWxPayResult implements Serializable {
|
||||||
|
private static final long serialVersionUID = 2416778827989487412L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回状态码
|
* 返回状态码
|
||||||
*/
|
*/
|
||||||
|
@ -68,5 +68,17 @@ public interface EntPayService {
|
|||||||
*
|
*
|
||||||
* @param request 请求对象
|
* @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;
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ public class EntPayServiceImpl implements EntPayService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EntPayBankResult payToBankCard(EntPayBankRequest request) throws WxPayException {
|
public EntPayBankResult payBank(EntPayBankRequest request) throws WxPayException {
|
||||||
File publicKeyFile = this.buildPublicKeyFile();
|
File publicKeyFile = this.buildPublicKeyFile();
|
||||||
request.setEncBankNo(this.encryptRSA(publicKeyFile, request.getEncBankNo()));
|
request.setEncBankNo(this.encryptRSA(publicKeyFile, request.getEncBankNo()));
|
||||||
request.setEncTrueName(this.encryptRSA(publicKeyFile, request.getEncTrueName()));
|
request.setEncTrueName(this.encryptRSA(publicKeyFile, request.getEncTrueName()));
|
||||||
@ -90,6 +90,19 @@ public class EntPayServiceImpl implements EntPayService {
|
|||||||
return result;
|
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 {
|
private String encryptRSA(File publicKeyFile, String srcString) throws WxPayException {
|
||||||
try {
|
try {
|
||||||
Security.addProvider(new BouncyCastleProvider());
|
Security.addProvider(new BouncyCastleProvider());
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package com.github.binarywang.wxpay.service.impl;
|
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.EntPayBankRequest;
|
||||||
import com.github.binarywang.wxpay.bean.entpay.EntPayBankResult;
|
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.bean.request.WxEntPayRequest;
|
||||||
import com.github.binarywang.wxpay.constant.WxPayConstants;
|
import com.github.binarywang.wxpay.constant.WxPayConstants;
|
||||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||||
@ -16,7 +16,7 @@ import org.testng.annotations.Test;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* 企业付款测试类
|
* 企业付款测试类.
|
||||||
* Created by BinaryWang on 2017/12/19.
|
* Created by BinaryWang on 2017/12/19.
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
@ -72,8 +72,8 @@ public class EntPayServiceImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPayToBankCard() throws Exception {
|
public void testPayBank() throws Exception {
|
||||||
EntPayBankResult result = this.payService.getEntPayService().payToBankCard(EntPayBankRequest.builder()
|
EntPayBankResult result = this.payService.getEntPayService().payBank(EntPayBankRequest.builder()
|
||||||
.bankCode("aa")
|
.bankCode("aa")
|
||||||
.amount(1)
|
.amount(1)
|
||||||
.encBankNo("1")
|
.encBankNo("1")
|
||||||
@ -83,4 +83,9 @@ public class EntPayServiceImplTest {
|
|||||||
.build());
|
.build());
|
||||||
this.logger.info(result.toString());
|
this.logger.info(result.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testQueryPayBank() throws Exception {
|
||||||
|
this.logger.info(this.payService.getEntPayService().queryPayBank("123").toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user