|
|
package com.yohoufo.order.controller;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.io.PrintWriter;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
import com.yohobuy.ufo.model.order.req.ManualDealRequest;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
...
|
...
|
@@ -17,6 +19,7 @@ import org.springframework.web.bind.annotation.RequestParam; |
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yohobuy.ufo.model.order.req.ManualDealRequest;
|
|
|
import com.yohoufo.common.ApiResponse;
|
|
|
import com.yohoufo.common.annotation.IgnoreSession;
|
|
|
import com.yohoufo.common.annotation.IgnoreSignature;
|
...
|
...
|
@@ -26,7 +29,6 @@ import com.yohoufo.order.model.NotifyResponse; |
|
|
import com.yohoufo.order.model.PayRefundBo;
|
|
|
import com.yohoufo.order.model.PaymentData;
|
|
|
import com.yohoufo.order.model.request.PaymentRequest;
|
|
|
import com.yohoufo.order.model.request.TransferMoneyRequest;
|
|
|
import com.yohoufo.order.model.response.PaymentConfirmRsp;
|
|
|
import com.yohoufo.order.model.response.PrepayResponse;
|
|
|
import com.yohoufo.order.service.IPaymentService;
|
...
|
...
|
@@ -127,22 +129,23 @@ public class PaymentController { |
|
|
* 微信支付 回调接口
|
|
|
* @param request
|
|
|
* @return
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
@IgnoreSignature
|
|
|
@IgnoreSession
|
|
|
@RequestMapping(value = "/ufo_wechat_notify", method = RequestMethod.POST)
|
|
|
public NotifyResponse notifyWeixinPayment(HttpServletRequest request) {
|
|
|
public void notifyWeixinPayment(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
wechatLogger.info("\n\n\n************************* Notify");
|
|
|
|
|
|
NotifyResponse response = new NotifyResponse(); //忽略,即成功
|
|
|
NotifyResponse notifyResponse = new NotifyResponse(); //忽略,即成功
|
|
|
|
|
|
String nofityBody = null;
|
|
|
try{
|
|
|
nofityBody = WXUtil.getWXPayRequestBody(request);
|
|
|
}catch(Exception e){
|
|
|
wechatLogger.error("get notify request failed: {}", e);
|
|
|
response.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_FAILED);
|
|
|
return response;
|
|
|
notifyResponse.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_FAILED);
|
|
|
return ;
|
|
|
}
|
|
|
|
|
|
wechatLogger.info("notify params: {}", nofityBody);
|
...
|
...
|
@@ -150,15 +153,15 @@ public class PaymentController { |
|
|
Map<String, String> params = WXUtil.parseWXPayXml(nofityBody);
|
|
|
if(params == null || params.size() == 0){
|
|
|
wechatLogger.error("parse notify request failed");
|
|
|
response.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_FAILED);
|
|
|
return response;
|
|
|
notifyResponse.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_FAILED);
|
|
|
return ;
|
|
|
}
|
|
|
|
|
|
String returnCode = params.get(RETURN_CODE);
|
|
|
if(!PREPAY_RESULT_SUCCESS.equals(returnCode)){
|
|
|
wechatLogger.error("Weixin pay notify returnCode error: {}", nofityBody);
|
|
|
response.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_FAILED);
|
|
|
return response;
|
|
|
notifyResponse.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_FAILED);
|
|
|
return ;
|
|
|
}
|
|
|
|
|
|
String out_trade_no = params.get("out_trade_no");
|
...
|
...
|
@@ -166,9 +169,9 @@ public class PaymentController { |
|
|
|
|
|
//回调验证
|
|
|
if(!weixinPayAppService.notifyVerify(params)) {
|
|
|
response.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_VERFAIL);
|
|
|
notifyResponse.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_VERFAIL);
|
|
|
wechatLogger.error("[{}] notification verify failed", out_trade_no);
|
|
|
return response;
|
|
|
return ;
|
|
|
}
|
|
|
|
|
|
PaymentData paymentData = null;
|
...
|
...
|
@@ -179,14 +182,22 @@ public class PaymentController { |
|
|
paymentService.paySuccess(paymentData);
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
response.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_FAILED);
|
|
|
notifyResponse.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_FAILED);
|
|
|
wechatLogger.error("[{}] notify process failed, ex: {}", out_trade_no, e);
|
|
|
return response;
|
|
|
return ;
|
|
|
}
|
|
|
|
|
|
response.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_SUCCESS);
|
|
|
response.setPaymentData(paymentData);
|
|
|
return response;
|
|
|
notifyResponse.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_SUCCESS);
|
|
|
notifyResponse.setPaymentData(paymentData);
|
|
|
|
|
|
|
|
|
Map<String, String> respParams = new HashMap<String, String>();
|
|
|
respParams.put("return_code", "SUCCESS");
|
|
|
respParams.put("return_msg", "");
|
|
|
PrintWriter out = response.getWriter();
|
|
|
out.println(WXUtil.createWXPayXml(respParams));
|
|
|
out.flush();
|
|
|
out.close();
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
@@ -194,11 +205,12 @@ public class PaymentController { |
|
|
* 支付宝支付通知
|
|
|
* @param request
|
|
|
* @return
|
|
|
* @throws IOException
|
|
|
*/
|
|
|
@IgnoreSignature
|
|
|
@IgnoreSession
|
|
|
@RequestMapping(value = "/ufo_alipay_notify", method = RequestMethod.POST)
|
|
|
public NotifyResponse notifyAliPayment(HttpServletRequest request) {
|
|
|
public void notifyAliPayment(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
|
|
alipayLogger.info("\n\n\n************************* Notify");
|
|
|
|
|
|
Map<String, String> params = parseParams(request.getParameterMap());
|
...
|
...
|
@@ -214,14 +226,14 @@ public class PaymentController { |
|
|
if(!isTradeSuccessNotify(params)) {
|
|
|
notifyResponse.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_IGNORE);
|
|
|
alipayLogger.info("[{}] not TRADE_SUCCESS notify, ignore it", out_trade_no);
|
|
|
return notifyResponse;
|
|
|
return ;
|
|
|
}
|
|
|
|
|
|
//回调验证
|
|
|
if(!alipayService.notifyVerify(params)) {
|
|
|
notifyResponse.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_VERFAIL);
|
|
|
alipayLogger.error("[{}] notification verify failed", out_trade_no);
|
|
|
return notifyResponse;
|
|
|
return ;
|
|
|
}
|
|
|
|
|
|
PaymentData paymentData = null;
|
...
|
...
|
@@ -234,12 +246,14 @@ public class PaymentController { |
|
|
} catch (Exception e) {
|
|
|
notifyResponse.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_FAILED);
|
|
|
alipayLogger.error("[{}] notify process failed, ex: {}", out_trade_no, e);
|
|
|
return notifyResponse;
|
|
|
return ;
|
|
|
}
|
|
|
|
|
|
notifyResponse.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_SUCCESS);
|
|
|
notifyResponse.setPaymentData(paymentData);
|
|
|
return notifyResponse;
|
|
|
|
|
|
logger.info("[{}] reply success to alipay", out_trade_no);
|
|
|
response.getWriter().print("success");
|
|
|
}
|
|
|
|
|
|
/* @RequestMapping(params = "method=ufo.order.transferMon")
|
...
|
...
|
|