|
@@ -1,61 +0,0 @@
|
|
|
-package com.bosshand.virgo.api.workark.service;
|
|
|
-
|
|
|
-import com.bosshand.virgo.api.workark.util.WeChatUtil;
|
|
|
-import com.wechat.pay.java.core.exception.ValidationException;
|
|
|
-import com.wechat.pay.java.core.notification.NotificationParser;
|
|
|
-import com.wechat.pay.java.service.payments.model.Transaction;
|
|
|
-import com.wechat.pay.java.service.refund.model.RefundNotification;
|
|
|
-import org.apache.commons.logging.Log;
|
|
|
-import org.apache.commons.logging.LogFactory;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-
|
|
|
-import javax.annotation.Resource;
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.io.IOException;
|
|
|
-
|
|
|
-@Service
|
|
|
-public class WechatPayValidatorForRequest {
|
|
|
-
|
|
|
- private final static Log log = LogFactory.getLog(WechatPayValidatorForRequest.class);
|
|
|
-
|
|
|
- @Resource
|
|
|
- private NotificationParser notificationParser;
|
|
|
-
|
|
|
- public boolean payNotify(HttpServletRequest request) {
|
|
|
- log.info("签名验证");
|
|
|
- Transaction transaction;
|
|
|
- try {
|
|
|
- transaction = notificationParser.parse(WeChatUtil.handleNodifyRequestParam(request), Transaction.class);
|
|
|
- log.info("state: " + transaction.getTradeState());
|
|
|
- if (transaction.getTradeState() == Transaction.TradeStateEnum.SUCCESS){
|
|
|
- log.info("签名验证成功");
|
|
|
- return true;
|
|
|
- }
|
|
|
- log.info("签名验证失败");
|
|
|
- return false;
|
|
|
- } catch (ValidationException | IOException e) {
|
|
|
- // 签名验证失败
|
|
|
- log.error("签名验证失败: " + e);
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public boolean refundNotify(HttpServletRequest request) {
|
|
|
- log.info("通知验签");
|
|
|
- try {
|
|
|
- RefundNotification parse = notificationParser.parse(WeChatUtil.handleNodifyRequestParam(request), RefundNotification.class);
|
|
|
- if ("SUCCESS".equals(parse.getRefundStatus())){
|
|
|
- log.info("通知验签成功");
|
|
|
- return true;
|
|
|
- }
|
|
|
- log.info("通知验签失败");
|
|
|
- return false;
|
|
|
- } catch (IOException e) {
|
|
|
- // 通知验签失败
|
|
|
- log.error("通知验签失败: " + e);
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-}
|