| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.http.HttpEntity; |
| | | import org.springframework.http.HttpHeaders; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.util.LinkedMultiValueMap; |
| | | import org.springframework.util.MultiValueMap; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | |
| | | |
| | | @Resource |
| | | private RedisTemplate<String, Object> redisTemplate; |
| | | |
| | | @Resource |
| | | private RestTemplate internalRestTemplate; |
| | | |
| | | @Resource |
| | | private ISystemPriceCityService systemPriceCityService; |
| | |
| | | } |
| | | return ResultUtil.success(orderInfoWarpper); |
| | | } catch (Exception e) { |
| | | log.error("获取服务中的详情订单数据异常,接口:{}, 错误信息:", "/api/order/queryOrderInfo", e); |
| | | e.printStackTrace(); |
| | | return ResultUtil.runErr(); |
| | | } |
| | |
| | | } |
| | | return ResultUtil.success(); |
| | | } catch (Exception e) { |
| | | log.error("订单完成支付订单操作,异常,接口:/api/taxi/payTaxiOrder1,错误信息:", e); |
| | | e.printStackTrace(); |
| | | return ResultUtil.runErr(); |
| | | } |
| | |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/base/cbyzxCancelOrderTaxi") |
| | | public void cbyzxCancelOrderTaxi(HttpServletRequest request, HttpServletResponse response) { |
| | | public Map<String, Object> cbyzxCancelOrderTaxi(@RequestBody(required = false) String params, |
| | | HttpServletRequest request, HttpServletResponse response) { |
| | | try { |
| | | Map<String, String> map = payMoneyUtil.weixinpayCallback(request); |
| | | if (null != map) { |
| | | String order_id = map.get("transaction_id"); |
| | | String out_trade_no = map.get("out_trade_no"); |
| | | String result = map.get("result"); |
| | | if (ToolUtil.isNotEmpty(out_trade_no) && ToolUtil.isNotEmpty(order_id)) { |
| | | PrintWriter out = response.getWriter(); |
| | | out.write(result); |
| | | out.flush(); |
| | | out.close(); |
| | | |
| | | String[] split = out_trade_no.split("_"); |
| | | Integer id = Integer.valueOf(split[0]); |
| | | Integer type = Integer.valueOf(split[1]); |
| | | switch (type) { |
| | | case 1: |
| | | orderPrivateCarService.payCancelOrderPrivateCar(id, order_id, 1); |
| | | break; |
| | | case 2: |
| | | orderTaxiService.payCancelOrderTaxi(id, order_id, 1); |
| | | break; |
| | | case 3: |
| | | orderCrossCityService.payCancelOrderCrossCity(id, order_id, 1); |
| | | break; |
| | | } |
| | | } |
| | | // cloudPay(map.get("total_fee"),map.get("transaction_id"),1); |
| | | |
| | | JSONObject payload = parseCbyzxCallbackPayload(params, request); |
| | | String refundNo = firstNotBlank(payload, |
| | | "refundOutRequestNo", "refund_out_request_no", "outRefundNo", "out_refund_no", |
| | | "merchantRefundSerialNo", "merchant_refund_serial_no"); |
| | | if (StringUtils.isBlank(refundNo)) { |
| | | return buildCbyzxCallbackResponse(0, "success"); |
| | | } |
| | | if (!refundNo.startsWith("PRF_")) { |
| | | return buildCbyzxCallbackResponse(0, "success"); |
| | | } |
| | | String[] split = refundNo.split("_"); |
| | | if (split.length < 4 || !StringUtils.isNumeric(split[1]) || !StringUtils.isNumeric(split[2])) { |
| | | return buildCbyzxCallbackResponse(1, "invalid refundOutRequestNo"); |
| | | } |
| | | Integer orderType = Integer.valueOf(split[1]); |
| | | Integer orderId = Integer.valueOf(split[2]); |
| | | String refundId = firstNotBlank(payload, |
| | | "refundId", "refund_id", "gatewaySerialNo", "gateway_serial_no", |
| | | "thirdRefundNo", "third_refund_no", "merchantRefundSerialNo", "merchant_refund_serial_no"); |
| | | Map<String, Object> driverResult = notifyDriverPrepayRefund(orderId, orderType, refundNo, refundId); |
| | | Object code = driverResult == null ? null : driverResult.get("code"); |
| | | if (code != null && "200".equals(String.valueOf(code))) { |
| | | return buildCbyzxCallbackResponse(0, "success"); |
| | | } |
| | | log.error("创博优退款回调转发司机端失败,payload={}, driverResult={}", payload, driverResult); |
| | | return buildCbyzxCallbackResponse(1, "driver callback fail"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("创博优退款回调处理失败", e); |
| | | return buildCbyzxCallbackResponse(1, "fail"); |
| | | } |
| | | |
| | | // try { |
| | | // Map<String, String> map = payMoneyUtil.weixinpayCallback(request); |
| | | // if (null != map) { |
| | | // String order_id = map.get("transaction_id"); |
| | | // String out_trade_no = map.get("out_trade_no"); |
| | | // String result = map.get("result"); |
| | | // if (ToolUtil.isNotEmpty(out_trade_no) && ToolUtil.isNotEmpty(order_id)) { |
| | | // PrintWriter out = response.getWriter(); |
| | | // out.write(result); |
| | | // out.flush(); |
| | | // out.close(); |
| | | // |
| | | // String[] split = out_trade_no.split("_"); |
| | | // Integer id = Integer.valueOf(split[0]); |
| | | // Integer type = Integer.valueOf(split[1]); |
| | | // switch (type) { |
| | | // case 1: |
| | | // orderPrivateCarService.payCancelOrderPrivateCar(id, order_id, 1); |
| | | // break; |
| | | // case 2: |
| | | // orderTaxiService.payCancelOrderTaxi(id, order_id, 1); |
| | | // break; |
| | | // case 3: |
| | | // orderCrossCityService.payCancelOrderCrossCity(id, order_id, 1); |
| | | // break; |
| | | // } |
| | | // } |
| | | //// cloudPay(map.get("total_fee"),map.get("transaction_id"),1); |
| | | // |
| | | // } |
| | | // } catch (Exception e) { |
| | | // e.printStackTrace(); |
| | | // } |
| | | } |
| | | |
| | | /** |
| | | * 内部服务调用:创博优微信先付订单退款。 |
| | | * 只负责调用退款网关并返回原始结果,不修改司机端订单业务状态。 |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/base/internal/cbyzxPrepayRefund") |
| | | public JSONObject cbyzxPrepayRefund(String outRequestNo, String refundOutRequestNo, |
| | | Integer refundAmount, String refundDesc) { |
| | | JSONObject error = new JSONObject(); |
| | | if (ToolUtil.isEmpty(outRequestNo)) { |
| | | error.put("code", 1); |
| | | error.put("msg", "missing outRequestNo"); |
| | | return error; |
| | | } |
| | | if (ToolUtil.isEmpty(refundOutRequestNo)) { |
| | | error.put("code", 1); |
| | | error.put("msg", "missing refundOutRequestNo"); |
| | | return error; |
| | | } |
| | | if (refundAmount == null || refundAmount <= 0) { |
| | | error.put("code", 1); |
| | | error.put("msg", "invalid refundAmount"); |
| | | return error; |
| | | } |
| | | try { |
| | | CbyzxPayUtil.ClosePayOrderRequest closeRequest = new CbyzxPayUtil.ClosePayOrderRequest(); |
| | | closeRequest.setOutRequestNo(outRequestNo); |
| | | closeRequest.setRefundOutRequestNo(refundOutRequestNo); |
| | | closeRequest.setRefundAmount(refundAmount); |
| | | closeRequest.setRefundDesc(ToolUtil.isNotEmpty(refundDesc) ? refundDesc : "微信先付订单退款"); |
| | | return CbyzxPayUtil.closePayOrder(closeRequest); |
| | | } catch (Exception e) { |
| | | log.error("内部创博优先付退款失败,outRequestNo={}, refundOutRequestNo={}", |
| | | outRequestNo, refundOutRequestNo, e); |
| | | error.put("code", 1); |
| | | error.put("msg", e.getMessage()); |
| | | return error; |
| | | } |
| | | } |
| | | |
| | |
| | | public Map<String, Object> cbyzxPayOrderTaxi(@RequestBody String params, HttpServletRequest request) { |
| | | try { |
| | | JSONObject payload = JSONObject.parseObject(params); |
| | | log.info("创博优完成订单支付回调,outRequestNo={}, paymentOrderId={}, paidTime={}, paidAmount={}", |
| | | log.error("创博优完成订单支付回调,outRequestNo={}, paymentOrderId={}, paidTime={}, paidAmount={}", |
| | | cbyzxOrderPayHelper.extractOutRequestNo(payload), |
| | | cbyzxOrderPayHelper.extractThirdPartyOrderNo(payload), |
| | | payload == null ? null : payload.getString("paidTime"), |
| | |
| | | return buildCbyzxCallbackResponse(1, "order not found"); |
| | | } |
| | | if (orderRide.getState() == null || orderRide.getState() != 2) { |
| | | orderRide.setOutNum(orderId); |
| | | // orderRide.setOutNum(orderId); |
| | | orderRide.setPayTime(new Date()); |
| | | orderRide.setPayType(2); |
| | | orderRide.setState(2); |
| | |
| | | return result; |
| | | } |
| | | |
| | | private JSONObject parseCbyzxCallbackPayload(String params, HttpServletRequest request) { |
| | | JSONObject payload = new JSONObject(); |
| | | if (StringUtils.isNotBlank(params)) { |
| | | try { |
| | | JSONObject body = JSONObject.parseObject(params); |
| | | if (body != null) { |
| | | payload.putAll(body); |
| | | } |
| | | } catch (Exception e) { |
| | | log.warn("创博优回调body不是JSON,params={}", params); |
| | | } |
| | | } |
| | | if (request != null && request.getParameterMap() != null) { |
| | | for (String key : request.getParameterMap().keySet()) { |
| | | String[] values = request.getParameterValues(key); |
| | | if (values == null || values.length == 0) { |
| | | continue; |
| | | } |
| | | payload.put(key, values.length == 1 ? values[0] : Arrays.asList(values)); |
| | | } |
| | | } |
| | | return payload; |
| | | } |
| | | |
| | | private String firstNotBlank(JSONObject payload, String... keys) { |
| | | if (payload == null || keys == null) { |
| | | return null; |
| | | } |
| | | for (String key : keys) { |
| | | Object value = payload.get(key); |
| | | if (value == null) { |
| | | continue; |
| | | } |
| | | if (value instanceof Collection) { |
| | | for (Object item : (Collection<?>) value) { |
| | | String text = item == null ? null : String.valueOf(item); |
| | | if (StringUtils.isNotBlank(text)) { |
| | | return text; |
| | | } |
| | | } |
| | | } else { |
| | | String text = String.valueOf(value); |
| | | if (StringUtils.isNotBlank(text)) { |
| | | return text; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private Map<String, Object> notifyDriverPrepayRefund(Integer orderId, Integer orderType, String refundNo, String refundId) { |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); |
| | | MultiValueMap<String, Object> postParams = new LinkedMultiValueMap<>(); |
| | | postParams.add("orderId", orderId); |
| | | postParams.add("orderType", orderType); |
| | | postParams.add("refundNo", refundNo); |
| | | postParams.add("refundId", refundId); |
| | | HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(postParams, headers); |
| | | return internalRestTemplate.postForObject( |
| | | "http://driver-server/base/internal/prepayRefundCallback", requestEntity, Map.class); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 小件物流差价微信支付回调 |