| @@ -19,6 +19,7 @@ import com.iformall.service.pay.PayServiceFactory; | |||||
| import com.iformall.service.pay.service.pay.PayAdapterService; | import com.iformall.service.pay.service.pay.PayAdapterService; | ||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.jdom2.JDOMException; | import org.jdom2.JDOMException; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| @@ -151,30 +152,12 @@ public class CallbackPayController extends BaseController { | |||||
| @AuthIgnore | @AuthIgnore | ||||
| @ApiOperation("支付回调") | @ApiOperation("支付回调") | ||||
| @PostMapping(value = "/aliNotify") | @PostMapping(value = "/aliNotify") | ||||
| public Map<String,Object> _aliNotify(HttpServletRequest request, HttpServletResponse response) { | |||||
| public String _aliNotify(HttpServletRequest request, HttpServletResponse response) { | |||||
| logger.debug("[" + getIpAddr() + "] CallbackPayController::_aliNotify"); | logger.debug("[" + getIpAddr() + "] CallbackPayController::_aliNotify"); | ||||
| String body1 = ((BodyReaderHttpServletRequestWrapper) request).getBody(); | |||||
| String body = ((BodyReaderHttpServletRequestWrapper) request).getBody(); | |||||
| logger.info("ali支付回调结果通知1{}"+JSONObject.toJSONString(body1)); | |||||
| Map< String , String > paranMap = new HashMap < String , String > (); | |||||
| Map requestParams = request.getParameterMap(); | |||||
| logger.info("ali支付回调结果通知2{}"+JSONObject.toJSONString(requestParams)); | |||||
| for(Iterator iter = requestParams.keySet().iterator(); iter.hasNext();){ | |||||
| String name = (String)iter.next(); | |||||
| String[] values = (String [])requestParams.get(name); | |||||
| String valueStr = ""; | |||||
| for(int i = 0;i < values.length;i ++ ){ | |||||
| valueStr = (i==values.length-1)?valueStr + values [i]:valueStr + values[i] + ","; | |||||
| } | |||||
| //乱码解决,这段代码在出现乱码时使用。 | |||||
| //valueStr = new String(valueStr.getBytes("ISO-8859-1"), "utf-8"); | |||||
| paranMap.put (name,valueStr); | |||||
| } | |||||
| logger.info("ali支付回调结果通知{}"+JSONObject.toJSONString(paranMap)); | |||||
| logger.info("ali支付回调结果通知 body{}"+body); | |||||
| Map<String,Object> resultMap = new HashMap<>(); | Map<String,Object> resultMap = new HashMap<>(); | ||||
| @@ -182,65 +165,43 @@ public class CallbackPayController extends BaseController { | |||||
| * ----效验数据来源合法 | * ----效验数据来源合法 | ||||
| */ | */ | ||||
| try{ | try{ | ||||
| String body = this.getBody(request); | |||||
| logger.info("ali支付回调结果通知---body{}"+body); | |||||
| // String msg = (String) paranMap.get("msg"); | |||||
| // String type = (String) paranMap.get("type"); | |||||
| // | |||||
| // Map<String, Object> pMap = JSONObject.parseObject(msg, Map.class); | |||||
| // String appid = (String) pMap.get("appid"); | |||||
| // WxAppinfo appInfo = wxAppinfoService.getOnlyByAppIdFromRedis(appid); | |||||
| // WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(appInfo.getPayId()); | |||||
| // if("payment".equals(type)){ | |||||
| // String out_order_no = (String)pMap.get("cp_orderno"); | |||||
| // | |||||
| // EnumProductOrderPayVendor payVendorEnum = EnumProductOrderPayVendor.PAY_WAY_TT; | |||||
| // ProductOrderPay orderPay = productOrderPayService.getByOrder(Long.parseLong(out_order_no), payVendorEnum); | |||||
| // | |||||
| // PayAdapterService payAdapterService = payServiceFactory.getPayAdapterService(payVendorEnum.getCode()); | |||||
| // productOrderPayService.handleProductOrderByQuery(appInfo,payAccount,orderPay,payAdapterService); | |||||
| // | |||||
| // resultMap.put("err_no",0); | |||||
| // resultMap.put("err_tips","success"); | |||||
| // } | |||||
| Map<String, String> paranMap = handBody(body); | |||||
| logger.info("ali支付回调结果通知 paranMap{}"+JSONObject.toJSONString(paranMap)); | |||||
| String app_id = paranMap.get("app_id"); | |||||
| WxAppinfo appInfo = wxAppinfoService.getOnlyByAppIdFromRedis(app_id); | |||||
| WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(appInfo.getPayId()); | |||||
| String out_trade_no = paranMap.get("out_trade_no"); | |||||
| String trade_status = paranMap.get("trade_status"); | |||||
| if("TRADE_SUCCESS".equals(trade_status)){ | |||||
| EnumProductOrderPayVendor payVendorEnum = EnumProductOrderPayVendor.PAY_WAY_ALIPAY_WAP; | |||||
| ProductOrderPay orderPay = productOrderPayService.getByOrder(Long.parseLong(out_trade_no), payVendorEnum); | |||||
| PayAdapterService payAdapterService = payServiceFactory.getPayAdapterService(payVendorEnum.getCode()); | |||||
| productOrderPayService.handleProductOrderByQuery(appInfo,payAccount,orderPay,payAdapterService); | |||||
| } | |||||
| return "success"; | |||||
| }catch(Exception e){ | }catch(Exception e){ | ||||
| logger.error("ali支付回调处理异常"+e); | logger.error("ali支付回调处理异常"+e); | ||||
| resultMap.put("err_no",ErrorCode.SYS_SERVER_ERROR.getCode()); | |||||
| resultMap.put("err_tips","ali支付回调处理异常"); | |||||
| } | } | ||||
| return resultMap; | |||||
| return "fail"; | |||||
| } | } | ||||
| private String getBody(HttpServletRequest request) throws IOException { | |||||
| StringBuilder stringBuilder = new StringBuilder(); | |||||
| BufferedReader bufferedReader = null; | |||||
| try { | |||||
| InputStream inputStream = request.getInputStream(); | |||||
| if (inputStream != null) { | |||||
| bufferedReader = new BufferedReader(new InputStreamReader(inputStream,"utf-8")); | |||||
| char[] charBuffer = new char[1024]; | |||||
| int bytesRead = -1; | |||||
| while ((bytesRead = bufferedReader.read(charBuffer)) > 0) { | |||||
| stringBuilder.append(charBuffer, 0, bytesRead); | |||||
| } | |||||
| } else { | |||||
| stringBuilder.append(""); | |||||
| } | |||||
| } catch ( | |||||
| IOException ex) { | |||||
| throw ex; | |||||
| } finally { | |||||
| if (bufferedReader != null) { | |||||
| try { | |||||
| bufferedReader.close(); | |||||
| } catch (IOException ex) { | |||||
| throw ex; | |||||
| private Map<String,String> handBody(String body){ | |||||
| Map<String,String> map = new HashMap<>(); | |||||
| if(StringUtils.isNotBlank(body)){ | |||||
| String[] key_value = body.split("&"); | |||||
| if(key_value.length > 0){ | |||||
| for (String kv: key_value) { | |||||
| String[] split = kv.split("="); | |||||
| map.put(split[0],split[1]); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return stringBuilder.toString(); | |||||
| return map; | |||||
| } | } | ||||
| } | } | ||||