| | |
| | | import com.stylefeng.guns.modular.system.service.ICompanyService; |
| | | import com.stylefeng.guns.modular.system.service.IDriverService; |
| | | import com.stylefeng.guns.modular.system.service.IReassignService; |
| | | import com.stylefeng.guns.modular.system.util.CbyzxOrderPayHelper; |
| | | import com.stylefeng.guns.modular.system.util.PayMoneyUtil; |
| | | import com.stylefeng.guns.modular.system.util.rongyun.RongYunUtil; |
| | | import com.stylefeng.guns.modular.system.util.rongyun.model.CloudRecordingCallback; |
| | |
| | | @Autowired |
| | | private PayMoneyUtil payMoneyUtil; |
| | | |
| | | @Autowired |
| | | private CbyzxOrderPayHelper cbyzxOrderPayHelper; |
| | | |
| | | |
| | | @Autowired |
| | | private IOrderPrivateCarService orderPrivateCarService; |
| | |
| | | |
| | | @Autowired |
| | | private IOrderCrossCityService orderCrossCityService; |
| | | |
| | | /** |
| | | * 创博优微信支付统一回调。 |
| | | * out_trade_no 为平台业务单号,用于反解跨城完成支付或改派支付; |
| | | * trade_no 为创博优支付流水号,用于回填真实支付流水; |
| | | * trade_status=TRADE_SUCCESS 视为支付成功; |
| | | * notify_type=directpay.status.sync 表示支付结果通知。 |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/cbyzxPayOrderTaxi") |
| | | public Map<String, Object> cbyzxPayOrderTaxi(HttpServletRequest request) { |
| | | try { |
| | | JSONObject payload = cbyzxOrderPayHelper.parseCallbackRequest(request); |
| | | if (payload == null) { |
| | | return buildCbyzxCallbackResponse(1, "invalid request"); |
| | | } |
| | | if (!cbyzxOrderPayHelper.isPaySuccess(payload)) { |
| | | return buildCbyzxCallbackResponse(1, cbyzxOrderPayHelper.extractMessage(payload)); |
| | | } |
| | | |
| | | String outTradeNo = cbyzxOrderPayHelper.extractOutRequestNo(payload); |
| | | if (ToolUtil.isEmpty(outTradeNo)) { |
| | | return buildCbyzxCallbackResponse(1, "missing out_trade_no"); |
| | | } |
| | | String tradeNo = cbyzxOrderPayHelper.extractThirdPartyOrderNo(payload); |
| | | String orderId = ToolUtil.isNotEmpty(tradeNo) ? tradeNo : outTradeNo; |
| | | |
| | | if (outTradeNo.startsWith("crossCity_")) { |
| | | String legacyOutTradeNo = outTradeNo.substring("crossCity_".length()); |
| | | String[] split = legacyOutTradeNo.split("_"); |
| | | if (split.length < 2) { |
| | | return buildCbyzxCallbackResponse(1, "invalid crossCity out_trade_no"); |
| | | } |
| | | orderCrossCityService.payOrderCrossCityCallback(Integer.valueOf(split[0]), orderId, 1); |
| | | return buildCbyzxCallbackResponse(0, "success"); |
| | | } |
| | | if (outTradeNo.startsWith("reassign_")) { |
| | | String legacyOutTradeNo = outTradeNo.substring("reassign_".length()); |
| | | reassignService.payReassign(legacyOutTradeNo, orderId, 1); |
| | | return buildCbyzxCallbackResponse(0, "success"); |
| | | } |
| | | if (outTradeNo.startsWith("reassignBatch_")) { |
| | | String legacyOutTradeNo = outTradeNo.substring("reassignBatch_".length()); |
| | | reassignService.payReassign(legacyOutTradeNo, orderId, 1); |
| | | return buildCbyzxCallbackResponse(0, "success"); |
| | | } |
| | | return buildCbyzxCallbackResponse(1, "unsupported out_trade_no"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return buildCbyzxCallbackResponse(1, "fail"); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | |
| | | out.close(); |
| | | } |
| | | |
| | | private Map<String, Object> buildCbyzxCallbackResponse(Integer code, String msg) { |
| | | Map<String, Object> result = new HashMap<>(); |
| | | result.put("code", code); |
| | | result.put("msg", msg); |
| | | return result; |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | @Autowired |
| | | private PayMoneyUtil payMoneyUtil; |
| | | |
| | | @Autowired |
| | | private CbyzxOrderPayHelper cbyzxOrderPayHelper; |
| | | |
| | | @Autowired |
| | | private IOrderAdditionalFeeService orderAdditionalFeeService; |
| | |
| | | orderCrossCity.setCouponMoney(0D);//初始化历史数据 |
| | | orderCrossCity.setCouponId(null); |
| | | |
| | | String out_trade_no = orderId + "_3_" + UUIDUtil.getRandomCode(5); |
| | | if(payType == 1){//微信支付 |
| | | resultUtil = payMoneyUtil.weixinpay("完成订单", "", out_trade_no, orderMoney.toString(), "/base/wxPayCrossCity", "APP", ""); |
| | | paymentRecordService.saveData(1, orderCrossCity.getDriverId(), 2, orderId, 3, 1, orderMoney, "", 1);//添加预支付数据 |
| | | String out_trade_no = buildCbyzxCrossCityOutTradeNo(orderId); |
| | | Driver driver = driverService.selectById(orderCrossCity.getDriverId()); |
| | | if(null == driver || ToolUtil.isEmpty(driver.getAppletsOpenId())){ |
| | | return ResultUtil.error("司机未绑定微信小程序openid,无法发起微信支付"); |
| | | } |
| | | JSONObject response = cbyzxOrderPayHelper.createOrder(orderCrossCity.getDriverId(), driver.getAppletsOpenId(), out_trade_no, orderMoney); |
| | | if(!cbyzxOrderPayHelper.isCreateSuccess(response)){ |
| | | return ResultUtil.error(cbyzxOrderPayHelper.extractMessage(response), response); |
| | | } |
| | | resultUtil = ResultUtil.success(response); |
| | | paymentRecordService.saveData(1, orderCrossCity.getDriverId(), 2, orderId, 3, 1, orderMoney, out_trade_no, 1);//添加预支付数据 |
| | | } |
| | | if(payType == 2){//支付宝支付 |
| | | String out_trade_no = orderId + "_3_" + UUIDUtil.getRandomCode(5); |
| | | resultUtil = payMoneyUtil.alipay("完成订单", "完成订单", "", out_trade_no, orderMoney.toString(), "/base/aliPayCrossCity"); |
| | | paymentRecordService.saveData(1, orderCrossCity.getDriverId(), 2, orderId, 3, 2, orderMoney, "", 1);//添加预支付数据 |
| | | } |
| | |
| | | return resultUtil; |
| | | } |
| | | |
| | | /** |
| | | * 创博优完成订单支付回调单号,增加业务前缀避免与改派支付共用回调地址时串单。 |
| | | */ |
| | | private String buildCbyzxCrossCityOutTradeNo(Integer orderId) { |
| | | return "crossCity_" + orderId + "_3_" + UUIDUtil.getRandomCode(5); |
| | | } |
| | | |
| | | |
| | | private ResultUtil placeAnOrder(BigDecimal amount, Integer type, Integer orderType, Integer orderId) throws Exception { |
| | | JSONObject json = new JSONObject(); |
| | |
| | | private PayMoneyUtil payMoneyUtil; |
| | | |
| | | @Autowired |
| | | private CbyzxOrderPayHelper cbyzxOrderPayHelper; |
| | | |
| | | @Autowired |
| | | private IOrderTaxiService orderTaxiService; |
| | | |
| | | @Autowired |
| | |
| | | if (null != reassign.getPayType()) { |
| | | if (reassign.getPayType() == 1) {//微信支付 |
| | | reassign.setState(1); |
| | | |
| | | resultUtil = payMoneyUtil.weixinpay("改派订单", "", reassign.getId() + "_" + reassign.getOrderType() + "_" + UUIDUtil.getRandomCode(5), "0", "/base/wxReassign", "APP", ""); |
| | | paymentRecordService.saveData(1, uid, 2, reassign.getOrderId(), reassign.getOrderType(), 1, 0.0, "", 1);//添加预支付数据 |
| | | if(ToolUtil.isEmpty(driver.getAppletsOpenId())){ |
| | | return ResultUtil.error("司机未绑定微信小程序openid,无法发起微信支付"); |
| | | } |
| | | String outTradeNo = buildCbyzxReassignOutTradeNo(reassign.getId(), reassign.getOrderType()); |
| | | JSONObject response = cbyzxOrderPayHelper.createOrder(uid, driver.getAppletsOpenId(), outTradeNo, aDouble); |
| | | if(!cbyzxOrderPayHelper.isCreateSuccess(response)){ |
| | | return ResultUtil.error(cbyzxOrderPayHelper.extractMessage(response), response); |
| | | } |
| | | resultUtil = ResultUtil.success(response); |
| | | paymentRecordService.saveData(1, uid, 2, reassign.getOrderId(), reassign.getOrderType(), 1, aDouble, outTradeNo, 1);//添加预支付数据 |
| | | } |
| | | if (reassign.getPayType() == 2) {//支付宝 |
| | | reassign.setState(1); |
| | |
| | | if (null != reassign.getPayType()) { |
| | | if (reassign.getPayType() == 1) {//微信支付 |
| | | String[] split1 = ids.split(","); |
| | | |
| | | resultUtil = payMoneyUtil.weixinpay("改派订单", "", ids + "_3_" + UUIDUtil.getRandomCode(5), totalMoney.toString(), "/base/wxReassign", "APP", ""); |
| | | if(ToolUtil.isEmpty(driver.getAppletsOpenId())){ |
| | | return ResultUtil.error("司机未绑定微信小程序openid,无法发起微信支付"); |
| | | } |
| | | String outTradeNo = buildCbyzxBatchReassignOutTradeNo(ids); |
| | | JSONObject response = cbyzxOrderPayHelper.createOrder(uid, driver.getAppletsOpenId(), outTradeNo, totalMoney); |
| | | if(!cbyzxOrderPayHelper.isCreateSuccess(response)){ |
| | | return ResultUtil.error(cbyzxOrderPayHelper.extractMessage(response), response); |
| | | } |
| | | resultUtil = ResultUtil.success(response); |
| | | for (String id : split1) { |
| | | paymentRecordService.saveData(1, uid, 2, Integer.valueOf(id), 3, 1, aDouble, "", 1);//添加预支付数据 |
| | | paymentRecordService.saveData(1, uid, 2, Integer.valueOf(id), 3, 1, aDouble, outTradeNo, 1);//添加预支付数据 |
| | | } |
| | | } |
| | | if (reassign.getPayType() == 2) {//支付宝 |
| | |
| | | return reassignMapper.queryList(uid, pageNum, size); |
| | | } |
| | | |
| | | /** |
| | | * 创博优单条改派支付单号,保留原有 reassignId_orderType 结构用于回调复用旧逻辑。 |
| | | */ |
| | | private String buildCbyzxReassignOutTradeNo(Integer reassignId, Integer orderType) { |
| | | return "reassign_" + reassignId + "_" + orderType + "_" + UUIDUtil.getRandomCode(5); |
| | | } |
| | | |
| | | /** |
| | | * 创博优批量跨城改派支付单号,使用前缀避免与跨城完成订单支付冲突。 |
| | | */ |
| | | private String buildCbyzxBatchReassignOutTradeNo(String reassignIds) { |
| | | return "reassignBatch_" + reassignIds + "_3_" + UUIDUtil.getRandomCode(5); |
| | | } |
| | | |
| | | |
| | | public static List<Integer> orderIds = new ArrayList<>(); |
| | | |
| | |
| | | |
| | | /** |
| | | * 改派支付完成后的操作 |
| | | * @param id 改派单id |
| | | * @param order_id 工行支付订单 |
| | | * @param id 改派回调中的平台业务单号,格式仍按 reassignId_orderType_random 解析 |
| | | * @param order_id 第三方支付流水号 |
| | | * @param type 1=微信,2=支付宝,4=云闪付 |
| | | * @throws Exception |
| | | */ |
| New file |
| | |
| | | package com.stylefeng.guns.modular.system.util; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.HashSet; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * 创博优订单支付适配工具。 |
| | | */ |
| | | @Component |
| | | public class CbyzxOrderPayHelper { |
| | | |
| | | private static final String CALLBACK_PATH = "/base/cbyzxPayOrderTaxi"; |
| | | private static final Set<String> SUCCESS_STATUS = new HashSet<>(Arrays.asList( |
| | | "SUCCESS", "SUCCEEDED", "PAY_SUCCESS", "TRADE_SUCCESS", "PAID", "PAYED", "1", "00", "TRUE" |
| | | )); |
| | | private static final Set<String> FAIL_STATUS = new HashSet<>(Arrays.asList( |
| | | "FAIL", "FAILED", "CLOSED", "CANCEL", "CANCELED", "CANCELLED", "0", "FALSE" |
| | | )); |
| | | |
| | | @Value("${callbackPath}") |
| | | private String callbackPath; |
| | | |
| | | public JSONObject createOrder(Integer buyerId, String openId, String outRequestNo, Double amount) { |
| | | CbyzxPayUtil.CreatePayOrderRequest request = new CbyzxPayUtil.CreatePayOrderRequest(); |
| | | request.setOutRequestNo(outRequestNo); |
| | | request.setPaymentOrderAmount(new BigDecimal(String.valueOf(amount)).setScale(2, RoundingMode.HALF_UP)); |
| | | request.setBuyerId(Long.valueOf(String.valueOf(buyerId))); |
| | | request.setOpenId(openId); |
| | | request.setPayEndTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(System.currentTimeMillis() + 30L * 60L * 1000L))); |
| | | request.setCallbackUrl(buildCallbackUrl()); |
| | | return CbyzxPayUtil.createPayOrder(request); |
| | | } |
| | | |
| | | public String buildCallbackUrl() { |
| | | return callbackPath + CALLBACK_PATH; |
| | | } |
| | | |
| | | public boolean isCreateSuccess(JSONObject response) { |
| | | if (response == null) { |
| | | return false; |
| | | } |
| | | Object code = findValue(response, names("code")); |
| | | if (code != null && "0".equals(String.valueOf(code))) { |
| | | return true; |
| | | } |
| | | Object success = findValue(response, names("success")); |
| | | return success != null && Boolean.parseBoolean(String.valueOf(success)); |
| | | } |
| | | |
| | | /** |
| | | * 解析创博优表单回调参数。 |
| | | * out_trade_no 为平台订单号,trade_no 为三方支付流水号。 |
| | | */ |
| | | public JSONObject parseCallbackRequest(HttpServletRequest request) { |
| | | if (request == null || request.getParameterMap() == null || request.getParameterMap().isEmpty()) { |
| | | return null; |
| | | } |
| | | JSONObject payload = new JSONObject(); |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * trade_status=TRADE_SUCCESS 视为支付成功。 |
| | | */ |
| | | public boolean isPaySuccess(JSONObject payload) { |
| | | if (payload == null) { |
| | | return false; |
| | | } |
| | | Object status = findValue(payload, names("trade_status", "tradeStatus", "payStatus", "paymentStatus", "status", "result", "resultCode", "state")); |
| | | if (status != null) { |
| | | String normalized = String.valueOf(status).trim().toUpperCase(); |
| | | if (SUCCESS_STATUS.contains(normalized)) { |
| | | return true; |
| | | } |
| | | if (FAIL_STATUS.contains(normalized)) { |
| | | return false; |
| | | } |
| | | } |
| | | Object success = findValue(payload, names("success")); |
| | | if (success != null) { |
| | | return Boolean.parseBoolean(String.valueOf(success)); |
| | | } |
| | | Object code = findValue(payload, names("code")); |
| | | return code != null && "0".equals(String.valueOf(code)) && StringUtils.hasText(extractOutRequestNo(payload)); |
| | | } |
| | | |
| | | /** |
| | | * out_trade_no 为平台侧订单号,格式为 orderId_orderType_random。 |
| | | */ |
| | | public String extractOutRequestNo(JSONObject payload) { |
| | | return valueToString(findValue(payload, names("outRequestNo", "out_trade_no"))); |
| | | } |
| | | |
| | | /** |
| | | * 回查本地支付记录时优先使用 out_trade_no。 |
| | | */ |
| | | public String extractRecordCode(JSONObject payload) { |
| | | String code = valueToString(findValue(payload, names("out_trade_no", "outRequestNo", "merchantSerialNo", "merchant_serial_no"))); |
| | | return StringUtils.hasText(code) ? code : null; |
| | | } |
| | | |
| | | /** |
| | | * trade_no 为创博优侧交易流水号,用于标记实际支付成功流水。 |
| | | */ |
| | | public String extractThirdPartyOrderNo(JSONObject payload) { |
| | | String orderNo = valueToString(findValue(payload, names( |
| | | "trade_no", "tradeNo", "merchantSerialNo", "merchant_serial_no", "paymentOrderId", "payment_order_id", |
| | | "transactionId", "transaction_id", "tradeNo", "trade_no" |
| | | ))); |
| | | return StringUtils.hasText(orderNo) ? orderNo : null; |
| | | } |
| | | |
| | | /** |
| | | * notify_type=directpay.status.sync 表示支付结果同步通知。 |
| | | */ |
| | | public String extractNotifyType(JSONObject payload) { |
| | | String notifyType = valueToString(findValue(payload, names("notify_type", "notifyType"))); |
| | | return StringUtils.hasText(notifyType) ? notifyType : null; |
| | | } |
| | | |
| | | public String extractMessage(JSONObject payload) { |
| | | String message = valueToString(findValue(payload, names("msg", "message", "errorMsg", "errorMessage", "trade_status", "notify_type"))); |
| | | return StringUtils.hasText(message) ? message : "支付回调处理失败"; |
| | | } |
| | | |
| | | private Set<String> names(String... names) { |
| | | return new HashSet<>(Arrays.asList(names)); |
| | | } |
| | | |
| | | private Object findValue(Object current, Set<String> names) { |
| | | if (current == null) { |
| | | return null; |
| | | } |
| | | if (current instanceof JSONObject) { |
| | | JSONObject jsonObject = (JSONObject) current; |
| | | for (String key : jsonObject.keySet()) { |
| | | if (names.contains(key)) { |
| | | return jsonObject.get(key); |
| | | } |
| | | } |
| | | for (String key : jsonObject.keySet()) { |
| | | Object found = findValue(jsonObject.get(key), names); |
| | | if (found != null) { |
| | | return found; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | if (current instanceof JSONArray) { |
| | | JSONArray jsonArray = (JSONArray) current; |
| | | for (Object item : jsonArray) { |
| | | Object found = findValue(item, names); |
| | | if (found != null) { |
| | | return found; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private String valueToString(Object value) { |
| | | return value == null ? null : String.valueOf(value); |
| | | } |
| | | } |
| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.Map; |
| | |
| | | if (request == null) { |
| | | throw new IllegalArgumentException("request must not be null"); |
| | | } |
| | | if (!StringUtils.hasText(request.getTenant())) { |
| | | throw new IllegalArgumentException("tenant must not be blank"); |
| | | } |
| | | if (!StringUtils.hasText(request.getPaymentOrderType())) { |
| | | throw new IllegalArgumentException("paymentOrderType must not be blank"); |
| | | } |
| | | if (!StringUtils.hasText(request.getOutRequestNo())) { |
| | | throw new IllegalArgumentException("outRequestNo must not be blank"); |
| | | } |
| | | if (request.getPaymentOrderAmount() == null) { |
| | | throw new IllegalArgumentException("paymentOrderAmount must not be null"); |
| | | } |
| | | if (!StringUtils.hasText(request.getCurrency())) { |
| | | throw new IllegalArgumentException("currency must not be blank"); |
| | | } |
| | | if (request.getBuyerId() == null) { |
| | | throw new IllegalArgumentException("buyerId must not be null"); |
| | | } |
| | | if (!StringUtils.hasText(request.getOpenId())) { |
| | | throw new IllegalArgumentException("openId must not be blank"); |
| | | } |
| | | if (!StringUtils.hasText(request.getStoreIds())) { |
| | | throw new IllegalArgumentException("storeIds must not be blank"); |
| | | } |
| | | if (!StringUtils.hasText(request.getPayChannelCode())) { |
| | | throw new IllegalArgumentException("payChannelCode must not be blank"); |
| | | } |
| | | if (!StringUtils.hasText(request.getPayEndTime())) { |
| | | throw new IllegalArgumentException("payEndTime must not be blank"); |
| | |
| | | */ |
| | | public static CreatePayOrderRequest mockRequest() { |
| | | CreatePayOrderRequest request = new CreatePayOrderRequest(); |
| | | request.setTenant(DEFAULT_TENANT); |
| | | request.setPaymentOrderType(PAYMENT_ORDER_TYPE); |
| | | request.setOutRequestNo("TEST" + System.currentTimeMillis()); |
| | | request.setPaymentOrderAmount(new BigDecimal("100")); |
| | | request.setCurrency(DEFAULT_CURRENCY); |
| | | request.setBuyerId(10001L); |
| | | request.setOpenId("oMockOpenId123456789"); |
| | | request.setStoreIds("[246]"); |
| | | request.setPayChannelCode(DEFAULT_PAY_CHANNEL_CODE); |
| | | request.setPayEndTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(System.currentTimeMillis() + 30L * 60L * 1000L))); |
| | | request.setCallbackUrl("http://127.0.0.1:8080/pay/mockCallback"); |
| | | return request; |
| | |
| | | */ |
| | | public static class CreatePayOrderRequest { |
| | | |
| | | private String tenant; |
| | | private String paymentOrderType; |
| | | private String outRequestNo; |
| | | private BigDecimal paymentOrderAmount; |
| | | private String currency; |
| | | private Long buyerId; |
| | | private String openId; |
| | | private String storeIds; |
| | | private String payChannelCode; |
| | | private String payEndTime; |
| | | private String callbackUrl; |
| | | |
| | | public Map<String, Object> toParamMap() { |
| | | Map<String, Object> params = new LinkedHashMap<>(); |
| | | params.put("tenant", tenant); |
| | | params.put("paymentOrderType", paymentOrderType); |
| | | params.put("tenant", DEFAULT_TENANT); |
| | | params.put("paymentOrderType", PAYMENT_ORDER_TYPE); |
| | | params.put("outRequestNo", outRequestNo); |
| | | params.put("paymentOrderAmount", paymentOrderAmount); |
| | | params.put("currency", currency); |
| | | params.put("currency", DEFAULT_CURRENCY); |
| | | params.put("buyerId", buyerId); |
| | | params.put("openId", openId); |
| | | params.put("storeIds", storeIds); |
| | | params.put("payChannelCode", payChannelCode); |
| | | params.put("storeIds", Arrays.asList("246")); |
| | | params.put("payChannelCode", DEFAULT_PAY_CHANNEL_CODE); |
| | | params.put("payEndTime", payEndTime); |
| | | params.put("callbackUrl", callbackUrl); |
| | | return params; |
| | | } |
| | | |
| | | public String getTenant() { |
| | | return tenant; |
| | | } |
| | | |
| | | public void setTenant(String tenant) { |
| | | this.tenant = tenant; |
| | | } |
| | | |
| | | public String getPaymentOrderType() { |
| | | return paymentOrderType; |
| | | } |
| | | |
| | | public void setPaymentOrderType(String paymentOrderType) { |
| | | this.paymentOrderType = paymentOrderType; |
| | | } |
| | | |
| | | public String getOutRequestNo() { |
| | | return outRequestNo; |
| | |
| | | this.paymentOrderAmount = paymentOrderAmount; |
| | | } |
| | | |
| | | public String getCurrency() { |
| | | return currency; |
| | | } |
| | | |
| | | public void setCurrency(String currency) { |
| | | this.currency = currency; |
| | | } |
| | | |
| | | public Long getBuyerId() { |
| | | return buyerId; |
| | |
| | | this.openId = openId; |
| | | } |
| | | |
| | | public String getStoreIds() { |
| | | return storeIds; |
| | | } |
| | | |
| | | public void setStoreIds(String storeIds) { |
| | | this.storeIds = storeIds; |
| | | } |
| | | |
| | | public String getPayChannelCode() { |
| | | return payChannelCode; |
| | | } |
| | | |
| | | public void setPayChannelCode(String payChannelCode) { |
| | | this.payChannelCode = payChannelCode; |
| | | } |
| | | |
| | | public String getPayEndTime() { |
| | | return payEndTime; |
| | |
| | | private PayMoneyUtil payMoneyUtil; |
| | | |
| | | @Autowired |
| | | private CbyzxOrderPayHelper cbyzxOrderPayHelper; |
| | | |
| | | @Autowired |
| | | private IPaymentRecordService paymentRecordService; |
| | | |
| | | @Autowired |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 创博优完成订单支付回调。 |
| | | * out_trade_no 为平台订单号,用于反解订单id和订单类型; |
| | | * trade_no 为创博优支付流水号,用于标记真实支付流水; |
| | | * trade_status=TRADE_SUCCESS 才认为支付成功。 |
| | | */ |
| | | @ResponseBody |
| | | @PostMapping("/base/cbyzxPayOrderTaxi") |
| | | public Map<String, Object> cbyzxPayOrderTaxi(HttpServletRequest request) { |
| | | try { |
| | | JSONObject payload = cbyzxOrderPayHelper.parseCallbackRequest(request); |
| | | log.info("创博优完成订单支付回调,notify_type={}, out_trade_no={}, trade_no={}, trade_status={}", |
| | | cbyzxOrderPayHelper.extractNotifyType(payload), |
| | | cbyzxOrderPayHelper.extractOutRequestNo(payload), |
| | | cbyzxOrderPayHelper.extractThirdPartyOrderNo(payload), |
| | | payload == null ? null : payload.getString("trade_status")); |
| | | if (payload == null) { |
| | | return buildCbyzxCallbackResponse(1, "invalid request"); |
| | | } |
| | | if (!cbyzxOrderPayHelper.isPaySuccess(payload)) { |
| | | return buildCbyzxCallbackResponse(1, cbyzxOrderPayHelper.extractMessage(payload)); |
| | | } |
| | | |
| | | String outRequestNo = cbyzxOrderPayHelper.extractOutRequestNo(payload); |
| | | if (StringUtils.isBlank(outRequestNo)) { |
| | | return buildCbyzxCallbackResponse(1, "missing outRequestNo"); |
| | | } |
| | | |
| | | String[] split = outRequestNo.split("_"); |
| | | if (split.length < 2) { |
| | | return buildCbyzxCallbackResponse(1, "invalid outRequestNo"); |
| | | } |
| | | Integer id = Integer.valueOf(split[0]); |
| | | Integer type = Integer.valueOf(split[1]); |
| | | String recordCode = StringUtils.defaultIfBlank(cbyzxOrderPayHelper.extractRecordCode(payload), outRequestNo); |
| | | String orderId = StringUtils.defaultIfBlank(cbyzxOrderPayHelper.extractThirdPartyOrderNo(payload), recordCode); |
| | | |
| | | switch (type) { |
| | | case 1: |
| | | orderPrivateCarService.payOrderPrivateCarCallback(id, orderId, 1, recordCode); |
| | | break; |
| | | case 2: |
| | | orderTaxiService.payOrderTaxiCallback(id, orderId, 1, 0, recordCode); |
| | | break; |
| | | case 3: |
| | | orderCrossCityService.payOrderCrossCityCallback(id, orderId, 1, recordCode); |
| | | break; |
| | | case 4: |
| | | orderLogisticsService.payOrderLogisticsCallback(id, orderId, 1); |
| | | break; |
| | | case 5: |
| | | orderLogisticsService.payOrderLogisticsCallback(id, orderId, 1); |
| | | break; |
| | | default: |
| | | return buildCbyzxCallbackResponse(1, "unsupported orderType"); |
| | | } |
| | | return buildCbyzxCallbackResponse(0, "success"); |
| | | } catch (Exception e) { |
| | | log.error("创博优完成订单支付回调处理失败", e); |
| | | return buildCbyzxCallbackResponse(1, "fail"); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 完成订单支付宝支付回调 |
| | |
| | | } |
| | | } |
| | | |
| | | private Map<String, Object> buildCbyzxCallbackResponse(Integer code, String msg) { |
| | | Map<String, Object> result = new HashMap<>(); |
| | | result.put("code", code); |
| | | result.put("msg", msg); |
| | | return result; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 小件物流差价微信支付回调 |
| | |
| | | private PayMoneyUtil payMoneyUtil; |
| | | |
| | | @Autowired |
| | | private CbyzxOrderPayHelper cbyzxOrderPayHelper; |
| | | |
| | | @Autowired |
| | | private ICompanyService companyService; |
| | | |
| | | @Autowired |
| | |
| | | } |
| | | |
| | | if (payType == 1) {//微信支付 |
| | | String app = type == 1 ? "APP" : "JSAPI"; |
| | | resultUtil = payMoneyUtil.weixinpay("完成订单", "", orderId + "_3_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/wxPayOrderTaxi", app, userInfo.getAppletsOpenId()); |
| | | paymentRecordService.saveData(1, orderCrossCity.getUserId(), 1, orderId, 3, 1, orderMoney, "", 1);//添加预支付数据 |
| | | String outTradeNo = orderId + "_3_" + UUIDUtil.getRandomCode(5); |
| | | JSONObject response = cbyzxOrderPayHelper.createOrder(orderCrossCity.getUserId(), userInfo.getAppletsOpenId(), outTradeNo, orderMoney); |
| | | if (!cbyzxOrderPayHelper.isCreateSuccess(response)) { |
| | | return ResultUtil.error(cbyzxOrderPayHelper.extractMessage(response), response); |
| | | } |
| | | String paymentCode = ToolUtil.isNotEmpty(cbyzxOrderPayHelper.extractRecordCode(response)) ? cbyzxOrderPayHelper.extractRecordCode(response) : outTradeNo; |
| | | resultUtil = ResultUtil.success(response); |
| | | paymentRecordService.saveData(1, orderCrossCity.getUserId(), 1, orderId, 3, 1, orderMoney, paymentCode, 1);//添加预支付数据 |
| | | } |
| | | if (payType == 2) {//支付宝支付 |
| | | resultUtil = payMoneyUtil.alipay("完成订单", "完成订单", "", orderId + "_3_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/aliPayOrderTaxi"); |
| | |
| | | if (orderMoney == 0) { |
| | | return ResultUtil.error("请使用余额支付"); |
| | | } |
| | | String app = type == 1 ? "APP" : "JSAPI"; |
| | | resultUtil = payMoneyUtil.weixinpay("完成订单", "", orderId + "_3_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/wxPayOrderTaxi", app, userInfo.getAppletsOpenId()); |
| | | |
| | | String outTradeNo = orderId + "_3_" + UUIDUtil.getRandomCode(5); |
| | | JSONObject response = cbyzxOrderPayHelper.createOrder(orderCrossCity.getUserId(), userInfo.getAppletsOpenId(), outTradeNo, orderMoney); |
| | | if (!cbyzxOrderPayHelper.isCreateSuccess(response)) { |
| | | return ResultUtil.error(cbyzxOrderPayHelper.extractMessage(response), response); |
| | | } |
| | | String paymentCode = ToolUtil.isNotEmpty(cbyzxOrderPayHelper.extractRecordCode(response)) ? cbyzxOrderPayHelper.extractRecordCode(response) : outTradeNo; |
| | | resultUtil = ResultUtil.success(response); |
| | | this.updateById(orderCrossCity); |
| | | paymentRecordService.saveData(1, orderCrossCity.getUserId(), 1, orderId, 3, 1, orderMoney, "", 1);//添加预支付数据 |
| | | paymentRecordService.saveData(1, orderCrossCity.getUserId(), 1, orderId, 3, 1, orderMoney, paymentCode, 1);//添加预支付数据 |
| | | } |
| | | if (payType == 2) {//支付宝支付 |
| | | if (orderMoney == 0) { |
| | |
| | | @Override |
| | | public void payOrderCrossCityCallback(Integer id, String order_id, Integer type, String no) throws Exception { |
| | | OrderCrossCity orderCrossCity = this.selectById(id); |
| | | PaymentRecord query = paymentRecordService.query(1, orderCrossCity.getUserId(), 1, Integer.valueOf(id), 3, type, 1); |
| | | PaymentRecord query = ToolUtil.isNotEmpty(no) ? paymentRecordService.queryByCode(no, 1) : null; |
| | | if (query == null) { |
| | | query = paymentRecordService.query(1, orderCrossCity.getUserId(), 1, Integer.valueOf(id), 3, type, 1); |
| | | } |
| | | if (null != query && query.getState() == 1) { |
| | | //添加交易明细 |
| | | transactionDetailsService.saveData(orderCrossCity.getUserId(), "跨城出行订单", query.getAmount(), 2, 1, 1, 3, query.getOrderId()); |
| | |
| | | |
| | | @Autowired |
| | | private PayMoneyUtil payMoneyUtil; |
| | | |
| | | @Autowired |
| | | private CbyzxOrderPayHelper cbyzxOrderPayHelper; |
| | | |
| | | @Resource |
| | | private OrderPrivateCarMapper orderPrivateCarMapper; |
| | |
| | | ResultUtil resultUtil = ResultUtil.success(new Object()); |
| | | |
| | | if(payType == 1){//微信支付 |
| | | String app = type == 1 ? "APP" : "JSAPI"; |
| | | resultUtil = payMoneyUtil.weixinpay("小件物流下单支付", "", orderId + "_" + orderLogistics.getType() + "_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/wxPayOrderTaxi", app, userInfo.getAppletsOpenId()); |
| | | paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 1, orderMoney, "", 1);//添加预支付数据 |
| | | String outTradeNo = orderId + "_" + orderLogistics.getType() + "_" + UUIDUtil.getRandomCode(5); |
| | | JSONObject response = cbyzxOrderPayHelper.createOrder(orderLogistics.getUserId(), userInfo.getAppletsOpenId(), outTradeNo, orderMoney); |
| | | if (!cbyzxOrderPayHelper.isCreateSuccess(response)) { |
| | | return ResultUtil.error(cbyzxOrderPayHelper.extractMessage(response), response); |
| | | } |
| | | String paymentCode = ToolUtil.isNotEmpty(cbyzxOrderPayHelper.extractRecordCode(response)) ? cbyzxOrderPayHelper.extractRecordCode(response) : outTradeNo; |
| | | resultUtil = ResultUtil.success(response); |
| | | paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 1, orderMoney, paymentCode, 1);//添加预支付数据 |
| | | } |
| | | if(payType == 2){//支付宝支付 |
| | | resultUtil = payMoneyUtil.alipay("小件物流下单支付", "小件物流下单支付", "", orderId + "_" + orderLogistics.getType() + "_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/aliPayOrderTaxi"); |
| | |
| | | if(orderMoney == 0){ |
| | | return ResultUtil.error("请使用余额支付"); |
| | | } |
| | | String app = type == 1 ? "APP" : "JSAPI"; |
| | | resultUtil = payMoneyUtil.weixinpay("小件物流下单支付", "", orderId + "_" + orderLogistics.getType() + "_" + UUIDUtil.getRandomCode(5), orderMoney.toString(), "/base/wxPayOrderTaxi", app, userInfo.getAppletsOpenId()); |
| | | paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 1, orderMoney, "", 1);//添加预支付数据 |
| | | String outTradeNo = orderId + "_" + orderLogistics.getType() + "_" + UUIDUtil.getRandomCode(5); |
| | | JSONObject response = cbyzxOrderPayHelper.createOrder(orderLogistics.getUserId(), userInfo.getAppletsOpenId(), outTradeNo, orderMoney); |
| | | if (!cbyzxOrderPayHelper.isCreateSuccess(response)) { |
| | | return ResultUtil.error(cbyzxOrderPayHelper.extractMessage(response), response); |
| | | } |
| | | String paymentCode = ToolUtil.isNotEmpty(cbyzxOrderPayHelper.extractRecordCode(response)) ? cbyzxOrderPayHelper.extractRecordCode(response) : outTradeNo; |
| | | resultUtil = ResultUtil.success(response); |
| | | paymentRecordService.saveData(1, orderLogistics.getUserId(), 1, orderId, orderLogistics.getType(), 1, orderMoney, paymentCode, 1);//添加预支付数据 |
| | | } |
| | | if(payType == 2){//支付宝支付 |
| | | if(orderMoney == 0){ |
| | |
| | | private IOrderTaxiService orderTaxiService; |
| | | @Autowired |
| | | private PayMoneyUtil payMoneyUtil; |
| | | |
| | | @Autowired |
| | | private CbyzxOrderPayHelper cbyzxOrderPayHelper; |
| | | @Autowired |
| | | private TAbnormalPayOrderMapper abnormalPayOrderMapper; |
| | | @Autowired |
| | |
| | | } |
| | | orderMoney = orderMoney < 0 ? 0 : orderMoney; |
| | | if (payType == 1) {//微信支付 |
| | | String app = type == 1 ? "APP" : "JSAPI"; |
| | | String outTradeNo = orderId + "_1_" + UUIDUtil.getRandomCode(5); |
| | | resultUtil = payMoneyUtil.weixinpay("完成订单", "", outTradeNo, orderMoney.toString(), "/base/wxPayOrderTaxi", app, userInfo.getAppletsOpenId()); |
| | | paymentRecordService.saveData(1, orderPrivateCar.getUserId(), 1, orderId, 1, 1, orderMoney, outTradeNo, 1);//添加预支付数据 |
| | | JSONObject response = cbyzxOrderPayHelper.createOrder(orderPrivateCar.getUserId(), userInfo.getAppletsOpenId(), outTradeNo, orderMoney); |
| | | if (!cbyzxOrderPayHelper.isCreateSuccess(response)) { |
| | | return ResultUtil.error(cbyzxOrderPayHelper.extractMessage(response), response); |
| | | } |
| | | String paymentCode = ToolUtil.isNotEmpty(cbyzxOrderPayHelper.extractRecordCode(response)) ? cbyzxOrderPayHelper.extractRecordCode(response) : outTradeNo; |
| | | resultUtil = ResultUtil.success(response); |
| | | paymentRecordService.saveData(1, orderPrivateCar.getUserId(), 1, orderId, 1, 1, orderMoney, paymentCode, 1);//添加预支付数据 |
| | | } |
| | | if (payType == 2) {//支付宝支付 |
| | | String outTradeNo = orderId + "_1_" + UUIDUtil.getRandomCode(5); |
| | |
| | | if (orderMoney == 0) { |
| | | return ResultUtil.error("请使用余额支付"); |
| | | } |
| | | String app = type == 1 ? "APP" : "JSAPI"; |
| | | String outTradeNo = orderId + "_1_" + UUIDUtil.getRandomCode(5); |
| | | resultUtil = payMoneyUtil.weixinpay("完成订单", "", outTradeNo, orderMoney.toString(), "/base/wxPayOrderTaxi", app, userInfo.getAppletsOpenId()); |
| | | paymentRecordService.saveData(1, orderPrivateCar.getUserId(), 1, orderId, 1, 1, orderMoney, outTradeNo, 1);//添加预支付数据 |
| | | JSONObject response = cbyzxOrderPayHelper.createOrder(orderPrivateCar.getUserId(), userInfo.getAppletsOpenId(), outTradeNo, orderMoney); |
| | | if (!cbyzxOrderPayHelper.isCreateSuccess(response)) { |
| | | return ResultUtil.error(cbyzxOrderPayHelper.extractMessage(response), response); |
| | | } |
| | | String paymentCode = ToolUtil.isNotEmpty(cbyzxOrderPayHelper.extractRecordCode(response)) ? cbyzxOrderPayHelper.extractRecordCode(response) : outTradeNo; |
| | | resultUtil = ResultUtil.success(response); |
| | | paymentRecordService.saveData(1, orderPrivateCar.getUserId(), 1, orderId, 1, 1, orderMoney, paymentCode, 1);//添加预支付数据 |
| | | |
| | | //创建定时任务查询订单支付状态 |
| | | ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); |
| New file |
| | |
| | | package com.stylefeng.guns.modular.system.util; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | import java.util.HashSet; |
| | | import java.util.Set; |
| | | |
| | | /** |
| | | * 创博优订单支付适配工具。 |
| | | */ |
| | | @Component |
| | | public class CbyzxOrderPayHelper { |
| | | |
| | | private static final String CALLBACK_PATH = "/base/cbyzxPayOrderTaxi"; |
| | | private static final Set<String> SUCCESS_STATUS = new HashSet<>(Arrays.asList( |
| | | "SUCCESS", "SUCCEEDED", "PAY_SUCCESS", "TRADE_SUCCESS", "PAID", "PAYED", "1", "00", "TRUE" |
| | | )); |
| | | private static final Set<String> FAIL_STATUS = new HashSet<>(Arrays.asList( |
| | | "FAIL", "FAILED", "CLOSED", "CANCEL", "CANCELED", "CANCELLED", "0", "FALSE" |
| | | )); |
| | | |
| | | @Value("${callbackPath}") |
| | | private String callbackPath; |
| | | |
| | | public JSONObject createOrder(Integer buyerId, String openId, String outRequestNo, Double amount) { |
| | | CbyzxPayUtil.CreatePayOrderRequest request = new CbyzxPayUtil.CreatePayOrderRequest(); |
| | | request.setOutRequestNo(outRequestNo); |
| | | request.setPaymentOrderAmount(new BigDecimal(String.valueOf(amount)).setScale(2, RoundingMode.HALF_UP)); |
| | | request.setBuyerId(Long.valueOf(String.valueOf(buyerId))); |
| | | request.setOpenId(openId); |
| | | request.setPayEndTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(System.currentTimeMillis() + 30L * 60L * 1000L))); |
| | | request.setCallbackUrl(buildCallbackUrl()); |
| | | return CbyzxPayUtil.createPayOrder(request); |
| | | } |
| | | |
| | | public String buildCallbackUrl() { |
| | | return callbackPath + CALLBACK_PATH; |
| | | } |
| | | |
| | | public boolean isCreateSuccess(JSONObject response) { |
| | | if (response == null) { |
| | | return false; |
| | | } |
| | | Object code = findValue(response, names("code")); |
| | | if (code != null && "0".equals(String.valueOf(code))) { |
| | | return true; |
| | | } |
| | | Object success = findValue(response, names("success")); |
| | | return success != null && Boolean.parseBoolean(String.valueOf(success)); |
| | | } |
| | | |
| | | /** |
| | | * 解析创博优表单回调参数。 |
| | | * out_trade_no 为平台订单号,trade_no 为三方支付流水号。 |
| | | */ |
| | | public JSONObject parseCallbackRequest(HttpServletRequest request) { |
| | | if (request == null || request.getParameterMap() == null || request.getParameterMap().isEmpty()) { |
| | | return null; |
| | | } |
| | | JSONObject payload = new JSONObject(); |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * trade_status=TRADE_SUCCESS 视为支付成功。 |
| | | */ |
| | | public boolean isPaySuccess(JSONObject payload) { |
| | | if (payload == null) { |
| | | return false; |
| | | } |
| | | Object status = findValue(payload, names("trade_status", "tradeStatus", "payStatus", "paymentStatus", "status", "result", "resultCode", "state")); |
| | | if (status != null) { |
| | | String normalized = String.valueOf(status).trim().toUpperCase(); |
| | | if (SUCCESS_STATUS.contains(normalized)) { |
| | | return true; |
| | | } |
| | | if (FAIL_STATUS.contains(normalized)) { |
| | | return false; |
| | | } |
| | | } |
| | | Object success = findValue(payload, names("success")); |
| | | if (success != null) { |
| | | return Boolean.parseBoolean(String.valueOf(success)); |
| | | } |
| | | Object code = findValue(payload, names("code")); |
| | | return code != null && "0".equals(String.valueOf(code)) && org.springframework.util.StringUtils.hasText(extractOutRequestNo(payload)); |
| | | } |
| | | |
| | | /** |
| | | * out_trade_no 为平台侧订单号,格式为 orderId_orderType_random。 |
| | | */ |
| | | public String extractOutRequestNo(JSONObject payload) { |
| | | return valueToString(findValue(payload, names("outRequestNo", "out_trade_no"))); |
| | | } |
| | | |
| | | /** |
| | | * 回查本地支付记录时优先使用 out_trade_no。 |
| | | */ |
| | | public String extractRecordCode(JSONObject payload) { |
| | | String code = valueToString(findValue(payload, names("out_trade_no", "outRequestNo", "merchantSerialNo", "merchant_serial_no"))); |
| | | return StringUtils.hasText(code) ? code : null; |
| | | } |
| | | |
| | | /** |
| | | * trade_no 为创博优侧交易流水号,用于标记实际支付成功流水。 |
| | | */ |
| | | public String extractThirdPartyOrderNo(JSONObject payload) { |
| | | String orderNo = valueToString(findValue(payload, names( |
| | | "trade_no", "tradeNo", "merchantSerialNo", "merchant_serial_no", "paymentOrderId", "payment_order_id", |
| | | "transactionId", "transaction_id", "tradeNo", "trade_no" |
| | | ))); |
| | | return StringUtils.hasText(orderNo) ? orderNo : null; |
| | | } |
| | | |
| | | /** |
| | | * notify_type=directpay.status.sync 表示支付结果同步通知。 |
| | | */ |
| | | public String extractNotifyType(JSONObject payload) { |
| | | String notifyType = valueToString(findValue(payload, names("notify_type", "notifyType"))); |
| | | return StringUtils.hasText(notifyType) ? notifyType : null; |
| | | } |
| | | |
| | | public String extractMessage(JSONObject payload) { |
| | | String message = valueToString(findValue(payload, names("msg", "message", "errorMsg", "errorMessage", "trade_status", "notify_type"))); |
| | | return StringUtils.hasText(message) ? message : "支付回调处理失败"; |
| | | } |
| | | |
| | | private Set<String> names(String... names) { |
| | | return new HashSet<>(Arrays.asList(names)); |
| | | } |
| | | |
| | | private Object findValue(Object current, Set<String> names) { |
| | | if (current == null) { |
| | | return null; |
| | | } |
| | | if (current instanceof JSONObject) { |
| | | JSONObject jsonObject = (JSONObject) current; |
| | | for (String key : jsonObject.keySet()) { |
| | | if (names.contains(key)) { |
| | | return jsonObject.get(key); |
| | | } |
| | | } |
| | | for (String key : jsonObject.keySet()) { |
| | | Object found = findValue(jsonObject.get(key), names); |
| | | if (found != null) { |
| | | return found; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | if (current instanceof JSONArray) { |
| | | JSONArray jsonArray = (JSONArray) current; |
| | | for (Object item : jsonArray) { |
| | | Object found = findValue(item, names); |
| | | if (found != null) { |
| | | return found; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | private String valueToString(Object value) { |
| | | return value == null ? null : String.valueOf(value); |
| | | } |
| | | } |
| | |
| | | |
| | | @Autowired |
| | | private PayMoneyUtil payMoneyUtil; |
| | | |
| | | @Autowired |
| | | private CbyzxOrderPayHelper cbyzxOrderPayHelper; |
| | | |
| | | @Autowired |
| | | private ITransactionDetailsService transactionDetailsService; |
| | |
| | | } |
| | | |
| | | if (payType == 1) {//微信支付 |
| | | String app = type == 1 ? "APP" : "JSAPI"; |
| | | String outTradeNo = orderId + "_2_" + UUIDUtil.getRandomCode(5); |
| | | resultUtil = payMoneyUtil.weixinpay("完成订单", "", outTradeNo, orderMoney.toString(), "/base/wxPayOrderTaxi", app, userInfo.getAppletsOpenId()); |
| | | paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, orderId, 2, 1, orderMoney, outTradeNo, 1);//添加预支付数据 |
| | | JSONObject response = cbyzxOrderPayHelper.createOrder(orderTaxi.getUserId(), userInfo.getAppletsOpenId(), outTradeNo, orderMoney); |
| | | if (!cbyzxOrderPayHelper.isCreateSuccess(response)) { |
| | | return ResultUtil.error(cbyzxOrderPayHelper.extractMessage(response), response); |
| | | } |
| | | String paymentCode = ToolUtil.isNotEmpty(cbyzxOrderPayHelper.extractRecordCode(response)) ? cbyzxOrderPayHelper.extractRecordCode(response) : outTradeNo; |
| | | resultUtil = ResultUtil.success(response); |
| | | paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, orderId, 2, 1, orderMoney, paymentCode, 1);//添加预支付数据 |
| | | } |
| | | if (payType == 2) {//支付宝支付 |
| | | String outTradeNo = orderId + "_2_" + UUIDUtil.getRandomCode(5); |
| | |
| | | if (orderMoney == 0) { |
| | | return ResultUtil.error("请使用余额支付"); |
| | | } |
| | | String app = type == 1 ? "APP" : "JSAPI"; |
| | | String outTradeNo = orderId + "_2_" + UUIDUtil.getRandomCode(5); |
| | | resultUtil = payMoneyUtil.weixinpay("完成订单", "", outTradeNo, orderMoney.toString(), "/base/wxPayOrderTaxi", app, userInfo.getAppletsOpenId()); |
| | | |
| | | paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, orderId, 2, 1, orderMoney, outTradeNo, 1);//添加预支付数据 |
| | | JSONObject response = cbyzxOrderPayHelper.createOrder(orderTaxi.getUserId(), userInfo.getAppletsOpenId(), outTradeNo, orderMoney); |
| | | if (!cbyzxOrderPayHelper.isCreateSuccess(response)) { |
| | | return ResultUtil.error(cbyzxOrderPayHelper.extractMessage(response), response); |
| | | } |
| | | String paymentCode = ToolUtil.isNotEmpty(cbyzxOrderPayHelper.extractRecordCode(response)) ? cbyzxOrderPayHelper.extractRecordCode(response) : outTradeNo; |
| | | resultUtil = ResultUtil.success(response); |
| | | paymentRecordService.saveData(1, orderTaxi.getUserId(), 1, orderId, 2, 1, orderMoney, paymentCode, 1);//添加预支付数据 |
| | | } |
| | | if (payType == 2) {//支付宝支付 |
| | | if (orderMoney == 0) { |