mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-10-31 10:38:42 +08:00 
			
		
		
		
	reformat code for PayService
This commit is contained in:
		| @ -30,9 +30,8 @@ public interface WxMpPayService { | |||||||
|    * 接口地址:https://api.mch.weixin.qq.com/pay/orderquery |    * 接口地址:https://api.mch.weixin.qq.com/pay/orderquery | ||||||
|    * </pre> |    * </pre> | ||||||
|    * |    * | ||||||
|    * @param transactionId 微信支付分配的商户号 |    * @param transactionId 微信订单号 | ||||||
|    * @param outTradeNo    商户系统内部的订单号,当没提供transaction_id时需要传这个。 |    * @param outTradeNo    商户系统内部的订单号,当没提供transaction_id时需要传这个。 | ||||||
|    * @throws WxErrorException |  | ||||||
|    */ |    */ | ||||||
|   WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) throws WxErrorException; |   WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) throws WxErrorException; | ||||||
|  |  | ||||||
| @ -49,7 +48,6 @@ public interface WxMpPayService { | |||||||
|    * </pre> |    * </pre> | ||||||
|    * |    * | ||||||
|    * @param outTradeNo 商户系统内部的订单号,当没提供transaction_id时需要传这个。 |    * @param outTradeNo 商户系统内部的订单号,当没提供transaction_id时需要传这个。 | ||||||
|    * @throws WxErrorException |  | ||||||
|    */ |    */ | ||||||
|   WxPayOrderCloseResult closeOrder(String outTradeNo) throws WxErrorException; |   WxPayOrderCloseResult closeOrder(String outTradeNo) throws WxErrorException; | ||||||
|  |  | ||||||
| @ -59,7 +57,6 @@ public interface WxMpPayService { | |||||||
|    * 接口地址:https://api.mch.weixin.qq.com/pay/unifiedorder |    * 接口地址:https://api.mch.weixin.qq.com/pay/unifiedorder | ||||||
|    * |    * | ||||||
|    * @param request 请求对象,注意一些参数如appid、mchid等不用设置,方法内会自动从配置对象中获取到(前提是对应配置中已经设置) |    * @param request 请求对象,注意一些参数如appid、mchid等不用设置,方法内会自动从配置对象中获取到(前提是对应配置中已经设置) | ||||||
|    * @throws WxErrorException |  | ||||||
|    */ |    */ | ||||||
|   WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request) throws WxErrorException; |   WxPayUnifiedOrderResult unifiedOrder(WxPayUnifiedOrderRequest request) throws WxErrorException; | ||||||
|  |  | ||||||
| @ -68,7 +65,6 @@ 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 请求对象,注意一些参数如appid、mchid等不用设置,方法内会自动从配置对象中获取到(前提是对应配置中已经设置) |    * @param request 请求对象,注意一些参数如appid、mchid等不用设置,方法内会自动从配置对象中获取到(前提是对应配置中已经设置) | ||||||
|    * @throws WxErrorException |  | ||||||
|    */ |    */ | ||||||
|   Map<String, String> getPayInfo(WxPayUnifiedOrderRequest request) throws WxErrorException; |   Map<String, String> getPayInfo(WxPayUnifiedOrderRequest request) throws WxErrorException; | ||||||
|  |  | ||||||
| @ -93,7 +89,8 @@ public interface WxMpPayService { | |||||||
|    * 详见 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_5 |    * 详见 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_5 | ||||||
|    * 接口链接:https://api.mch.weixin.qq.com/pay/refundquery |    * 接口链接:https://api.mch.weixin.qq.com/pay/refundquery | ||||||
|    * </pre> |    * </pre> | ||||||
|    *  以下四个参数四选一 |    * 以下四个参数四选一 | ||||||
|  |    * | ||||||
|    * @param transactionId 微信订单号 |    * @param transactionId 微信订单号 | ||||||
|    * @param outTradeNo    商户订单号 |    * @param outTradeNo    商户订单号 | ||||||
|    * @param outRefundNo   商户退款单号 |    * @param outRefundNo   商户退款单号 | ||||||
| @ -107,81 +104,85 @@ public interface WxMpPayService { | |||||||
|    * 详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7 |    * 详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_7 | ||||||
|    */ |    */ | ||||||
|   WxPayOrderNotifyResult getOrderNotifyResult(String xmlData) throws WxErrorException; |   WxPayOrderNotifyResult getOrderNotifyResult(String xmlData) throws WxErrorException; | ||||||
|    |  | ||||||
|   /** |   /** | ||||||
|    * 微信公众号支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3) |    * 微信公众号支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3) | ||||||
|    * |    * | ||||||
|    * @param xmlbean Bean需要标记有XML注解,默认使用配置中的PartnerKey进行签名 |    * @param xmlbean Bean需要标记有XML注解,默认使用配置中的PartnerKey进行签名 | ||||||
|    * @since 2.5.0 |  | ||||||
|    * @return 签名字符串 |    * @return 签名字符串 | ||||||
|    * @see #createSign(Map, String) |    * @see #createSign(Map, String) | ||||||
|  |    * @since 2.5.0 | ||||||
|    */ |    */ | ||||||
|   String createSign(Object xmlbean); |   String createSign(Object xmlbean); | ||||||
|    |  | ||||||
|   /** |   /** | ||||||
|    * 微信公众号支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3) |    * 微信公众号支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3) | ||||||
|    * @param xmlbean  Bean需要标记有XML注解 |    * | ||||||
|  |    * @param xmlbean Bean需要标记有XML注解 | ||||||
|    * @param signKey 签名Key |    * @param signKey 签名Key | ||||||
|    * @return 签名字符串 |    * @return 签名字符串 | ||||||
|    * @see #createSign(Map, String) |    * @see #createSign(Map, String) | ||||||
|    */ |    */ | ||||||
|   String createSign(Object xmlbean, String signKey); |   String createSign(Object xmlbean, String signKey); | ||||||
|    |  | ||||||
|   /** |   /** | ||||||
|    * 微信公众号支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3) |    * 微信公众号支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3) | ||||||
|    * @param prams 参数信息,默认使用配置中的PartnerKey进行签名 |    * | ||||||
|    * @param signKey 签名Key |    * @param prams   参数信息,默认使用配置中的PartnerKey进行签名 | ||||||
|    * @return 签名字符串 |    * @return 签名字符串 | ||||||
|    * @see #createSign(Map, String) |    * @see #createSign(Map, String) | ||||||
|    */ |    */ | ||||||
|   String createSign(Map<String, String> prams); |   String createSign(Map<String, String> prams); | ||||||
|    |  | ||||||
|    |  | ||||||
|   /** |   /** | ||||||
|    * 微信公众号支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3) |    * 微信公众号支付签名算法(详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3) | ||||||
|    * @param prams  参数信息 |    * | ||||||
|  |    * @param prams   参数信息 | ||||||
|    * @param signKey 签名Key |    * @param signKey 签名Key | ||||||
|    * @return 签名字符串 |    * @return 签名字符串 | ||||||
|    */ |    */ | ||||||
|   String createSign(Map<String, String> prams, String signKey); |   String createSign(Map<String, String> prams, String signKey); | ||||||
|  |  | ||||||
|    |  | ||||||
|    |  | ||||||
|   /** |   /** | ||||||
|    * 校验签名是否正确,默认使用配置中的PartnerKey进行签名 |    * 校验签名是否正确,默认使用配置中的PartnerKey进行签名 | ||||||
|  |    * | ||||||
|    * @param xmlbean Bean需要标记有XML注解 |    * @param xmlbean Bean需要标记有XML注解 | ||||||
|    * @return true - 签名校验成功,false - 签名校验失败 |    * @return true - 签名校验成功,false - 签名校验失败 | ||||||
|    * @see #checkSign(Map, String) |    * @see #checkSign(Map, String) | ||||||
|    */ |    */ | ||||||
|   boolean checkSign(Object xmlbean); |   boolean checkSign(Object xmlbean); | ||||||
|    |  | ||||||
|   /** |   /** | ||||||
|    * 校验签名是否正确 |    * 校验签名是否正确 | ||||||
|  |    * | ||||||
|    * @param xmlbean Bean需要标记有XML注解 |    * @param xmlbean Bean需要标记有XML注解 | ||||||
|    * @param signKey  校验的签名Key |    * @param signKey 校验的签名Key | ||||||
|    * @return true - 签名校验成功,false - 签名校验失败 |    * @return true - 签名校验成功,false - 签名校验失败 | ||||||
|    * @see #checkSign(Map, String) |    * @see #checkSign(Map, String) | ||||||
|    */ |    */ | ||||||
|   boolean checkSign(Object xmlbean, String signKey); |   boolean checkSign(Object xmlbean, String signKey); | ||||||
|   |  | ||||||
|   /** |   /** | ||||||
|    * 校验签名是否正确,默认使用配置中的PartnerKey进行签名 |    * 校验签名是否正确,默认使用配置中的PartnerKey进行签名 | ||||||
|  |    * | ||||||
|    * @param prams 需要校验的参数Map |    * @param prams 需要校验的参数Map | ||||||
|    * @return true - 签名校验成功,false - 签名校验失败 |    * @return true - 签名校验成功,false - 签名校验失败 | ||||||
|    * @see #checkSign(Map, String) |    * @see #checkSign(Map, String) | ||||||
|    */ |    */ | ||||||
|   boolean checkSign(Map<String, String> prams); |   boolean checkSign(Map<String, String> prams); | ||||||
|    |  | ||||||
|   /** |   /** | ||||||
|    * 校验签名是否正确 |    * 校验签名是否正确 | ||||||
|    * @param prams 需要校验的参数Map |    * | ||||||
|    * @param signKey  校验的签名Key |    * @param params   需要校验的参数Map | ||||||
|  |    * @param signKey 校验的签名Key | ||||||
|    * @return true - 签名校验成功,false - 签名校验失败 |    * @return true - 签名校验成功,false - 签名校验失败 | ||||||
|    * @see #checkSign(Map, String) |    * @see #checkSign(Map, String) | ||||||
|    */ |    */ | ||||||
|   boolean checkSign(Map<String, String> prams, String signKey); |   boolean checkSign(Map<String, String> params, String signKey); | ||||||
|    |  | ||||||
|    |  | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * 发送微信红包给个人用户 |    * 发送微信红包给个人用户 | ||||||
| @ -206,8 +207,9 @@ public interface WxMpPayService { | |||||||
|    *   是否需要证书	是(证书及使用说明详见商户证书) |    *   是否需要证书	是(证书及使用说明详见商户证书) | ||||||
|    *   请求方式	POST |    *   请求方式	POST | ||||||
|    * </pre> |    * </pre> | ||||||
|  |    * | ||||||
|    * @param mchBillNo 商户发放红包的商户订单号,比如10000098201411111234567890 |    * @param mchBillNo 商户发放红包的商户订单号,比如10000098201411111234567890 | ||||||
|    * @param keyFile 证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3) |    * @param keyFile   证书文件对象(即apiclient_cert.p12 商户证书文件,详细参考https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=4_3) | ||||||
|    */ |    */ | ||||||
|   WxPayRedpackQueryResult queryRedpack(String mchBillNo, File keyFile) throws WxErrorException; |   WxPayRedpackQueryResult queryRedpack(String mchBillNo, File keyFile) throws WxErrorException; | ||||||
|  |  | ||||||
|  | |||||||
| @ -1,17 +1,16 @@ | |||||||
| package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||||
|  |  | ||||||
| import java.io.File; | import com.thoughtworks.xstream.XStream; | ||||||
| import java.io.FileInputStream; | import me.chanjar.weixin.common.bean.result.WxError; | ||||||
| import java.io.IOException; | import me.chanjar.weixin.common.exception.WxErrorException; | ||||||
| import java.security.KeyStore; | import me.chanjar.weixin.common.util.BeanUtils; | ||||||
| import java.util.Arrays; | import me.chanjar.weixin.common.util.xml.XStreamInitializer; | ||||||
| import java.util.HashMap; | import me.chanjar.weixin.mp.api.WxMpConfigStorage; | ||||||
| import java.util.Map; | import me.chanjar.weixin.mp.api.WxMpPayService; | ||||||
| import java.util.SortedMap; | import me.chanjar.weixin.mp.api.WxMpService; | ||||||
| import java.util.TreeMap; | import me.chanjar.weixin.mp.bean.pay.WxPayOrderNotifyResultConverter; | ||||||
|  | import me.chanjar.weixin.mp.bean.pay.request.*; | ||||||
| import javax.net.ssl.SSLContext; | import me.chanjar.weixin.mp.bean.pay.result.*; | ||||||
|  |  | ||||||
| import org.apache.commons.codec.digest.DigestUtils; | import org.apache.commons.codec.digest.DigestUtils; | ||||||
| import org.apache.commons.lang3.ArrayUtils; | import org.apache.commons.lang3.ArrayUtils; | ||||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||||
| @ -29,36 +28,12 @@ import org.apache.http.util.EntityUtils; | |||||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||||
|  |  | ||||||
| import com.thoughtworks.xstream.XStream; | import javax.net.ssl.SSLContext; | ||||||
|  | import java.io.File; | ||||||
| import me.chanjar.weixin.common.bean.result.WxError; | import java.io.FileInputStream; | ||||||
| import me.chanjar.weixin.common.exception.WxErrorException; | import java.io.IOException; | ||||||
| import me.chanjar.weixin.common.util.BeanUtils; | import java.security.KeyStore; | ||||||
| import me.chanjar.weixin.common.util.xml.XStreamInitializer; | import java.util.*; | ||||||
| import me.chanjar.weixin.mp.api.WxMpConfigStorage; |  | ||||||
| import me.chanjar.weixin.mp.api.WxMpPayService; |  | ||||||
| import me.chanjar.weixin.mp.api.WxMpService; |  | ||||||
| import me.chanjar.weixin.mp.bean.pay.WxPayOrderNotifyResultConverter; |  | ||||||
| import me.chanjar.weixin.mp.bean.pay.request.WxEntPayQueryRequest; |  | ||||||
| import me.chanjar.weixin.mp.bean.pay.request.WxEntPayRequest; |  | ||||||
| import me.chanjar.weixin.mp.bean.pay.request.WxPayOrderCloseRequest; |  | ||||||
| import me.chanjar.weixin.mp.bean.pay.request.WxPayOrderQueryRequest; |  | ||||||
| import me.chanjar.weixin.mp.bean.pay.request.WxPayRedpackQueryRequest; |  | ||||||
| import me.chanjar.weixin.mp.bean.pay.request.WxPayRefundQueryRequest; |  | ||||||
| import me.chanjar.weixin.mp.bean.pay.request.WxPayRefundRequest; |  | ||||||
| import me.chanjar.weixin.mp.bean.pay.request.WxPaySendRedpackRequest; |  | ||||||
| import me.chanjar.weixin.mp.bean.pay.request.WxPayUnifiedOrderRequest; |  | ||||||
| import me.chanjar.weixin.mp.bean.pay.result.WxEntPayQueryResult; |  | ||||||
| import me.chanjar.weixin.mp.bean.pay.result.WxEntPayResult; |  | ||||||
| import me.chanjar.weixin.mp.bean.pay.result.WxPayBaseResult; |  | ||||||
| import me.chanjar.weixin.mp.bean.pay.result.WxPayOrderCloseResult; |  | ||||||
| import me.chanjar.weixin.mp.bean.pay.result.WxPayOrderNotifyResult; |  | ||||||
| import me.chanjar.weixin.mp.bean.pay.result.WxPayOrderQueryResult; |  | ||||||
| import me.chanjar.weixin.mp.bean.pay.result.WxPayRedpackQueryResult; |  | ||||||
| import me.chanjar.weixin.mp.bean.pay.result.WxPayRefundQueryResult; |  | ||||||
| import me.chanjar.weixin.mp.bean.pay.result.WxPayRefundResult; |  | ||||||
| import me.chanjar.weixin.mp.bean.pay.result.WxPaySendRedpackResult; |  | ||||||
| import me.chanjar.weixin.mp.bean.pay.result.WxPayUnifiedOrderResult; |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Created by Binary Wang on 2016/7/28. |  * Created by Binary Wang on 2016/7/28. | ||||||
| @ -71,16 +46,16 @@ public class WxMpPayServiceImpl implements WxMpPayService { | |||||||
|   private static final String[] TRADE_TYPES = new String[]{"JSAPI", "NATIVE", "APP"}; |   private static final String[] TRADE_TYPES = new String[]{"JSAPI", "NATIVE", "APP"}; | ||||||
|   private static final String[] REFUND_ACCOUNT = new String[]{"REFUND_SOURCE_RECHARGE_FUNDS", |   private static final String[] REFUND_ACCOUNT = new String[]{"REFUND_SOURCE_RECHARGE_FUNDS", | ||||||
|     "REFUND_SOURCE_UNSETTLED_FUNDS"}; |     "REFUND_SOURCE_UNSETTLED_FUNDS"}; | ||||||
|   protected final Logger log = LoggerFactory.getLogger(this.getClass()); |   private final Logger log = LoggerFactory.getLogger(this.getClass()); | ||||||
|   private WxMpService wxMpService; |   private WxMpService wxMpService; | ||||||
|   private WxMpConfigStorage config = null; |   private WxMpConfigStorage config = null; | ||||||
|  |  | ||||||
|   public WxMpPayServiceImpl(WxMpService wxMpService) { |   public WxMpPayServiceImpl(WxMpService wxMpService) { | ||||||
|     this.wxMpService = wxMpService; |     this.wxMpService = wxMpService; | ||||||
|   } |   } | ||||||
|    |  | ||||||
|   private WxMpConfigStorage getConfig(){ |   private WxMpConfigStorage getConfig() { | ||||||
|     if(config == null){ |     if (config == null) { | ||||||
|       this.config = wxMpService.getWxMpConfigStorage(); |       this.config = wxMpService.getWxMpConfigStorage(); | ||||||
|     } |     } | ||||||
|     return this.config; |     return this.config; | ||||||
| @ -139,24 +114,24 @@ public class WxMpPayServiceImpl implements WxMpPayService { | |||||||
|     this.checkResult(result); |     this.checkResult(result); | ||||||
|     return result; |     return result; | ||||||
|   } |   } | ||||||
|    |  | ||||||
|  |  | ||||||
|   private void checkResult(WxPayBaseResult result) throws WxErrorException { |   private void checkResult(WxPayBaseResult result) throws WxErrorException { | ||||||
|   	//校验返回结果签名 |     //校验返回结果签名 | ||||||
|   	if(!checkSign(result.toMap())){ |     if (!checkSign(result.toMap())) { | ||||||
|   	  log.debug("校验结果签名失败,参数:{}",result.toMap()); |       log.debug("校验结果签名失败,参数:{}", result.toMap()); | ||||||
|   		throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("参数格式校验错误!").build()); |       throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg("参数格式校验错误!").build()); | ||||||
|   	} |     } | ||||||
|   	 |  | ||||||
|   	//校验结果是否成功 |     //校验结果是否成功 | ||||||
|     if (!"SUCCESS".equalsIgnoreCase(result.getReturnCode()) |     if (!"SUCCESS".equalsIgnoreCase(result.getReturnCode()) | ||||||
|       || !"SUCCESS".equalsIgnoreCase(result.getResultCode())) { |       || !"SUCCESS".equalsIgnoreCase(result.getResultCode())) { | ||||||
|       WxError error = WxError.newBuilder().setErrorCode(-1) |       WxError error = WxError.newBuilder().setErrorCode(-1) | ||||||
|       .setErrorMsg("返回代码: " + result.getReturnCode() + ", 返回信息: " |         .setErrorMsg("返回代码: " + result.getReturnCode() + ", 返回信息: " | ||||||
|         + result.getReturnMsg() + ", 结果代码: " + result.getResultCode() + ", 错误代码: " |           + result.getReturnMsg() + ", 结果代码: " + result.getResultCode() + ", 错误代码: " | ||||||
|         + result.getErrCode() + ", 错误详情: " + result.getErrCodeDes()) |           + result.getErrCode() + ", 错误详情: " + result.getErrCodeDes()) | ||||||
|       .build(); |         .build(); | ||||||
|       log.debug("结果校验失败,参数:{},详细:{}",result.toMap(),error); |       log.debug("结果校验失败,参数:{},详细:{}", result.toMap(), error); | ||||||
|       throw new WxErrorException(error); |       throw new WxErrorException(error); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| @ -166,7 +141,7 @@ public class WxMpPayServiceImpl implements WxMpPayService { | |||||||
|  |  | ||||||
|     if (StringUtils.isNotBlank(request.getRefundAccount())) { |     if (StringUtils.isNotBlank(request.getRefundAccount())) { | ||||||
|       if (!ArrayUtils.contains(REFUND_ACCOUNT, request.getRefundAccount())) { |       if (!ArrayUtils.contains(REFUND_ACCOUNT, request.getRefundAccount())) { | ||||||
|         throw new IllegalArgumentException("refund_account目前必须为" + Arrays.toString(REFUND_ACCOUNT) + "其中之一,实际值:"+ request.getRefundAccount()); |         throw new IllegalArgumentException("refund_account目前必须为" + Arrays.toString(REFUND_ACCOUNT) + "其中之一,实际值:" + request.getRefundAccount()); | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @ -181,16 +156,16 @@ public class WxMpPayServiceImpl implements WxMpPayService { | |||||||
|       log.trace("微信支付回调参数详细:{}", xmlData); |       log.trace("微信支付回调参数详细:{}", xmlData); | ||||||
|       XStream xstream = XStreamInitializer.getInstance(); |       XStream xstream = XStreamInitializer.getInstance(); | ||||||
|       xstream.processAnnotations(WxPayOrderNotifyResult.class); |       xstream.processAnnotations(WxPayOrderNotifyResult.class); | ||||||
|   		xstream.registerConverter(new WxPayOrderNotifyResultConverter(xstream.getMapper(),xstream.getReflectionProvider())); |       xstream.registerConverter(new WxPayOrderNotifyResultConverter(xstream.getMapper(), xstream.getReflectionProvider())); | ||||||
|   		WxPayOrderNotifyResult result = (WxPayOrderNotifyResult) xstream.fromXML(xmlData); |       WxPayOrderNotifyResult result = (WxPayOrderNotifyResult) xstream.fromXML(xmlData); | ||||||
|   		log.debug("微信支付回调结果对象:{}",result); |       log.debug("微信支付回调结果对象:{}", result); | ||||||
|   		this.checkResult(result); |       this.checkResult(result); | ||||||
|   		return result; |       return result; | ||||||
|     }catch (WxErrorException e) { |     } catch (WxErrorException e) { | ||||||
|     	log.error(e.getMessage(),e); |       log.error(e.getMessage(), e); | ||||||
|     	throw e; |       throw e; | ||||||
| 		}catch (Exception e) { |     } catch (Exception e) { | ||||||
|     	log.error(e.getMessage(),e); |       log.error(e.getMessage(), e); | ||||||
|       throw new WxErrorException(WxError.newBuilder().setErrorMsg("发生异常" + e.getMessage()).build()); |       throw new WxErrorException(WxError.newBuilder().setErrorMsg("发生异常" + e.getMessage()).build()); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| @ -245,20 +220,20 @@ public class WxMpPayServiceImpl implements WxMpPayService { | |||||||
|     this.checkResult(result); |     this.checkResult(result); | ||||||
|     return result; |     return result; | ||||||
|   } |   } | ||||||
|    |  | ||||||
|   @Override |   @Override | ||||||
|   public String createSign(Object xmlBean) { |   public String createSign(Object xmlBean) { | ||||||
|   	return createSign(BeanUtils.xmlBean2Map(xmlBean),getConfig().getPartnerKey()); |     return createSign(BeanUtils.xmlBean2Map(xmlBean), getConfig().getPartnerKey()); | ||||||
|   } |   } | ||||||
|    |  | ||||||
|   @Override |   @Override | ||||||
|   public String createSign(Object xmlBean, String signKey) { |   public String createSign(Object xmlBean, String signKey) { | ||||||
|   	return createSign(BeanUtils.xmlBean2Map(xmlBean), signKey); |     return createSign(BeanUtils.xmlBean2Map(xmlBean), signKey); | ||||||
|   } |   } | ||||||
|    |  | ||||||
|   @Override |   @Override | ||||||
|   public String createSign(Map<String, String> params) { |   public String createSign(Map<String, String> params) { | ||||||
|   	return createSign(params,getConfig().getPartnerKey()); |     return createSign(params, getConfig().getPartnerKey()); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   @Override |   @Override | ||||||
| @ -276,28 +251,28 @@ public class WxMpPayServiceImpl implements WxMpPayService { | |||||||
|     toSign.append("key=" + signKey); |     toSign.append("key=" + signKey); | ||||||
|     return DigestUtils.md5Hex(toSign.toString()).toUpperCase(); |     return DigestUtils.md5Hex(toSign.toString()).toUpperCase(); | ||||||
|   } |   } | ||||||
|    |  | ||||||
|   @Override |   @Override | ||||||
|   public boolean checkSign(Object xmlBean) { |   public boolean checkSign(Object xmlBean) { | ||||||
|     return checkSign(BeanUtils.xmlBean2Map(xmlBean) , getConfig().getPartnerKey()); |     return checkSign(BeanUtils.xmlBean2Map(xmlBean), getConfig().getPartnerKey()); | ||||||
|   } |   } | ||||||
|    |  | ||||||
|   @Override |   @Override | ||||||
|   public boolean checkSign(Object xmlBean, String signKey) { |   public boolean checkSign(Object xmlBean, String signKey) { | ||||||
|     return checkSign(BeanUtils.xmlBean2Map(xmlBean) , signKey); |     return checkSign(BeanUtils.xmlBean2Map(xmlBean), signKey); | ||||||
|   } |   } | ||||||
|    |  | ||||||
|   @Override |   @Override | ||||||
|   public boolean checkSign(Map<String, String> params) { |   public boolean checkSign(Map<String, String> params) { | ||||||
|     return checkSign(params , getConfig().getPartnerKey()); |     return checkSign(params, getConfig().getPartnerKey()); | ||||||
|   } |   } | ||||||
|    |  | ||||||
|   @Override |   @Override | ||||||
|   public boolean checkSign(Map<String, String> params, String signKey) { |   public boolean checkSign(Map<String, String> params, String signKey) { | ||||||
|   	String sign = this.createSign(params , signKey); |     String sign = this.createSign(params, signKey); | ||||||
|     return sign.equals(params.get("sign")); |     return sign.equals(params.get("sign")); | ||||||
|   } |   } | ||||||
|    |  | ||||||
|  |  | ||||||
|   @Override |   @Override | ||||||
|   public WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) throws WxErrorException { |   public WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo) throws WxErrorException { | ||||||
| @ -366,16 +341,16 @@ public class WxMpPayServiceImpl implements WxMpPayService { | |||||||
|     request.setNotifyURL(getConfig().getNotifyURL()); |     request.setNotifyURL(getConfig().getNotifyURL()); | ||||||
|     request.setTradeType(getConfig().getTradeType()); |     request.setTradeType(getConfig().getTradeType()); | ||||||
|     request.setNonceStr(System.currentTimeMillis() + ""); |     request.setNonceStr(System.currentTimeMillis() + ""); | ||||||
|      |  | ||||||
|     checkParameters(request);//校验参数 |     checkParameters(request);//校验参数 | ||||||
|      |  | ||||||
|     request.setSign(this.createSign(request)); |     request.setSign(this.createSign(request)); | ||||||
|     String url = PAY_BASE_URL + "/pay/unifiedorder"; |     String url = PAY_BASE_URL + "/pay/unifiedorder"; | ||||||
|     String xmlParam =  xstream.toXML(request); |     String xmlParam = xstream.toXML(request); | ||||||
|     log.debug("微信统一下单接口,URL:{},参数:{}",url, xmlParam); |     log.debug("微信统一下单接口,URL:{},参数:{}", url, xmlParam); | ||||||
|  |  | ||||||
|     String responseContent = this.executeRequest(url, xmlParam); |     String responseContent = this.executeRequest(url, xmlParam); | ||||||
|     log.debug("微信统一下单接口,URL:{},结果:{}",url, responseContent); |     log.debug("微信统一下单接口,URL:{},结果:{}", url, responseContent); | ||||||
|     WxPayUnifiedOrderResult result = (WxPayUnifiedOrderResult) xstream.fromXML(responseContent); |     WxPayUnifiedOrderResult result = (WxPayUnifiedOrderResult) xstream.fromXML(responseContent); | ||||||
|     this.checkResult(result); |     this.checkResult(result); | ||||||
|     return result; |     return result; | ||||||
| @ -385,7 +360,7 @@ public class WxMpPayServiceImpl implements WxMpPayService { | |||||||
|     BeanUtils.checkRequiredFields(request); |     BeanUtils.checkRequiredFields(request); | ||||||
|  |  | ||||||
|     if (!ArrayUtils.contains(TRADE_TYPES, request.getTradeType())) { |     if (!ArrayUtils.contains(TRADE_TYPES, request.getTradeType())) { | ||||||
|       throw new IllegalArgumentException("trade_type目前必须为" + Arrays.toString(TRADE_TYPES) + "其中之一,实际值:"+request.getTradeType()); |       throw new IllegalArgumentException("trade_type目前必须为" + Arrays.toString(TRADE_TYPES) + "其中之一,实际值:" + request.getTradeType()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     if ("JSAPI".equals(request.getTradeType()) && request.getOpenid() == null) { |     if ("JSAPI".equals(request.getTradeType()) && request.getOpenid() == null) { | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Binary Wang
					Binary Wang