Authored by Lixiaodi

修改支付回调

1 package com.yohoufo.order.controller; 1 package com.yohoufo.order.controller;
2 2
  3 +import java.io.IOException;
  4 +import java.io.PrintWriter;
3 import java.util.HashMap; 5 import java.util.HashMap;
4 import java.util.Map; 6 import java.util.Map;
5 7
6 import javax.servlet.http.HttpServletRequest; 8 import javax.servlet.http.HttpServletRequest;
  9 +import javax.servlet.http.HttpServletResponse;
7 10
8 -import com.yohobuy.ufo.model.order.req.ManualDealRequest;  
9 import org.apache.commons.lang.StringUtils; 11 import org.apache.commons.lang.StringUtils;
10 import org.slf4j.Logger; 12 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory; 13 import org.slf4j.LoggerFactory;
@@ -17,6 +19,7 @@ import org.springframework.web.bind.annotation.RequestParam; @@ -17,6 +19,7 @@ import org.springframework.web.bind.annotation.RequestParam;
17 import org.springframework.web.bind.annotation.RestController; 19 import org.springframework.web.bind.annotation.RestController;
18 20
19 import com.yoho.error.exception.ServiceException; 21 import com.yoho.error.exception.ServiceException;
  22 +import com.yohobuy.ufo.model.order.req.ManualDealRequest;
20 import com.yohoufo.common.ApiResponse; 23 import com.yohoufo.common.ApiResponse;
21 import com.yohoufo.common.annotation.IgnoreSession; 24 import com.yohoufo.common.annotation.IgnoreSession;
22 import com.yohoufo.common.annotation.IgnoreSignature; 25 import com.yohoufo.common.annotation.IgnoreSignature;
@@ -26,7 +29,6 @@ import com.yohoufo.order.model.NotifyResponse; @@ -26,7 +29,6 @@ import com.yohoufo.order.model.NotifyResponse;
26 import com.yohoufo.order.model.PayRefundBo; 29 import com.yohoufo.order.model.PayRefundBo;
27 import com.yohoufo.order.model.PaymentData; 30 import com.yohoufo.order.model.PaymentData;
28 import com.yohoufo.order.model.request.PaymentRequest; 31 import com.yohoufo.order.model.request.PaymentRequest;
29 -import com.yohoufo.order.model.request.TransferMoneyRequest;  
30 import com.yohoufo.order.model.response.PaymentConfirmRsp; 32 import com.yohoufo.order.model.response.PaymentConfirmRsp;
31 import com.yohoufo.order.model.response.PrepayResponse; 33 import com.yohoufo.order.model.response.PrepayResponse;
32 import com.yohoufo.order.service.IPaymentService; 34 import com.yohoufo.order.service.IPaymentService;
@@ -127,22 +129,23 @@ public class PaymentController { @@ -127,22 +129,23 @@ public class PaymentController {
127 * 微信支付 回调接口 129 * 微信支付 回调接口
128 * @param request 130 * @param request
129 * @return 131 * @return
  132 + * @throws IOException
130 */ 133 */
131 @IgnoreSignature 134 @IgnoreSignature
132 @IgnoreSession 135 @IgnoreSession
133 @RequestMapping(value = "/ufo_wechat_notify", method = RequestMethod.POST) 136 @RequestMapping(value = "/ufo_wechat_notify", method = RequestMethod.POST)
134 - public NotifyResponse notifyWeixinPayment(HttpServletRequest request) { 137 + public void notifyWeixinPayment(HttpServletRequest request, HttpServletResponse response) throws IOException {
135 wechatLogger.info("\n\n\n************************* Notify"); 138 wechatLogger.info("\n\n\n************************* Notify");
136 139
137 - NotifyResponse response = new NotifyResponse(); //忽略,即成功 140 + NotifyResponse notifyResponse = new NotifyResponse(); //忽略,即成功
138 141
139 String nofityBody = null; 142 String nofityBody = null;
140 try{ 143 try{
141 nofityBody = WXUtil.getWXPayRequestBody(request); 144 nofityBody = WXUtil.getWXPayRequestBody(request);
142 }catch(Exception e){ 145 }catch(Exception e){
143 wechatLogger.error("get notify request failed: {}", e); 146 wechatLogger.error("get notify request failed: {}", e);
144 - response.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_FAILED);  
145 - return response; 147 + notifyResponse.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_FAILED);
  148 + return ;
146 } 149 }
147 150
148 wechatLogger.info("notify params: {}", nofityBody); 151 wechatLogger.info("notify params: {}", nofityBody);
@@ -150,15 +153,15 @@ public class PaymentController { @@ -150,15 +153,15 @@ public class PaymentController {
150 Map<String, String> params = WXUtil.parseWXPayXml(nofityBody); 153 Map<String, String> params = WXUtil.parseWXPayXml(nofityBody);
151 if(params == null || params.size() == 0){ 154 if(params == null || params.size() == 0){
152 wechatLogger.error("parse notify request failed"); 155 wechatLogger.error("parse notify request failed");
153 - response.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_FAILED);  
154 - return response; 156 + notifyResponse.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_FAILED);
  157 + return ;
155 } 158 }
156 159
157 String returnCode = params.get(RETURN_CODE); 160 String returnCode = params.get(RETURN_CODE);
158 if(!PREPAY_RESULT_SUCCESS.equals(returnCode)){ 161 if(!PREPAY_RESULT_SUCCESS.equals(returnCode)){
159 wechatLogger.error("Weixin pay notify returnCode error: {}", nofityBody); 162 wechatLogger.error("Weixin pay notify returnCode error: {}", nofityBody);
160 - response.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_FAILED);  
161 - return response; 163 + notifyResponse.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_FAILED);
  164 + return ;
162 } 165 }
163 166
164 String out_trade_no = params.get("out_trade_no"); 167 String out_trade_no = params.get("out_trade_no");
@@ -166,9 +169,9 @@ public class PaymentController { @@ -166,9 +169,9 @@ public class PaymentController {
166 169
167 //回调验证 170 //回调验证
168 if(!weixinPayAppService.notifyVerify(params)) { 171 if(!weixinPayAppService.notifyVerify(params)) {
169 - response.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_VERFAIL); 172 + notifyResponse.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_VERFAIL);
170 wechatLogger.error("[{}] notification verify failed", out_trade_no); 173 wechatLogger.error("[{}] notification verify failed", out_trade_no);
171 - return response; 174 + return ;
172 } 175 }
173 176
174 PaymentData paymentData = null; 177 PaymentData paymentData = null;
@@ -179,14 +182,22 @@ public class PaymentController { @@ -179,14 +182,22 @@ public class PaymentController {
179 paymentService.paySuccess(paymentData); 182 paymentService.paySuccess(paymentData);
180 183
181 } catch (Exception e) { 184 } catch (Exception e) {
182 - response.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_FAILED); 185 + notifyResponse.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_FAILED);
183 wechatLogger.error("[{}] notify process failed, ex: {}", out_trade_no, e); 186 wechatLogger.error("[{}] notify process failed, ex: {}", out_trade_no, e);
184 - return response; 187 + return ;
185 } 188 }
186 189
187 - response.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_SUCCESS);  
188 - response.setPaymentData(paymentData);  
189 - return response; 190 + notifyResponse.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_SUCCESS);
  191 + notifyResponse.setPaymentData(paymentData);
  192 +
  193 +
  194 + Map<String, String> respParams = new HashMap<String, String>();
  195 + respParams.put("return_code", "SUCCESS");
  196 + respParams.put("return_msg", "");
  197 + PrintWriter out = response.getWriter();
  198 + out.println(WXUtil.createWXPayXml(respParams));
  199 + out.flush();
  200 + out.close();
