@@ -35,6 +35,8 @@ public class WxPayApiData { | |||
private String exceptionMsg; | |||
/** | |||
* Instantiates a new Wx pay api data. | |||
* | |||
* @param url 接口请求地址 | |||
* @param requestData 请求数据 | |||
* @param responseData 响应数据 | |||
@@ -13,7 +13,6 @@ import me.chanjar.weixin.common.annotation.Required; | |||
* | |||
* @author <a href="https://github.com/binarywang">Binary Wang</a> | |||
*/ | |||
@Data | |||
@EqualsAndHashCode(callSuper = true) | |||
@Builder(builderMethodName = "newBuilder") | |||
@@ -13,7 +13,6 @@ import me.chanjar.weixin.common.annotation.Required; | |||
* | |||
* @author <a href="https://github.com/binarywang">Binary Wang</a> | |||
*/ | |||
@Data | |||
@EqualsAndHashCode(callSuper = true) | |||
@Builder(builderMethodName = "newBuilder") | |||
@@ -20,7 +20,6 @@ import me.chanjar.weixin.common.annotation.Required; | |||
* | |||
* @author <a href="https://github.com/binarywang">Binary Wang</a> | |||
*/ | |||
@Data | |||
@EqualsAndHashCode(callSuper = true) | |||
@Builder(builderMethodName = "newBuilder") | |||
@@ -32,6 +32,12 @@ public class WxPayNotifyResponse { | |||
@XStreamAlias("return_msg") | |||
private String returnMsg; | |||
/** | |||
* Fail string. | |||
* | |||
* @param msg the msg | |||
* @return the string | |||
*/ | |||
public static String fail(String msg) { | |||
WxPayNotifyResponse response = new WxPayNotifyResponse(FAIL, msg); | |||
XStream xstream = XStreamInitializer.getInstance(); | |||
@@ -39,6 +45,12 @@ public class WxPayNotifyResponse { | |||
return xstream.toXML(response); | |||
} | |||
/** | |||
* Success string. | |||
* | |||
* @param msg the msg | |||
* @return the string | |||
*/ | |||
public static String success(String msg) { | |||
WxPayNotifyResponse response = new WxPayNotifyResponse(SUCCESS, msg); | |||
XStream xstream = XStreamInitializer.getInstance(); | |||
@@ -12,6 +12,7 @@ import lombok.NoArgsConstructor; | |||
/** | |||
* 支付异步通知代金券详细. | |||
* | |||
* @author aimilin | |||
*/ | |||
@Data | |||
@@ -23,6 +24,12 @@ public class WxPayOrderNotifyCoupon implements Serializable { | |||
private String couponType; | |||
private Integer couponFee; | |||
/** | |||
* To map map. | |||
* | |||
* @param index the index | |||
* @return the map | |||
*/ | |||
public Map<String, String> toMap(int index) { | |||
Map<String, String> map = new HashMap<>(); | |||
map.put("coupon_id_" + index, this.getCouponId()); | |||
@@ -285,6 +285,12 @@ public class WxPayOrderNotifyResult extends BaseWxPayResult { | |||
@XStreamAlias("version") | |||
private String version; | |||
/** | |||
* From xml wx pay order notify result. | |||
* | |||
* @param xmlString the xml string | |||
* @return the wx pay order notify result | |||
*/ | |||
public static WxPayOrderNotifyResult fromXML(String xmlString) { | |||
XStream xstream = XStreamInitializer.getInstance(); | |||
xstream.processAnnotations(WxPayOrderNotifyResult.class); | |||
@@ -40,6 +40,8 @@ public class WxPayRefundNotifyResult extends BaseWxPayResult implements Serializ | |||
* | |||
* @param xmlString xml字符串 | |||
* @param mchKey 商户密钥 | |||
* @return the wx pay refund notify result | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
public static WxPayRefundNotifyResult fromXML(String xmlString, String mchKey) throws WxPayException { | |||
WxPayRefundNotifyResult result = BaseWxPayResult.fromXML(xmlString, WxPayRefundNotifyResult.class); | |||
@@ -252,6 +254,12 @@ public class WxPayRefundNotifyResult extends BaseWxPayResult implements Serializ | |||
@XStreamAlias("refund_request_source") | |||
private String refundRequestSource; | |||
/** | |||
* From xml req info. | |||
* | |||
* @param xmlString the xml string | |||
* @return the req info | |||
*/ | |||
public static ReqInfo fromXML(String xmlString) { | |||
XStream xstream = XStreamInitializer.getInstance(); | |||
xstream.processAnnotations(ReqInfo.class); | |||
@@ -121,6 +121,7 @@ public abstract class BaseWxPayRequest implements Serializable { | |||
* 将单位为元转换为单位为分. | |||
* | |||
* @param yuan 将要转换的元的数值字符串 | |||
* @return the integer | |||
*/ | |||
public static Integer yuanToFen(String yuan) { | |||
return new BigDecimal(yuan).setScale(2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100)).intValue(); | |||
@@ -143,6 +144,8 @@ public abstract class BaseWxPayRequest implements Serializable { | |||
/** | |||
* 检查约束情况. | |||
* | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
protected abstract void checkConstraints() throws WxPayException; | |||
@@ -178,6 +181,11 @@ public abstract class BaseWxPayRequest implements Serializable { | |||
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE); | |||
} | |||
/** | |||
* To xml string. | |||
* | |||
* @return the string | |||
*/ | |||
public String toXML() { | |||
XStream xstream = XStreamInitializer.getInstance(); | |||
//涉及到服务商模式的两个参数,在为空值时置为null,以免在请求时将空值传给微信服务器 | |||
@@ -189,6 +197,8 @@ public abstract class BaseWxPayRequest implements Serializable { | |||
/** | |||
* 签名时,是否忽略appid. | |||
* | |||
* @return the boolean | |||
*/ | |||
protected boolean ignoreAppid() { | |||
return false; | |||
@@ -196,6 +206,8 @@ public abstract class BaseWxPayRequest implements Serializable { | |||
/** | |||
* 签名时,忽略的参数. | |||
* | |||
* @return the string [ ] | |||
*/ | |||
protected String[] getIgnoredParamsForSign() { | |||
return new String[0]; | |||
@@ -210,6 +222,7 @@ public abstract class BaseWxPayRequest implements Serializable { | |||
* </pre> | |||
* | |||
* @param config 支付配置对象,用于读取相应系统配置信息 | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
public void checkAndSign(WxPayConfig config) throws WxPayException { | |||
this.checkFields(); | |||
@@ -116,6 +116,7 @@ public abstract class BaseWxPayResult implements Serializable { | |||
* 将单位分转换成单位圆. | |||
* | |||
* @param fen 将要被转换为元的分的数值 | |||
* @return the string | |||
*/ | |||
public static String fenToYuan(Integer fen) { | |||
return BigDecimal.valueOf(Double.valueOf(fen) / 100).setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString(); | |||
@@ -123,6 +124,11 @@ public abstract class BaseWxPayResult implements Serializable { | |||
/** | |||
* 从xml字符串创建bean对象. | |||
* | |||
* @param <T> the type parameter | |||
* @param xmlString the xml string | |||
* @param clz the clz | |||
* @return the t | |||
*/ | |||
public static <T extends BaseWxPayResult> T fromXML(String xmlString, Class<T> clz) { | |||
XStream xstream = XStreamInitializer.getInstance(); | |||
@@ -132,6 +138,11 @@ public abstract class BaseWxPayResult implements Serializable { | |||
return result; | |||
} | |||
/** | |||
* Gets logger. | |||
* | |||
* @return the logger | |||
*/ | |||
protected Logger getLogger() { | |||
return LoggerFactory.getLogger(this.getClass()); | |||
} | |||
@@ -143,6 +154,8 @@ public abstract class BaseWxPayResult implements Serializable { | |||
/** | |||
* 将bean通过保存的xml字符串转换成map. | |||
* | |||
* @return the map | |||
*/ | |||
public Map<String, String> toMap() { | |||
if (StringUtils.isBlank(this.xmlString)) { | |||
@@ -189,6 +202,9 @@ public abstract class BaseWxPayResult implements Serializable { | |||
/** | |||
* 获取xml中元素的值. | |||
* | |||
* @param path the path | |||
* @return the xml value | |||
*/ | |||
String getXmlValue(String... path) { | |||
Document doc = this.getXmlDoc(); | |||
@@ -206,6 +222,9 @@ public abstract class BaseWxPayResult implements Serializable { | |||
/** | |||
* 获取xml中元素的值,作为int值返回. | |||
* | |||
* @param path the path | |||
* @return the xml value as int | |||
*/ | |||
Integer getXmlValueAsInt(String... path) { | |||
String result = this.getXmlValue(path); | |||
@@ -219,8 +238,10 @@ public abstract class BaseWxPayResult implements Serializable { | |||
/** | |||
* 校验返回结果签名. | |||
* | |||
* @param wxPayService the wx pay service | |||
* @param signType 签名类型 | |||
* @param checkSuccess 是否同时检查结果是否成功 | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
public void checkResult(WxPayService wxPayService, String signType, boolean checkSuccess) throws WxPayException { | |||
//校验返回结果签名 | |||
@@ -10,6 +10,8 @@ import lombok.Data; | |||
import lombok.NoArgsConstructor; | |||
/** | |||
* The type Wx pay bill result. | |||
* | |||
* @author BinaryWang | |||
*/ | |||
@Data | |||
@@ -10,7 +10,6 @@ import com.thoughtworks.xstream.annotations.XStreamAlias; | |||
* | |||
* @author <a href="https://github.com/binarywang">Binary Wang</a> | |||
*/ | |||
@XStreamAlias("xml") | |||
public class WxPayCommonResult extends BaseWxPayResult { | |||
} |
@@ -1,12 +1,13 @@ | |||
package com.github.binarywang.wxpay.bean.result; | |||
import lombok.Data; | |||
import lombok.NoArgsConstructor; | |||
import java.io.Serializable; | |||
import java.util.List; | |||
import org.apache.commons.lang3.builder.ToStringBuilder; | |||
import org.apache.commons.lang3.builder.ToStringStyle; | |||
import java.io.Serializable; | |||
import java.util.List; | |||
import lombok.Data; | |||
import lombok.NoArgsConstructor; | |||
/** | |||
* <pre> | |||
@@ -15,7 +16,6 @@ import java.util.List; | |||
* </pre> | |||
* | |||
* @author cwivan | |||
* @date 2018-08-02 | |||
*/ | |||
@Data | |||
@NoArgsConstructor | |||
@@ -267,6 +267,9 @@ public class WxPayOrderQueryResult extends BaseWxPayResult { | |||
} | |||
} | |||
/** | |||
* The type Coupon. | |||
*/ | |||
@Data | |||
@Builder(builderMethodName = "newBuilder") | |||
@AllArgsConstructor | |||
@@ -223,6 +223,9 @@ public class WxPayRedpackQueryResult extends BaseWxPayResult { | |||
@XStreamAlias("hblist") | |||
private List<RedpackInfo> redpackList; | |||
/** | |||
* The type Redpack info. | |||
*/ | |||
@Data | |||
@XStreamAlias("hbinfo") | |||
public static class RedpackInfo implements Serializable { | |||
@@ -1,10 +1,14 @@ | |||
package com.github.binarywang.wxpay.bean.result; | |||
import java.util.List; | |||
import com.google.common.collect.Lists; | |||
import com.thoughtworks.xstream.annotations.XStreamAlias; | |||
import lombok.*; | |||
import java.util.List; | |||
import lombok.AllArgsConstructor; | |||
import lombok.Builder; | |||
import lombok.Data; | |||
import lombok.EqualsAndHashCode; | |||
import lombok.NoArgsConstructor; | |||
/** | |||
* <pre> | |||
@@ -168,6 +172,9 @@ public class WxPayRefundQueryResult extends BaseWxPayResult { | |||
} | |||
} | |||
/** | |||
* The type Refund record. | |||
*/ | |||
@Data | |||
@Builder(builderMethodName = "newBuilder") | |||
@NoArgsConstructor | |||
@@ -95,6 +95,9 @@ public class WxPayConfig { | |||
/** | |||
* 初始化ssl. | |||
* | |||
* @return the ssl context | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
public SSLContext initSSLContext() throws WxPayException { | |||
if (StringUtils.isBlank(this.getMchId())) { | |||
@@ -127,8 +127,17 @@ public class WxPayConstants { | |||
* 签名类型. | |||
*/ | |||
public static class SignType { | |||
/** | |||
* The constant HMAC_SHA256. | |||
*/ | |||
public static final String HMAC_SHA256 = "HMAC-SHA256"; | |||
/** | |||
* The constant MD5. | |||
*/ | |||
public static final String MD5 = "MD5"; | |||
/** | |||
* The constant ALL_SIGN_TYPES. | |||
*/ | |||
public static final List<String> ALL_SIGN_TYPES = Lists.newArrayList(HMAC_SHA256, MD5); | |||
} | |||
@@ -1,5 +1,14 @@ | |||
package com.github.binarywang.wxpay.converter; | |||
import java.beans.PropertyDescriptor; | |||
import java.lang.reflect.Field; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.List; | |||
import java.util.Map; | |||
import org.apache.commons.lang3.StringUtils; | |||
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyCoupon; | |||
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; | |||
import com.google.common.base.Function; | |||
@@ -13,20 +22,20 @@ import com.thoughtworks.xstream.converters.reflection.ReflectionProvider; | |||
import com.thoughtworks.xstream.io.HierarchicalStreamReader; | |||
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; | |||
import com.thoughtworks.xstream.mapper.Mapper; | |||
import org.apache.commons.lang3.StringUtils; | |||
import java.beans.PropertyDescriptor; | |||
import java.lang.reflect.Field; | |||
import java.util.ArrayList; | |||
import java.util.Arrays; | |||
import java.util.List; | |||
import java.util.Map; | |||
/** | |||
* The type Wxpay order notify result converter. | |||
* | |||
* @author aimilin | |||
*/ | |||
public class WxPayOrderNotifyResultConverter extends AbstractReflectionConverter { | |||
/** | |||
* Instantiates a new Wx pay order notify result converter. | |||
* | |||
* @param mapper the mapper | |||
* @param reflectionProvider the reflection provider | |||
*/ | |||
public WxPayOrderNotifyResultConverter(Mapper mapper, ReflectionProvider reflectionProvider) { | |||
super(mapper, reflectionProvider); | |||
} | |||
@@ -51,11 +51,22 @@ public class WxPayException extends Exception { | |||
*/ | |||
private String xmlString; | |||
/** | |||
* Instantiates a new Wx pay exception. | |||
* | |||
* @param customErrorMsg the custom error msg | |||
*/ | |||
public WxPayException(String customErrorMsg) { | |||
super(customErrorMsg); | |||
this.customErrorMsg = customErrorMsg; | |||
} | |||
/** | |||
* Instantiates a new Wx pay exception. | |||
* | |||
* @param customErrorMsg the custom error msg | |||
* @param tr the tr | |||
*/ | |||
public WxPayException(String customErrorMsg, Throwable tr) { | |||
super(customErrorMsg, tr); | |||
this.customErrorMsg = customErrorMsg; | |||
@@ -73,6 +84,9 @@ public class WxPayException extends Exception { | |||
/** | |||
* 通过BaseWxPayResult生成异常对象. | |||
* | |||
* @param payBaseResult the pay base result | |||
* @return the wx pay exception | |||
*/ | |||
public static WxPayException from(BaseWxPayResult payBaseResult) { | |||
return WxPayException.newBuilder() | |||
@@ -85,10 +99,18 @@ public class WxPayException extends Exception { | |||
.build(); | |||
} | |||
/** | |||
* New builder builder. | |||
* | |||
* @return the builder | |||
*/ | |||
public static Builder newBuilder() { | |||
return new Builder(); | |||
} | |||
/** | |||
* The type Builder. | |||
*/ | |||
public static final class Builder { | |||
private String returnCode; | |||
private String returnMsg; | |||
@@ -100,40 +122,86 @@ public class WxPayException extends Exception { | |||
private Builder() { | |||
} | |||
/** | |||
* Return code builder. | |||
* | |||
* @param returnCode the return code | |||
* @return the builder | |||
*/ | |||
public Builder returnCode(String returnCode) { | |||
this.returnCode = returnCode; | |||
return this; | |||
} | |||
/** | |||
* Return msg builder. | |||
* | |||
* @param returnMsg the return msg | |||
* @return the builder | |||
*/ | |||
public Builder returnMsg(String returnMsg) { | |||
this.returnMsg = returnMsg; | |||
return this; | |||
} | |||
/** | |||
* Result code builder. | |||
* | |||
* @param resultCode the result code | |||
* @return the builder | |||
*/ | |||
public Builder resultCode(String resultCode) { | |||
this.resultCode = resultCode; | |||
return this; | |||
} | |||
/** | |||
* Err code builder. | |||
* | |||
* @param errCode the err code | |||
* @return the builder | |||
*/ | |||
public Builder errCode(String errCode) { | |||
this.errCode = errCode; | |||
return this; | |||
} | |||
/** | |||
* Err code des builder. | |||
* | |||
* @param errCodeDes the err code des | |||
* @return the builder | |||
*/ | |||
public Builder errCodeDes(String errCodeDes) { | |||
this.errCodeDes = errCodeDes; | |||
return this; | |||
} | |||
/** | |||
* Xml string builder. | |||
* | |||
* @param xmlString the xml string | |||
* @return the builder | |||
*/ | |||
public Builder xmlString(String xmlString) { | |||
this.xmlString = xmlString; | |||
return this; | |||
} | |||
/** | |||
* Build wx pay exception. | |||
* | |||
* @return the wx pay exception | |||
*/ | |||
public WxPayException build() { | |||
return new WxPayException(this); | |||
} | |||
/** | |||
* Build error msg string. | |||
* | |||
* @return the string | |||
*/ | |||
public String buildErrorMsg() { | |||
return Joiner.on(",").skipNulls().join( | |||
returnCode == null ? null : String.format("返回代码:[%s]", returnCode), | |||
@@ -24,6 +24,8 @@ public interface EntPayService { | |||
* </pre> | |||
* | |||
* @param request 请求对象 | |||
* @return the ent pay result | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
EntPayResult entPay(EntPayRequest request) throws WxPayException; | |||
@@ -36,6 +38,8 @@ public interface EntPayService { | |||
* </pre> | |||
* | |||
* @param partnerTradeNo 商户订单号 | |||
* @return the ent pay query result | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
EntPayQueryResult queryEntPay(String partnerTradeNo) throws WxPayException; | |||
@@ -54,6 +58,9 @@ public interface EntPayService { | |||
* 文档详见:https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=24_7&index=4 | |||
* 接口链接:https://fraud.mch.weixin.qq.com/risk/getpublickey | |||
* </pre> | |||
* | |||
* @return the public key | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
String getPublicKey() throws WxPayException; | |||
@@ -67,6 +74,8 @@ public interface EntPayService { | |||
* </pre> | |||
* | |||
* @param request 请求对象 | |||
* @return the ent pay bank result | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
EntPayBankResult payBank(EntPayBankRequest request) throws WxPayException; | |||
@@ -79,6 +88,8 @@ public interface EntPayService { | |||
* </pre> | |||
* | |||
* @param partnerTradeNo 商户订单号 | |||
* @return the ent pay bank query result | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
EntPayBankQueryResult queryPayBank(String partnerTradeNo) throws WxPayException; | |||
} |
@@ -53,6 +53,8 @@ public interface WxPayService { | |||
/** | |||
* 获取微信支付请求url前缀,沙箱环境可能不一样. | |||
* | |||
* @return the pay base url | |||
*/ | |||
String getPayBaseUrl(); | |||
@@ -62,7 +64,8 @@ public interface WxPayService { | |||
* @param url 请求地址 | |||
* @param requestStr 请求信息 | |||
* @param useKey 是否使用证书 | |||
* @return 返回请求结果字节数组 | |||
* @return 返回请求结果字节数组 byte [ ] | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
byte[] postForBytes(String url, String requestStr, boolean useKey) throws WxPayException; | |||
@@ -72,17 +75,22 @@ public interface WxPayService { | |||
* @param url 请求地址 | |||
* @param requestStr 请求信息 | |||
* @param useKey 是否使用证书 | |||
* @return 返回请求结果字符串 | |||
* @return 返回请求结果字符串 string | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
String post(String url, String requestStr, boolean useKey) throws WxPayException; | |||
/** | |||
* 获取企业付款服务类. | |||
* | |||
* @return the ent pay service | |||
*/ | |||
EntPayService getEntPayService(); | |||
/** | |||
* 设置企业付款服务类,允许开发者自定义实现类. | |||
* | |||
* @param entPayService the ent pay service | |||
*/ | |||
void setEntPayService(EntPayService entPayService); | |||
@@ -101,6 +109,8 @@ public interface WxPayService { | |||
* | |||
* @param transactionId 微信订单号 | |||
* @param outTradeNo 商户系统内部的订单号,当没提供transactionId时需要传这个。 | |||
* @return the wx pay order query result | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) throws WxPayException; | |||
@@ -118,6 +128,8 @@ public interface WxPayService { | |||
* </pre> | |||
* | |||
* @param request 查询订单请求对象 | |||
* @return the wx pay order query result | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
WxPayOrderQueryResult queryOrder(WxPayOrderQueryRequest request) throws WxPayException; | |||
@@ -134,6 +146,8 @@ public interface WxPayService { | |||
* </pre> | |||
* | |||
* @param outTradeNo 商户系统内部的订单号 | |||
* @return the wx pay order close result | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
WxPayOrderCloseResult closeOrder(String outTradeNo) throws WxPayException; | |||
@@ -150,15 +164,18 @@ public interface WxPayService { | |||
* </pre> | |||
* | |||
* @param request 关闭订单请求对象 | |||
* @return the wx pay order close result | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
WxPayOrderCloseResult closeOrder(WxPayOrderCloseRequest request) throws WxPayException; | |||
/** | |||
* 调用统一下单接口,并组装生成支付所需参数对象. | |||
* | |||
* @param request 统一下单请求参数 | |||
* @param <T> 请使用{@link com.github.binarywang.wxpay.bean.order}包下的类 | |||
* @param request 统一下单请求参数 | |||
* @return 返回 {@link com.github.binarywang.wxpay.bean.order}包下的类对象 | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
<T> T createOrder(WxPayUnifiedOrderRequest request) throws WxPayException; | |||
@@ -168,6 +185,8 @@ public interface WxPayService { | |||
* 接口地址:https://api.mch.weixin.qq.com/pay/unifiedorder | |||
* | |||
* @param request 请求对象,注意一些参数如appid、mchid等不用设置,方法内会自动从配置对象中获取到(前提是对应配置中已经设置) | |||
* @return the wx pay unified order result | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request) throws WxPayException; | |||
@@ -176,6 +195,8 @@ public interface WxPayService { | |||
* 详见https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=8_5 | |||
* | |||
* @param request 请求对象,注意一些参数如appid、mchid等不用设置,方法内会自动从配置对象中获取到(前提是对应配置中已经设置) | |||
* @return the pay info | |||
* @throws WxPayException the wx pay exception | |||
* @deprecated 建议使用 {@link com.github.binarywang.wxpay.service.WxPayService#createOrder(WxPayUnifiedOrderRequest)} | |||
*/ | |||
@Deprecated | |||
@@ -183,11 +204,15 @@ public interface WxPayService { | |||
/** | |||
* 获取配置. | |||
* | |||
* @return the config | |||
*/ | |||
WxPayConfig getConfig(); | |||
/** | |||
* 设置配置对象. | |||
* | |||
* @param config the config | |||
*/ | |||
void setConfig(WxPayConfig config); | |||
@@ -199,7 +224,8 @@ public interface WxPayService { | |||
* </pre> | |||
* | |||
* @param request 请求对象 | |||
* @return 退款操作结果 | |||
* @return 退款操作结果 wx pay refund result | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
WxPayRefundResult refund(WxPayRefundRequest request) throws WxPayException; | |||
@@ -218,7 +244,8 @@ public interface WxPayService { | |||
* @param outTradeNo 商户订单号 | |||
* @param outRefundNo 商户退款单号 | |||
* @param refundId 微信退款单号 | |||
* @return 退款信息 | |||
* @return 退款信息 wx pay refund query result | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
WxPayRefundQueryResult refundQuery(String transactionId, String outTradeNo, String outRefundNo, String refundId) | |||
throws WxPayException; | |||
@@ -234,25 +261,38 @@ public interface WxPayService { | |||
* </pre> | |||
* | |||
* @param request 微信退款单号 | |||
* @return 退款信息 | |||
* @return 退款信息 wx pay refund query result | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
WxPayRefundQueryResult refundQuery(WxPayRefundQueryRequest request) throws WxPayException; | |||
/** | |||
* 解析支付结果通知. | |||
* 详见https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7 | |||
* | |||
* @param xmlData the xml data | |||
* @return the wx pay order notify result | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
WxPayOrderNotifyResult parseOrderNotifyResult(String xmlData) throws WxPayException; | |||
/** | |||
* 解析退款结果通知 | |||
* 详见https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_16&index=9 | |||
* | |||
* @param xmlData the xml data | |||
* @return the wx pay refund notify result | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
WxPayRefundNotifyResult parseRefundNotifyResult(String xmlData) throws WxPayException; | |||
/** | |||
* 解析扫码支付回调通知 | |||
* 详见https://pay.weixin.qq.com/wiki/doc/api/native.php?chapter=6_4 | |||
* | |||
* @param xmlData the xml data | |||
* @return the wx scan pay notify result | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
WxScanPayNotifyResult parseScanPayNotifyResult(String xmlData) throws WxPayException; | |||
@@ -267,6 +307,8 @@ public interface WxPayService { | |||
* </pre> | |||
* | |||
* @param request 请求对象 | |||
* @return the wx pay send redpack result | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
WxPaySendRedpackResult sendRedpack(WxPaySendRedpackRequest request) throws WxPayException; | |||
@@ -280,6 +322,8 @@ public interface WxPayService { | |||
* </pre> | |||
* | |||
* @param mchBillNo 商户发放红包的商户订单号,比如10000098201411111234567890 | |||
* @return the wx pay redpack query result | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
WxPayRedpackQueryResult queryRedpack(String mchBillNo) throws WxPayException; | |||
@@ -293,9 +337,9 @@ public interface WxPayService { | |||
* </pre> | |||
* | |||
* @param productId 产品Id | |||
* @param sideLength 要生成的二维码的边长,如果为空,则取默认值400 | |||
* @param logoFile 商户logo图片的文件对象,可以为空 | |||
* @return 生成的二维码的字节数组 | |||
* @param sideLength 要生成的二维码的边长,如果为空,则取默认值400 | |||
* @return 生成的二维码的字节数组 byte [ ] | |||
*/ | |||
byte[] createScanPayQrcodeMode1(String productId, File logoFile, Integer sideLength); | |||
@@ -309,7 +353,7 @@ public interface WxPayService { | |||
* </pre> | |||
* | |||
* @param productId 产品Id | |||
* @return 生成的二维码URL连接 | |||
* @return 生成的二维码URL连接 string | |||
*/ | |||
String createScanPayQrcodeMode1(String productId); | |||
@@ -324,7 +368,7 @@ public interface WxPayService { | |||
* @param codeUrl 微信返回的交易会话的二维码链接 | |||
* @param logoFile 商户logo图片的文件对象,可以为空 | |||
* @param sideLength 要生成的二维码的边长,如果为空,则取默认值400 | |||
* @return 生成的二维码的字节数组 | |||
* @return 生成的二维码的字节数组 byte [ ] | |||
*/ | |||
byte[] createScanPayQrcodeMode2(String codeUrl, File logoFile, Integer sideLength); | |||
@@ -338,6 +382,9 @@ public interface WxPayService { | |||
* 接口地址: https://api.mch.weixin.qq.com/payitil/report | |||
* 是否需要证书:不需要 | |||
* </pre> | |||
* | |||
* @param request the request | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
void report(WxPayReportRequest request) throws WxPayException; | |||
@@ -358,7 +405,8 @@ public interface WxPayService { | |||
* @param billType 账单类型 bill_type ALL,返回当日所有订单信息,默认值,SUCCESS,返回当日成功支付的订单,REFUND,返回当日退款订单 | |||
* @param tarType 压缩账单 tar_type 非必传参数,固定值:GZIP,返回格式为.gzip的压缩包账单。不传则默认为数据流形式。 | |||
* @param deviceInfo 设备号 device_info 非必传参数,终端设备号 | |||
* @return WxPayBillResult对象 | |||
* @return WxPayBillResult对象 wx pay bill result | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
WxPayBillResult downloadBill(String billDate, String billType, String tarType, String deviceInfo) throws WxPayException; | |||
@@ -376,7 +424,8 @@ public interface WxPayService { | |||
* </pre> | |||
* | |||
* @param request 下载对账单请求 | |||
* @return WxPayBillResult对象 | |||
* @return WxPayBillResult对象 wx pay bill result | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
WxPayBillResult downloadBill(WxPayDownloadBillRequest request) throws WxPayException; | |||
@@ -392,10 +441,11 @@ public interface WxPayService { | |||
* 详情请见: <a href="https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_18">下载对账单</a> | |||
* </pre> | |||
* | |||
* @param billDate 资金账单日期 bill_date 下载对账单的日期,格式:20140603 | |||
* @param accountType 资金账户类型 account_type Basic,基本账户,Operation,运营账户,Fees,手续费账户 | |||
* @param tarType 压缩账单 tar_type 非必传参数,固定值:GZIP,返回格式为.gzip的压缩包账单。不传则默认为数据流形式。 | |||
* @return WxPayFundFlowResult对象 | |||
* @param billDate 资金账单日期 bill_date 下载对账单的日期,格式:20140603 | |||
* @param accountType 资金账户类型 account_type Basic,基本账户,Operation,运营账户,Fees,手续费账户 | |||
* @param tarType 压缩账单 tar_type 非必传参数,固定值:GZIP,返回格式为.gzip的压缩包账单。不传则默认为数据流形式。 | |||
* @return WxPayFundFlowResult对象 wx pay fund flow result | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
WxPayFundFlowResult downloadFundFlow(String billDate, String accountType, String tarType) throws WxPayException; | |||
@@ -412,7 +462,8 @@ public interface WxPayService { | |||
* </pre> | |||
* | |||
* @param request 下载资金流水请求 | |||
* @return WxPayFundFlowResult对象 | |||
* @return WxPayFundFlowResult对象 wx pay fund flow result | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
WxPayFundFlowResult downloadFundFlow(WxPayDownloadFundFlowRequest request) throws WxPayException; | |||
@@ -427,6 +478,10 @@ public interface WxPayService { | |||
* 接口地址: https://api.mch.weixin.qq.com/pay/micropay | |||
* 是否需要证书:不需要。 | |||
* </pre> | |||
* | |||
* @param request the request | |||
* @return the wx pay micropay result | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
WxPayMicropayResult micropay(WxPayMicropayRequest request) throws WxPayException; | |||
@@ -443,6 +498,10 @@ public interface WxPayService { | |||
* 接口链接 :https://api.mch.weixin.qq.com/secapi/pay/reverse | |||
* 是否需要证书:请求需要双向证书。 | |||
* </pre> | |||
* | |||
* @param request the request | |||
* @return the wx pay order reverse result | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
WxPayOrderReverseResult reverseOrder(WxPayOrderReverseRequest request) throws WxPayException; | |||
@@ -458,6 +517,8 @@ public interface WxPayService { | |||
* </pre> | |||
* | |||
* @param request 请求对象 | |||
* @return the string | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
String shorturl(WxPayShorturlRequest request) throws WxPayException; | |||
@@ -467,7 +528,9 @@ public interface WxPayService { | |||
* </pre> | |||
* | |||
* @param longUrl 需要被压缩的网址 | |||
* @see WxPayService#shorturl(WxPayShorturlRequest) | |||
* @return the string | |||
* @throws WxPayException the wx pay exception | |||
* @see WxPayService#shorturl(WxPayShorturlRequest) WxPayService#shorturl(WxPayShorturlRequest) | |||
*/ | |||
String shorturl(String longUrl) throws WxPayException; | |||
@@ -482,7 +545,8 @@ public interface WxPayService { | |||
* </pre> | |||
* | |||
* @param request 请求对象 | |||
* @return openid | |||
* @return openid string | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
String authcode2Openid(WxPayAuthcode2OpenidRequest request) throws WxPayException; | |||
@@ -492,8 +556,9 @@ public interface WxPayService { | |||
* </pre> | |||
* | |||
* @param authCode 授权码 | |||
* @return openid | |||
* @see WxPayService#authcode2Openid(WxPayAuthcode2OpenidRequest) | |||
* @return openid string | |||
* @throws WxPayException the wx pay exception | |||
* @see WxPayService#authcode2Openid(WxPayAuthcode2OpenidRequest) WxPayService#authcode2Openid(WxPayAuthcode2OpenidRequest) | |||
*/ | |||
String authcode2Openid(String authCode) throws WxPayException; | |||
@@ -505,6 +570,9 @@ public interface WxPayService { | |||
* 请求方式: POST | |||
* 文档地址:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=23_1 | |||
* </pre> | |||
* | |||
* @return the sandbox sign key | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
String getSandboxSignKey() throws WxPayException; | |||
@@ -515,6 +583,10 @@ public interface WxPayService { | |||
* 是否需要证书:请求需要双向证书。 | |||
* 文档地址:https://pay.weixin.qq.com/wiki/doc/api/tools/sp_coupon.php?chapter=12_3 | |||
* </pre> | |||
* | |||
* @param request the request | |||
* @return the wx pay coupon send result | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
WxPayCouponSendResult sendCoupon(WxPayCouponSendRequest request) throws WxPayException; | |||
@@ -524,6 +596,10 @@ public interface WxPayService { | |||
* 接口请求链接:https://api.mch.weixin.qq.com/mmpaymkttransfers/query_coupon_stock | |||
* 文档地址:https://pay.weixin.qq.com/wiki/doc/api/tools/sp_coupon.php?chapter=12_4 | |||
* </pre> | |||
* | |||
* @param request the request | |||
* @return the wx pay coupon stock query result | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
WxPayCouponStockQueryResult queryCouponStock(WxPayCouponStockQueryRequest request) throws WxPayException; | |||
@@ -533,11 +609,17 @@ public interface WxPayService { | |||
* 接口请求链接:https://api.mch.weixin.qq.com/mmpaymkttransfers/querycouponsinfo | |||
* 文档地址:https://pay.weixin.qq.com/wiki/doc/api/tools/sp_coupon.php?chapter=12_5 | |||
* </pre> | |||
* | |||
* @param request the request | |||
* @return the wx pay coupon info query result | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
WxPayCouponInfoQueryResult queryCouponInfo(WxPayCouponInfoQueryRequest request) throws WxPayException; | |||
/** | |||
* 获取微信请求数据,方便接口调用方获取处理. | |||
* | |||
* @return the wx api data | |||
*/ | |||
WxPayApiData getWxApiData(); | |||
@@ -558,6 +640,8 @@ public interface WxPayService { | |||
* @param endDate 结束时间 | |||
* @param offset 位移 | |||
* @param limit 条数,建议填null,否则接口会报签名错误 | |||
* @return the string | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
String queryComment(Date beginDate, Date endDate, Integer offset, Integer limit) throws WxPayException; | |||
} |
@@ -90,11 +90,20 @@ import static com.github.binarywang.wxpay.constant.WxPayConstants.TarType; | |||
*/ | |||
public abstract class BaseWxPayServiceImpl implements WxPayService { | |||
private static final String PAY_BASE_URL = "https://api.mch.weixin.qq.com"; | |||
/** | |||
* The Log. | |||
*/ | |||
protected final Logger log = LoggerFactory.getLogger(this.getClass()); | |||
/** | |||
* The constant wxApiData. | |||
*/ | |||
protected static ThreadLocal<WxPayApiData> wxApiData = new ThreadLocal<>(); | |||
private EntPayService entPayService = new EntPayServiceImpl(this); | |||
/** | |||
* The Config. | |||
*/ | |||
protected WxPayConfig config; | |||
@Override | |||
@@ -40,6 +40,11 @@ import com.github.binarywang.wxpay.service.WxPayService; | |||
public class EntPayServiceImpl implements EntPayService { | |||
private WxPayService payService; | |||
/** | |||
* Instantiates a new Ent pay service. | |||
* | |||
* @param payService the pay service | |||
*/ | |||
public EntPayServiceImpl(WxPayService payService) { | |||
this.payService = payService; | |||
} | |||
@@ -140,6 +145,13 @@ public class EntPayServiceImpl implements EntPayService { | |||
} | |||
} | |||
/** | |||
* The entry point of application. | |||
* | |||
* @param args the input arguments | |||
* @throws WxPayException the wx pay exception | |||
* @throws IOException the io exception | |||
*/ | |||
public static void main(String[] args) throws WxPayException, IOException { | |||
String key = "-----BEGIN RSA PUBLIC KEY-----\n" + | |||
"MIIBCgKCAQEAtEeUSop/YGqZ53Y++R9NapFSZmorj+SL/brmJUU7+hyClEnPOeG/\n" + | |||
@@ -33,6 +33,10 @@ import lombok.extern.slf4j.Slf4j; | |||
public class SignUtils { | |||
/** | |||
* 请参考并使用 {@link #createSign(Object, String, String, String[])}. | |||
* | |||
* @param xmlBean the xml bean | |||
* @param signKey the sign key | |||
* @return the string | |||
*/ | |||
@Deprecated | |||
public static String createSign(Object xmlBean, String signKey) { | |||
@@ -41,6 +45,10 @@ public class SignUtils { | |||
/** | |||
* 请参考并使用 {@link #createSign(Map, String, String, String[])} . | |||
* | |||
* @param params the params | |||
* @param signKey the sign key | |||
* @return the string | |||
*/ | |||
@Deprecated | |||
public static String createSign(Map<String, String> params, String signKey) { | |||
@@ -54,7 +62,7 @@ public class SignUtils { | |||
* @param signType 签名类型,如果为空,则默认为MD5 | |||
* @param signKey 签名Key | |||
* @param ignoredParams 签名时需要忽略的特殊参数 | |||
* @return 签名字符串 | |||
* @return 签名字符串 string | |||
*/ | |||
public static String createSign(Object xmlBean, String signType, String signKey, String[] ignoredParams) { | |||
return createSign(xmlBean2Map(xmlBean), signType, signKey, ignoredParams); | |||
@@ -67,7 +75,7 @@ public class SignUtils { | |||
* @param signType 签名类型,如果为空,则默认为MD5 | |||
* @param signKey 签名Key | |||
* @param ignoredParams 签名时需要忽略的特殊参数 | |||
* @return 签名字符串 | |||
* @return 签名字符串 string | |||
*/ | |||
public static String createSign(Map<String, String> params, String signType, String signKey, String[] ignoredParams) { | |||
SortedMap<String, String> sortedMap = new TreeMap<>(params); | |||
@@ -123,7 +131,7 @@ public class SignUtils { | |||
* 将bean按照@XStreamAlias标识的字符串内容生成以之为key的map对象. | |||
* | |||
* @param bean 包含@XStreamAlias的xml bean对象 | |||
* @return map对象 | |||
* @return map对象 map | |||
*/ | |||
public static Map<String, String> xmlBean2Map(Object bean) { | |||
Map<String, String> result = Maps.newHashMap(); | |||
@@ -1,16 +1,19 @@ | |||
package com.github.binarywang.wxpay.bean.notify; | |||
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; | |||
import org.testng.*; | |||
import org.testng.annotations.*; | |||
/** | |||
* <pre> | |||
* Created by Binary Wang on 2017-6-15. | |||
* @author <a href="https://github.com/binarywang">Binary Wang</a> | |||
* </pre> | |||
* | |||
* @author <a href="https://github.com/binarywang">Binary Wang</a> | |||
*/ | |||
public class WxPayOrderNotifyResultTest { | |||
/** | |||
* Test from xml. | |||
*/ | |||
@Test | |||
public void testFromXML() { | |||
String xmlString = "<xml>\n" + | |||
@@ -28,6 +28,11 @@ public class WxPayRefundNotifyResultTest { | |||
@Inject | |||
private WxPayConfig wxPayConfig; | |||
/** | |||
* Test from xml. | |||
* | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
public void testFromXML() throws WxPayException { | |||
String xmlString = "<xml>" + | |||
"<return_code>SUCCESS</return_code>" + | |||
@@ -42,6 +47,11 @@ public class WxPayRefundNotifyResultTest { | |||
System.out.println(refundNotifyResult); | |||
} | |||
/** | |||
* Encode req info. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
public void encodeReqInfo() throws Exception { | |||
String xml = "<root>\n" + | |||
"<out_refund_no><![CDATA[R4001312001201707262674894706_4]]></out_refund_no>\n" + | |||
@@ -16,10 +16,16 @@ import static org.assertj.core.api.Assertions.assertThat; | |||
*/ | |||
public class WxScanPayNotifyResultTest { | |||
/** | |||
* Test to map. | |||
*/ | |||
@Test | |||
public void testToMap() { | |||
} | |||
/** | |||
* Test from xml. | |||
*/ | |||
@Test | |||
public void testFromXML() { | |||
String xmlString = "<xml>\n" + | |||
@@ -1,26 +1,42 @@ | |||
package com.github.binarywang.wxpay.bean.result; | |||
import java.util.Map; | |||
import org.testng.*; | |||
import org.testng.annotations.*; | |||
import java.util.Map; | |||
/** | |||
* <pre> | |||
* Created by Binary Wang on 2017-01-04. | |||
* @author <a href="https://github.com/binarywang">binarywang(Binary Wang)</a> | |||
* </pre> | |||
* | |||
* @author <a href="https://github.com/binarywang">binarywang(Binary Wang)</a> | |||
*/ | |||
public class BaseWxPayResultTest { | |||
/** | |||
* Test get xml value. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testGetXmlValue() throws Exception { | |||
} | |||
/** | |||
* Test xml 2 doc. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testXml2Doc() throws Exception { | |||
} | |||
/** | |||
* Test to map. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testToMap() throws Exception { | |||
WxPayOrderQueryResult result = new WxPayOrderQueryResult(); | |||
@@ -53,6 +69,9 @@ public class BaseWxPayResultTest { | |||
} | |||
/** | |||
* Test to map with empty xml string. | |||
*/ | |||
@Test(expectedExceptions = {RuntimeException.class}) | |||
public void testToMap_with_empty_xmlString() { | |||
WxPayOrderQueryResult result = new WxPayOrderQueryResult(); | |||
@@ -6,10 +6,14 @@ import org.testng.annotations.*; | |||
/** | |||
* <pre> | |||
* Created by Binary Wang on 2017-01-04. | |||
* </pre> | |||
* | |||
* @author <a href="https://github.com/binarywang">binarywang(Binary Wang)</a> | |||
* </pre> | |||
*/ | |||
public class WxPayOrderQueryResultTest { | |||
/** | |||
* Test compose coupons. | |||
*/ | |||
@Test | |||
public void testComposeCoupons() { | |||
/* | |||
@@ -13,6 +13,9 @@ import static org.assertj.core.api.Assertions.assertThat; | |||
* @author <a href="https://github.com/binarywang">Binary Wang</a> | |||
*/ | |||
public class WxPayRedpackQueryResultTest { | |||
/** | |||
* Test from xml. | |||
*/ | |||
@Test | |||
public void testFromXML() { | |||
String xmlString = "<xml>\n" + | |||
@@ -7,10 +7,16 @@ import org.testng.annotations.*; | |||
/** | |||
* <pre> | |||
* Created by Binary Wang on 2016-12-29. | |||
* </pre> | |||
* | |||
* @author <a href="https://github.com/binarywang">binarywang(Binary Wang)</a> | |||
* </pre> | |||
*/ | |||
public class WxPayRefundQueryResultTest { | |||
/** | |||
* Compose refund records. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void composeRefundRecords() throws Exception { | |||
/* | |||
@@ -13,6 +13,9 @@ import static org.assertj.core.api.Assertions.assertThat; | |||
*/ | |||
public class WxPayRefundResultTest { | |||
/** | |||
* Test compose refund coupons. | |||
*/ | |||
@Test | |||
public void testComposeRefundCoupons() { | |||
/* | |||
@@ -1,20 +1,30 @@ | |||
package com.github.binarywang.wxpay.bean.result; | |||
import com.thoughtworks.xstream.XStream; | |||
import me.chanjar.weixin.common.util.xml.XStreamInitializer; | |||
import org.testng.*; | |||
import org.testng.annotations.*; | |||
import com.thoughtworks.xstream.XStream; | |||
import me.chanjar.weixin.common.util.xml.XStreamInitializer; | |||
/** | |||
* The type Wx pay send redpack result test. | |||
*/ | |||
public class WxPaySendRedpackResultTest { | |||
private XStream xstream; | |||
/** | |||
* Sets . | |||
*/ | |||
@BeforeTest | |||
public void setup() { | |||
this.xstream = XStreamInitializer.getInstance(); | |||
this.xstream.processAnnotations(WxPaySendRedpackResult.class); | |||
} | |||
/** | |||
* Load success result. | |||
*/ | |||
@Test | |||
public void loadSuccessResult() { | |||
final String successSample = "<xml>\n" + | |||
@@ -37,6 +47,9 @@ public class WxPaySendRedpackResultTest { | |||
Assert.assertEquals("20150520102602", wxMpRedpackResult.getSendTime()); | |||
} | |||
/** | |||
* Load failure result. | |||
*/ | |||
@Test | |||
public void loadFailureResult() { | |||
final String failureSample = "<xml>\n" + | |||
@@ -14,6 +14,11 @@ import static org.testng.Assert.*; | |||
public class WxPayConfigTest { | |||
private WxPayConfig payConfig = new WxPayConfig(); | |||
/** | |||
* Test init ssl context. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testInitSSLContext() throws Exception { | |||
payConfig.setMchId("123"); | |||
@@ -68,6 +68,8 @@ public class BaseWxPayServiceImplTest { | |||
/** | |||
* Test method for {@link WxPayService#unifiedOrder(WxPayUnifiedOrderRequest)}. | |||
* | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
@Test | |||
public void testUnifiedOrder() throws WxPayException { | |||
@@ -86,11 +88,21 @@ public class BaseWxPayServiceImplTest { | |||
this.logger.warn(this.payService.getWxApiData().toString()); | |||
} | |||
/** | |||
* Test create order. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testCreateOrder() throws Exception { | |||
//see other tests with method name starting with 'testCreateOrder_' | |||
} | |||
/** | |||
* Test create order jsapi. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testCreateOrder_jsapi() throws Exception { | |||
WxPayMpOrderResult result = this.payService | |||
@@ -107,6 +119,11 @@ public class BaseWxPayServiceImplTest { | |||
this.logger.warn(this.payService.getWxApiData().toString()); | |||
} | |||
/** | |||
* Test create order app. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testCreateOrder_app() throws Exception { | |||
WxPayAppOrderResult result = this.payService | |||
@@ -122,6 +139,11 @@ public class BaseWxPayServiceImplTest { | |||
this.logger.warn(this.payService.getWxApiData().toString()); | |||
} | |||
/** | |||
* Test create order native. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testCreateOrder_native() throws Exception { | |||
WxPayNativeOrderResult result = this.payService | |||
@@ -138,6 +160,11 @@ public class BaseWxPayServiceImplTest { | |||
this.logger.warn(this.payService.getWxApiData().toString()); | |||
} | |||
/** | |||
* Test get pay info. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testGetPayInfo() throws Exception { | |||
//please use createOrder instead | |||
@@ -145,6 +172,8 @@ public class BaseWxPayServiceImplTest { | |||
/** | |||
* Test method for {@link WxPayService#queryOrder(String, String)} . | |||
* | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
@Test | |||
public void testQueryOrder() throws WxPayException { | |||
@@ -154,12 +183,19 @@ public class BaseWxPayServiceImplTest { | |||
/** | |||
* Test method for {@link WxPayService#closeOrder(String)} . | |||
* | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
@Test | |||
public void testCloseOrder() throws WxPayException { | |||
this.logger.info(this.payService.closeOrder("11212121").toString()); | |||
} | |||
/** | |||
* Billing data object [ ] [ ]. | |||
* | |||
* @return the object [ ] [ ] | |||
*/ | |||
@DataProvider | |||
public Object[][] billingData() { | |||
return new Object[][]{ | |||
@@ -174,6 +210,15 @@ public class BaseWxPayServiceImplTest { | |||
}; | |||
} | |||
/** | |||
* Test download bill. | |||
* | |||
* @param billDate the bill date | |||
* @param billType the bill type | |||
* @param tarType the tar type | |||
* @param deviceInfo the device info | |||
* @throws Exception the exception | |||
*/ | |||
@Test(dataProvider = "billingData") | |||
public void testDownloadBill(String billDate, String billType, | |||
String tarType, String deviceInfo) throws Exception { | |||
@@ -182,12 +227,22 @@ public class BaseWxPayServiceImplTest { | |||
this.logger.info(billResult.toString()); | |||
} | |||
/** | |||
* Test download bill with no params. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test(expectedExceptions = WxPayException.class) | |||
public void testDownloadBill_withNoParams() throws Exception { | |||
//必填字段为空时,抛出异常 | |||
this.payService.downloadBill("", "", "", null); | |||
} | |||
/** | |||
* Fund flow data object [ ] [ ]. | |||
* | |||
* @return the object [ ] [ ] | |||
*/ | |||
@DataProvider | |||
public Object[][] fundFlowData() { | |||
return new Object[][]{ | |||
@@ -200,6 +255,14 @@ public class BaseWxPayServiceImplTest { | |||
}; | |||
} | |||
/** | |||
* Test download fund flow. | |||
* | |||
* @param billDate the bill date | |||
* @param accountType the account type | |||
* @param tarType the tar type | |||
* @throws Exception the exception | |||
*/ | |||
@Test(dataProvider = "fundFlowData") | |||
public void testDownloadFundFlow(String billDate, String accountType, String tarType) throws Exception { | |||
WxPayFundFlowResult fundFlowResult = this.payService.downloadFundFlow(billDate, accountType, tarType); | |||
@@ -207,12 +270,22 @@ public class BaseWxPayServiceImplTest { | |||
this.logger.info(fundFlowResult.toString()); | |||
} | |||
/** | |||
* Test download fund flow with no params. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test(expectedExceptions = WxPayException.class) | |||
public void testDownloadFundFlow_withNoParams() throws Exception { | |||
//必填字段为空时,抛出异常 | |||
this.payService.downloadFundFlow("", "", null); | |||
} | |||
/** | |||
* Test report. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testReport() throws Exception { | |||
WxPayReportRequest request = new WxPayReportRequest(); | |||
@@ -227,6 +300,8 @@ public class BaseWxPayServiceImplTest { | |||
/** | |||
* Test method for {@link WxPayService#refund(WxPayRefundRequest)} . | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testRefund() throws Exception { | |||
@@ -242,6 +317,8 @@ public class BaseWxPayServiceImplTest { | |||
/** | |||
* Test method for {@link WxPayService#refundQuery(String, String, String, String)} . | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testRefundQuery() throws Exception { | |||
@@ -264,6 +341,11 @@ public class BaseWxPayServiceImplTest { | |||
this.logger.info(result.toString()); | |||
} | |||
/** | |||
* Test parse refund notify result. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testParseRefundNotifyResult() throws Exception { | |||
// 请参考com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResultTest里的单元测试 | |||
@@ -271,6 +353,8 @@ public class BaseWxPayServiceImplTest { | |||
/** | |||
* Test method for {@link WxPayService#sendRedpack(WxPaySendRedpackRequest)} . | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testSendRedpack() throws Exception { | |||
@@ -289,6 +373,8 @@ public class BaseWxPayServiceImplTest { | |||
/** | |||
* Test method for {@link WxPayService#queryRedpack(String)}. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testQueryRedpack() throws Exception { | |||
@@ -296,6 +382,11 @@ public class BaseWxPayServiceImplTest { | |||
this.logger.info(redpackResult.toString()); | |||
} | |||
/** | |||
* Test create scan pay qrcode mode 1. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testCreateScanPayQrcodeMode1() throws Exception { | |||
String productId = "abc"; | |||
@@ -309,6 +400,11 @@ public class BaseWxPayServiceImplTest { | |||
assertTrue(qrcodeContent.contains("product_id=" + productId)); | |||
} | |||
/** | |||
* Test create scan pay qrcode mode 2. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testCreateScanPayQrcodeMode2() throws Exception { | |||
String qrcodeContent = "abc"; | |||
@@ -318,6 +414,11 @@ public class BaseWxPayServiceImplTest { | |||
assertEquals(QrcodeUtils.decodeQrcode(qrcodeFilePath.toFile()), qrcodeContent); | |||
} | |||
/** | |||
* Test micropay. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testMicropay() throws Exception { | |||
WxPayMicropayResult result = this.payService.micropay( | |||
@@ -332,16 +433,31 @@ public class BaseWxPayServiceImplTest { | |||
this.logger.info(result.toString()); | |||
} | |||
/** | |||
* Test get config. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testGetConfig() throws Exception { | |||
// no need to test | |||
} | |||
/** | |||
* Test set config. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testSetConfig() throws Exception { | |||
// no need to test | |||
} | |||
/** | |||
* Test reverse order. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testReverseOrder() throws Exception { | |||
WxPayOrderReverseResult result = this.payService.reverseOrder( | |||
@@ -353,6 +469,11 @@ public class BaseWxPayServiceImplTest { | |||
this.logger.info(result.toString()); | |||
} | |||
/** | |||
* Test shorturl. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testShorturl() throws Exception { | |||
String longUrl = "weixin://wxpay/bizpayurl?sign=XXXXX&appid=XXXXX&mch_id=XXXXX&product_id=XXXXXX&time_stamp=XXXXXX&nonce_str=XXXXX"; | |||
@@ -366,6 +487,11 @@ public class BaseWxPayServiceImplTest { | |||
this.logger.info(result); | |||
} | |||
/** | |||
* Test authcode 2 openid. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testAuthcode2Openid() throws Exception { | |||
String authCode = "11111"; | |||
@@ -379,6 +505,11 @@ public class BaseWxPayServiceImplTest { | |||
this.logger.info(result); | |||
} | |||
/** | |||
* Test get sandbox sign key. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testGetSandboxSignKey() throws Exception { | |||
final String signKey = this.payService.getSandboxSignKey(); | |||
@@ -386,6 +517,11 @@ public class BaseWxPayServiceImplTest { | |||
this.logger.info(signKey); | |||
} | |||
/** | |||
* Test send coupon. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testSendCoupon() throws Exception { | |||
WxPayCouponSendResult result = this.payService.sendCoupon(WxPayCouponSendRequest.newBuilder() | |||
@@ -397,6 +533,11 @@ public class BaseWxPayServiceImplTest { | |||
this.logger.info(result.toString()); | |||
} | |||
/** | |||
* Test query coupon stock. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testQueryCouponStock() throws Exception { | |||
WxPayCouponStockQueryResult result = this.payService.queryCouponStock( | |||
@@ -407,6 +548,11 @@ public class BaseWxPayServiceImplTest { | |||
this.logger.info(result.toString()); | |||
} | |||
/** | |||
* Test query coupon info. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testQueryCouponInfo() throws Exception { | |||
WxPayCouponInfoQueryResult result = this.payService.queryCouponInfo( | |||
@@ -421,6 +567,8 @@ public class BaseWxPayServiceImplTest { | |||
/** | |||
* 只支持拉取90天内的评论数据 | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testQueryComment() throws Exception { | |||
@@ -434,7 +582,10 @@ public class BaseWxPayServiceImplTest { | |||
} | |||
/** | |||
* @see WxPayOrderNotifyResultTest#testFromXML() | |||
* Test parse order notify result. | |||
* | |||
* @throws Exception the exception | |||
* @see WxPayOrderNotifyResultTest#testFromXML() WxPayOrderNotifyResultTest#testFromXML() | |||
*/ | |||
@Test | |||
public void testParseOrderNotifyResult() throws Exception { | |||
@@ -471,6 +622,11 @@ public class BaseWxPayServiceImplTest { | |||
System.out.println(result); | |||
} | |||
/** | |||
* Test get wx api data. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testGetWxApiData() throws Exception { | |||
//see test in testUnifiedOrder() | |||
@@ -28,6 +28,11 @@ public class EntPayServiceImplTest { | |||
@Inject | |||
private WxPayService payService; | |||
/** | |||
* Test ent pay. | |||
* | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
@Test | |||
public void testEntPay() throws WxPayException { | |||
EntPayRequest request = EntPayRequest.newBuilder() | |||
@@ -42,16 +47,31 @@ public class EntPayServiceImplTest { | |||
this.logger.info(this.payService.getEntPayService().entPay(request).toString()); | |||
} | |||
/** | |||
* Test query ent pay. | |||
* | |||
* @throws WxPayException the wx pay exception | |||
*/ | |||
@Test | |||
public void testQueryEntPay() throws WxPayException { | |||
this.logger.info(this.payService.getEntPayService().queryEntPay("11212121").toString()); | |||
} | |||
/** | |||
* Test get public key. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testGetPublicKey() throws Exception { | |||
this.logger.info(this.payService.getEntPayService().getPublicKey()); | |||
} | |||
/** | |||
* Test pay bank. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testPayBank() throws Exception { | |||
EntPayBankResult result = this.payService.getEntPayService().payBank(EntPayBankRequest.builder() | |||
@@ -65,6 +85,11 @@ public class EntPayServiceImplTest { | |||
this.logger.info(result.toString()); | |||
} | |||
/** | |||
* Test query pay bank. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testQueryPayBank() throws Exception { | |||
this.logger.info(this.payService.getEntPayService().queryPayBank("123").toString()); | |||
@@ -14,6 +14,9 @@ import com.google.inject.Module; | |||
import com.thoughtworks.xstream.XStream; | |||
import me.chanjar.weixin.common.util.xml.XStreamInitializer; | |||
/** | |||
* The type Api test module. | |||
*/ | |||
public class ApiTestModule implements Module { | |||
private final Logger log = LoggerFactory.getLogger(this.getClass()); | |||
private static final String TEST_CONFIG_XML = "test-config.xml"; | |||
@@ -3,14 +3,27 @@ package com.github.binarywang.wxpay.testbase; | |||
import com.github.binarywang.wxpay.config.WxPayConfig; | |||
import com.thoughtworks.xstream.annotations.XStreamAlias; | |||
/** | |||
* The type Xml wx pay config. | |||
*/ | |||
@XStreamAlias("xml") | |||
public class XmlWxPayConfig extends WxPayConfig { | |||
private String openid; | |||
/** | |||
* Gets openid. | |||
* | |||
* @return the openid | |||
*/ | |||
public String getOpenid() { | |||
return openid; | |||
} | |||
/** | |||
* Sets openid. | |||
* | |||
* @param openid the openid | |||
*/ | |||
public void setOpenid(String openid) { | |||
this.openid = openid; | |||
} | |||
@@ -17,6 +17,11 @@ import static org.testng.Assert.*; | |||
* @author <a href="https://github.com/binarywang">Binary Wang</a> | |||
*/ | |||
public class SignUtilsTest { | |||
/** | |||
* Test create sign. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testCreateSign() throws Exception { | |||
String signKey = "192006250b4c09247ec02edce69f6a2d"; | |||
@@ -25,6 +30,11 @@ public class SignUtilsTest { | |||
"9A0A8659F005D6984697E2CA0A9CF3B7"); | |||
} | |||
/** | |||
* Test create sign hmacsha 256. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testCreateSign_HMACSHA256() throws Exception { | |||
String signKey = "192006250b4c09247ec02edce69f6a2d"; | |||
@@ -34,6 +44,11 @@ public class SignUtilsTest { | |||
assertEquals(sign, "6A9AE1657590FD6257D693A078E1C3E4BB6BA4DC30B23E0EE2496E54170DACD6"); | |||
} | |||
/** | |||
* Test check sign. | |||
* | |||
* @throws Exception the exception | |||
*/ | |||
@Test | |||
public void testCheckSign() throws Exception { | |||
} | |||