mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-05-06 13:47:47 +08:00
Merge branch 'develop' of https://github.com/wechat-group/weixin-java-tools into develop
This commit is contained in:
commit
e68abe7016
@ -18,6 +18,7 @@ public interface WxMpPayService {
|
|||||||
* 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"
|
* 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"
|
||||||
* 接口地址:https://api.mch.weixin.qq.com/pay/unifiedorder
|
* 接口地址:https://api.mch.weixin.qq.com/pay/unifiedorder
|
||||||
* @throws WxErrorException
|
* @throws WxErrorException
|
||||||
|
* @param request 请求对象
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
WxUnifiedOrderResult unifiedOrder(WxUnifiedOrderRequest request)
|
WxUnifiedOrderResult unifiedOrder(WxUnifiedOrderRequest request)
|
||||||
@ -26,11 +27,10 @@ public interface WxMpPayService {
|
|||||||
/**
|
/**
|
||||||
* 该接口调用“统一下单”接口,并拼装发起支付请求需要的参数
|
* 该接口调用“统一下单”接口,并拼装发起支付请求需要的参数
|
||||||
* 详见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN
|
* 详见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN
|
||||||
*
|
* @param request 请求对象
|
||||||
*/
|
*/
|
||||||
Map<String, String> getPayInfo(WxUnifiedOrderRequest request) throws WxErrorException;
|
Map<String, String> getPayInfo(WxUnifiedOrderRequest request) throws WxErrorException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 该接口提供所有微信支付订单的查询,当支付通知处理异常戒丢失的情冴,商户可以通过该接口查询订单支付状态。
|
* 该接口提供所有微信支付订单的查询,当支付通知处理异常戒丢失的情冴,商户可以通过该接口查询订单支付状态。
|
||||||
* 详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2
|
* 详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_2
|
||||||
@ -53,6 +53,7 @@ public interface WxMpPayService {
|
|||||||
* 详见 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4
|
* 详见 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_4
|
||||||
* 接口链接:https://api.mch.weixin.qq.com/secapi/pay/refund
|
* 接口链接:https://api.mch.weixin.qq.com/secapi/pay/refund
|
||||||
* </pre>
|
* </pre>
|
||||||
|
* @param request 请求对象
|
||||||
* @param keyFile 证书文件对象
|
* @param keyFile 证书文件对象
|
||||||
* @return 退款操作结果
|
* @return 退款操作结果
|
||||||
*/
|
*/
|
||||||
@ -74,6 +75,7 @@ public interface WxMpPayService {
|
|||||||
* 发送普通红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3
|
* 发送普通红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3
|
||||||
* 发送裂变红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5&index=4
|
* 发送裂变红包 https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_5&index=4
|
||||||
* </pre>
|
* </pre>
|
||||||
|
* @param request 请求对象
|
||||||
* @param keyFile 证书文件对象
|
* @param keyFile 证书文件对象
|
||||||
*/
|
*/
|
||||||
WxRedpackResult sendRedpack(WxSendRedpackRequest request, File keyFile) throws WxErrorException;
|
WxRedpackResult sendRedpack(WxSendRedpackRequest request, File keyFile) throws WxErrorException;
|
||||||
@ -86,9 +88,22 @@ public interface WxMpPayService {
|
|||||||
* 注意:与商户微信支付收款资金并非同一账户,需要单独充值。
|
* 注意:与商户微信支付收款资金并非同一账户,需要单独充值。
|
||||||
* 文档详见:https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2
|
* 文档详见:https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_2
|
||||||
* 接口链接:https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers
|
* 接口链接:https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers
|
||||||
* @param keyFile 证书文件对象
|
|
||||||
* </pre>
|
* </pre>
|
||||||
|
* @param request 请求对象
|
||||||
|
* @param keyFile 证书文件对象
|
||||||
*/
|
*/
|
||||||
WxEntPayResult entPay(WxEntPayRequest request, File keyFile) throws WxErrorException;
|
WxEntPayResult entPay(WxEntPayRequest request, File keyFile) throws WxErrorException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* 查询企业付款API
|
||||||
|
* 用于商户的企业付款操作进行结果查询,返回付款操作详细结果。
|
||||||
|
* 文档详见:https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_3
|
||||||
|
* 接口链接:https://api.mch.weixin.qq.com/mmpaymkttransfers/gettransferinfo
|
||||||
|
* </pre>
|
||||||
|
* @param partnerTradeNo 商户订单号
|
||||||
|
* @param keyFile 证书文件对象
|
||||||
|
*/
|
||||||
|
WxEntPayQueryResult queryEntPay(String partnerTradeNo, File keyFile) throws WxErrorException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -369,6 +369,31 @@ public class WxMpPayServiceImpl implements WxMpPayService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WxEntPayQueryResult queryEntPay(String partnerTradeNo, File keyFile) throws WxErrorException {
|
||||||
|
XStream xstream = XStreamInitializer.getInstance();
|
||||||
|
xstream.processAnnotations(WxEntPayQueryRequest.class);
|
||||||
|
xstream.processAnnotations(WxEntPayQueryResult.class);
|
||||||
|
|
||||||
|
WxEntPayQueryRequest request = new WxEntPayQueryRequest();
|
||||||
|
request.setAppid(this.wxMpService.getWxMpConfigStorage().getAppId());
|
||||||
|
request.setMchId(this.wxMpService.getWxMpConfigStorage().getPartnerId());
|
||||||
|
request.setNonceStr(System.currentTimeMillis() + "");
|
||||||
|
|
||||||
|
String sign = this.createSign(xmlBean2Map(request), this.wxMpService.getWxMpConfigStorage().getPartnerKey());
|
||||||
|
request.setSign(sign);
|
||||||
|
|
||||||
|
String url = PAY_BASE_URL + "/mmpaymkttransfers/gettransferinfo";
|
||||||
|
|
||||||
|
String responseContent = this.executeRequestWithKeyFile(url, keyFile, xstream.toXML(request), request.getMchId());
|
||||||
|
WxEntPayQueryResult result = (WxEntPayQueryResult) xstream.fromXML(responseContent);
|
||||||
|
if ("FAIL".equals(result.getResultCode())) {
|
||||||
|
throw new WxErrorException(
|
||||||
|
WxError.newBuilder().setErrorMsg(result.getErrCode() + ":" + result.getErrCodeDes()).build());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private String executeRequestWithKeyFile( String url, File keyFile, String requestStr, String mchId) throws WxErrorException {
|
private String executeRequestWithKeyFile( String url, File keyFile, String requestStr, String mchId) throws WxErrorException {
|
||||||
try (FileInputStream inputStream = new FileInputStream(keyFile)) {
|
try (FileInputStream inputStream = new FileInputStream(keyFile)) {
|
||||||
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
KeyStore keyStore = KeyStore.getInstance("PKCS12");
|
||||||
|
@ -0,0 +1,135 @@
|
|||||||
|
package me.chanjar.weixin.mp.bean.pay;
|
||||||
|
|
||||||
|
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||||
|
import me.chanjar.weixin.common.annotation.Required;
|
||||||
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* 企业付款请求对象
|
||||||
|
* 注释中各行每个字段描述对应如下:
|
||||||
|
* <li>字段名
|
||||||
|
* <li>变量名
|
||||||
|
* <li>是否必填
|
||||||
|
* <li>类型
|
||||||
|
* <li>示例值
|
||||||
|
* <li>描述
|
||||||
|
* </pre>
|
||||||
|
* Created by Binary Wang on 2016/10/19.
|
||||||
|
* @author binarywang (https://github.com/binarywang)
|
||||||
|
*/
|
||||||
|
@XStreamAlias("xml")
|
||||||
|
public class WxEntPayQueryRequest {
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* Appid
|
||||||
|
* appid
|
||||||
|
* 是
|
||||||
|
* wxe062425f740d30d8
|
||||||
|
* String(32)
|
||||||
|
* 商户号的appid
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
@XStreamAlias("appid")
|
||||||
|
private String appid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* 商户号
|
||||||
|
* mch_id
|
||||||
|
* 是
|
||||||
|
* 10000098
|
||||||
|
* String(32)
|
||||||
|
* 微信支付分配的商户号
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
@XStreamAlias("mchid")
|
||||||
|
private String mchId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* 随机字符串
|
||||||
|
* nonce_str
|
||||||
|
* 是
|
||||||
|
* 5K8264ILTKCH16CQ2502SI8ZNMTM67VS
|
||||||
|
* String(32)
|
||||||
|
* 随机字符串,不长于32位
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
@XStreamAlias("nonce_str")
|
||||||
|
private String nonceStr;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* 签名
|
||||||
|
* sign
|
||||||
|
* 是
|
||||||
|
* C380BEC2BFD727A4B6845133519F3AD6
|
||||||
|
* String(32)
|
||||||
|
*签名,详见签名算法
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
@XStreamAlias("sign")
|
||||||
|
private String sign;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* 商户订单号
|
||||||
|
* partner_trade_no
|
||||||
|
* 是
|
||||||
|
* 10000098201411111234567890
|
||||||
|
* String
|
||||||
|
* 商户订单号
|
||||||
|
* </pre>
|
||||||
|
*/
|
||||||
|
@Required
|
||||||
|
@XStreamAlias("partner_trade_no")
|
||||||
|
private String partnerTradeNo;
|
||||||
|
|
||||||
|
public String getAppid() {
|
||||||
|
return appid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAppid(String appid) {
|
||||||
|
this.appid = appid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMchId() {
|
||||||
|
return mchId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMchId(String mchId) {
|
||||||
|
this.mchId = mchId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNonceStr() {
|
||||||
|
return nonceStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNonceStr(String nonceStr) {
|
||||||
|
this.nonceStr = nonceStr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSign() {
|
||||||
|
return sign;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSign(String sign) {
|
||||||
|
this.sign = sign;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPartnerTradeNo() {
|
||||||
|
return partnerTradeNo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPartnerTradeNo(String partnerTradeNo) {
|
||||||
|
this.partnerTradeNo = partnerTradeNo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,230 @@
|
|||||||
|
package me.chanjar.weixin.mp.bean.pay;
|
||||||
|
|
||||||
|
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||||
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 企业付款查询返回结果
|
||||||
|
* Created by Binary Wang on 2016/10/19.
|
||||||
|
* @author binarywang (https://github.com/binarywang)
|
||||||
|
*/
|
||||||
|
@XStreamAlias("xml")
|
||||||
|
public class WxEntPayQueryResult {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回状态码
|
||||||
|
*/
|
||||||
|
@XStreamAlias("return_code")
|
||||||
|
private String returnCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回信息
|
||||||
|
*/
|
||||||
|
@XStreamAlias("return_msg")
|
||||||
|
private String returnMsg;
|
||||||
|
|
||||||
|
//############以下字段在return_code为SUCCESS的时候有返回
|
||||||
|
/**
|
||||||
|
* 业务结果
|
||||||
|
*/
|
||||||
|
@XStreamAlias("result_code")
|
||||||
|
private String resultCode;
|
||||||
|
/**
|
||||||
|
* 错误代码
|
||||||
|
*/
|
||||||
|
@XStreamAlias("err_code")
|
||||||
|
private String errCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 错误代码描述
|
||||||
|
*/
|
||||||
|
@XStreamAlias("err_code_des")
|
||||||
|
private String errCodeDes;
|
||||||
|
|
||||||
|
//############以下字段在return_code 和result_code都为SUCCESS的时候有返回##############
|
||||||
|
/**
|
||||||
|
* 商户订单号
|
||||||
|
*/
|
||||||
|
@XStreamAlias("partner_trade_no")
|
||||||
|
private String partnerTradeNo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商户号
|
||||||
|
*/
|
||||||
|
@XStreamAlias("mchid")
|
||||||
|
private String mchId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 付款单号
|
||||||
|
*/
|
||||||
|
@XStreamAlias("detail_id")
|
||||||
|
private String detailId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转账状态
|
||||||
|
*/
|
||||||
|
@XStreamAlias("status")
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 失败原因
|
||||||
|
*/
|
||||||
|
@XStreamAlias("reason")
|
||||||
|
private String reason;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 收款用户openid
|
||||||
|
*/
|
||||||
|
@XStreamAlias("openid")
|
||||||
|
private String openid;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 收款用户姓名
|
||||||
|
*/
|
||||||
|
@XStreamAlias("transfer_name")
|
||||||
|
private String transferName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 付款金额
|
||||||
|
*/
|
||||||
|
@XStreamAlias("payment_amount")
|
||||||
|
private Integer paymentAmount;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转账时间
|
||||||
|
*/
|
||||||
|
@XStreamAlias("transfer_time")
|
||||||
|
private String transferTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 付款描述
|
||||||
|
*/
|
||||||
|
@XStreamAlias("desc")
|
||||||
|
private String desc;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getReturnCode() {
|
||||||
|
return returnCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReturnCode(String returnCode) {
|
||||||
|
this.returnCode = returnCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getReturnMsg() {
|
||||||
|
return returnMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReturnMsg(String returnMsg) {
|
||||||
|
this.returnMsg = returnMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getResultCode() {
|
||||||
|
return resultCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResultCode(String resultCode) {
|
||||||
|
this.resultCode = resultCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getErrCode() {
|
||||||
|
return errCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setErrCode(String errCode) {
|
||||||
|
this.errCode = errCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getErrCodeDes() {
|
||||||
|
return errCodeDes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setErrCodeDes(String errCodeDes) {
|
||||||
|
this.errCodeDes = errCodeDes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPartnerTradeNo() {
|
||||||
|
return partnerTradeNo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPartnerTradeNo(String partnerTradeNo) {
|
||||||
|
this.partnerTradeNo = partnerTradeNo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMchId() {
|
||||||
|
return mchId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMchId(String mchId) {
|
||||||
|
this.mchId = mchId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDetailId() {
|
||||||
|
return detailId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDetailId(String detailId) {
|
||||||
|
this.detailId = detailId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(String status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getReason() {
|
||||||
|
return reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReason(String reason) {
|
||||||
|
this.reason = reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOpenid() {
|
||||||
|
return openid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOpenid(String openid) {
|
||||||
|
this.openid = openid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTransferName() {
|
||||||
|
return transferName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTransferName(String transferName) {
|
||||||
|
this.transferName = transferName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getPaymentAmount() {
|
||||||
|
return paymentAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPaymentAmount(Integer paymentAmount) {
|
||||||
|
this.paymentAmount = paymentAmount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTransferTime() {
|
||||||
|
return transferTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTransferTime(String transferTime) {
|
||||||
|
this.transferTime = transferTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDesc() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDesc(String desc) {
|
||||||
|
this.desc = desc;
|
||||||
|
}
|
||||||
|
}
|
@ -91,4 +91,13 @@ public class WxMpPayServiceImplTest {
|
|||||||
System.err.println(this.wxService.getPayService().entPay(request, keyFile));
|
System.err.println(this.wxService.getPayService().entPay(request, keyFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#queryEntPay(String, File)}.
|
||||||
|
* @throws WxErrorException
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public final void testQueryEntPay() throws WxErrorException {
|
||||||
|
File keyFile = new File("E:\\dlt.p12");
|
||||||
|
System.err.println(this.wxService.getPayService().queryEntPay("11212121", keyFile));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user