190 } 201 }
191 202
192 203
@@ -194,11 +205,12 @@ public class PaymentController { @@ -194,11 +205,12 @@ public class PaymentController {
194 * 支付宝支付通知 205 * 支付宝支付通知
195 * @param request 206 * @param request
196 * @return 207 * @return
  208 + * @throws IOException
197 */ 209 */
198 @IgnoreSignature 210 @IgnoreSignature
199 @IgnoreSession 211 @IgnoreSession
200 @RequestMapping(value = "/ufo_alipay_notify", method = RequestMethod.POST) 212 @RequestMapping(value = "/ufo_alipay_notify", method = RequestMethod.POST)
201 - public NotifyResponse notifyAliPayment(HttpServletRequest request) { 213 + public void notifyAliPayment(HttpServletRequest request, HttpServletResponse response) throws IOException {
202 alipayLogger.info("\n\n\n************************* Notify"); 214 alipayLogger.info("\n\n\n************************* Notify");
203 215
204 Map<String, String> params = parseParams(request.getParameterMap()); 216 Map<String, String> params = parseParams(request.getParameterMap());
@@ -214,14 +226,14 @@ public class PaymentController { @@ -214,14 +226,14 @@ public class PaymentController {
214 if(!isTradeSuccessNotify(params)) { 226 if(!isTradeSuccessNotify(params)) {
215 notifyResponse.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_IGNORE); 227 notifyResponse.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_IGNORE);
216 alipayLogger.info("[{}] not TRADE_SUCCESS notify, ignore it", out_trade_no); 228 alipayLogger.info("[{}] not TRADE_SUCCESS notify, ignore it", out_trade_no);
217 - return notifyResponse; 229 + return ;
218 } 230 }
219 231
220 //回调验证 232 //回调验证
221 if(!alipayService.notifyVerify(params)) { 233 if(!alipayService.notifyVerify(params)) {
222 notifyResponse.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_VERFAIL); 234 notifyResponse.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_VERFAIL);
223 alipayLogger.error("[{}] notification verify failed", out_trade_no); 235 alipayLogger.error("[{}] notification verify failed", out_trade_no);
224 - return notifyResponse; 236 + return ;
225 } 237 }
226 238
227 PaymentData paymentData = null; 239 PaymentData paymentData = null;
@@ -234,12 +246,14 @@ public class PaymentController { @@ -234,12 +246,14 @@ public class PaymentController {
234 } catch (Exception e) { 246 } catch (Exception e) {
235 notifyResponse.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_FAILED); 247 notifyResponse.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_FAILED);
236 alipayLogger.error("[{}] notify process failed, ex: {}", out_trade_no, e); 248 alipayLogger.error("[{}] notify process failed, ex: {}", out_trade_no, e);
237 - return notifyResponse; 249 + return ;
238 } 250 }
239 251
240 notifyResponse.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_SUCCESS); 252 notifyResponse.setNotifyResult(NotifyResponse.PAYMENT_NOTIFY_RESULT_SUCCESS);
241 notifyResponse.setPaymentData(paymentData); 253 notifyResponse.setPaymentData(paymentData);
242 - return notifyResponse; 254 +
  255 + logger.info("[{}] reply success to alipay", out_trade_no);
  256 + response.getWriter().print("success");
243 } 257 }
244 258
245 /* @RequestMapping(params = "method=ufo.order.transferMon") 259 /* @RequestMapping(params = "method=ufo.order.transferMon")