| | |
| | | import java.math.BigDecimal; |
| | | import java.math.MathContext; |
| | | import java.math.RoundingMode; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | |
| | | |
| | |
| | | if(ToolUtil.isEmpty(userInfo.getAppletsOpenId())){ |
| | | return ResultUtil.error("未授权微信,无法完成支付"); |
| | | } |
| | | String code = id + "_1_" + UUIDUtil.getRandomCode(3); |
| | | orderCancel.setPayType(1); |
| | | orderCancelService.updateById(orderCancel); |
| | | resultUtil = payMoneyUtil.weixinpay("订单取消",id +"",id + "_1_" + UUIDUtil.getRandomCode(3),query.getMoney()+"","/base/wxCancelOrderTaxi","JSAPI",userInfo.getAppletsOpenId()); |
| | | //Map<String, String> map = icbcPayUtil.placeAnOrder(id + ",1", 9, 5, uid.toString(), "订单取消", query.getMoney(), callbackPath + "/base/wxCancelOrderTaxi", "", type, userInfo.getAppletsOpenId()); |
| | | resultUtil = payMoneyUtil.weixinpay("订单取消",id +"",code,query.getMoney()+"","/base/wxCancelOrderTaxi","JSAPI",userInfo.getAppletsOpenId()); |
| | | if(resultUtil.getCode()==200){ |
| | | paymentRecordService.saveData(1, null, null, id, 1, 1, query.getMoney(), null, 1);//添加预支付数据 |
| | | resultUtil = resultUtil; |
| | | new Thread(()->{ |
| | | int num = 1; |
| | | int min = 5000; |
| | | int w = 0; |
| | | while (num <= 10) { |
| | | try { |
| | | w += min * num; |
| | | OrderPrivateCar orderPrivateCar1 = orderPrivateCarMapper.selectById(id); |
| | | if (orderPrivateCar1.getState() == 10) { |
| | | break; |
| | | } |
| | | ResultUtil<Map<String, Object>> resultUtil1 = payMoneyUtil.queryWXOrder("", code, "JSAPI"); |
| | | if (resultUtil1.getCode() == 200) { |
| | | /** |
| | | * SUCCESS--支付成功 |
| | | * REFUND--转入退款 |
| | | * NOTPAY--未支付 |
| | | * CLOSED--已关闭 |
| | | * REVOKED--已撤销(刷卡支付) |
| | | * USERPAYING--用户支付中 |
| | | * PAYERROR--支付失败(其他原因,如银行返回失败) |
| | | * ACCEPT--已接收,等待扣款 |
| | | */ |
| | | String s = resultUtil1.getData().get("trade_state").toString(); |
| | | if ("REFUND".equals(s) || "CLOSED".equals(s) || "REVOKED".equals(s) || "PAYERROR".equals(s) || num == 10) { |
| | | break; |
| | | } |
| | | if ("SUCCESS".equals(s) || "ACCEPT".equals(s)) { |
| | | String transaction_id = resultUtil1.getData().get("transaction_id").toString(); |
| | | payCancelOrderPrivateCar(id, transaction_id, 1); |
| | | break; |
| | | } |
| | | if ("NOTPAY".equals(s) || "USERPAYING".equals(s)) { |
| | | Thread.sleep(w); |
| | | num++; |
| | | } |
| | | } else { |
| | | Thread.sleep(w); |
| | | num++; |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }).start(); |
| | | |
| | | }else{ |
| | | resultUtil = ResultUtil.error("支付失败", ""); |
| | | } |
| | |
| | | return ResultUtil.error("未授权微信,无法完成支付"); |
| | | } |
| | | if(payType == 1){//微信支付 |
| | | resultUtil = payMoneyUtil.weixinpay("完成订单",orderId +"",orderId + "_1_" + UUIDUtil.getRandomCode(3),orderMoney+"","/base/wxPayOrderTaxi","JSAPI",userInfo.getAppletsOpenId()); |
| | | String code = orderId + "_1_" + UUIDUtil.getRandomCode(3); |
| | | resultUtil = payMoneyUtil.weixinpay("完成订单",orderId +"",code,orderMoney+"","/base/wxPayOrderTaxi","JSAPI",userInfo.getAppletsOpenId()); |
| | | if(resultUtil.getCode()==200){ |
| | | paymentRecordService.saveData(1, null, null, orderId, 1, 1, orderMoney, null, 1);//添加预支付数据 |
| | | new Thread(()->{ |
| | | int num = 1; |
| | | int min = 5000; |
| | | int w = 0; |
| | | while (num <= 10) { |
| | | try { |
| | | w += min * num; |
| | | OrderPrivateCar orderPrivateCar1 = orderPrivateCarMapper.selectById(orderId); |
| | | if (orderPrivateCar1.getState() != 7) { |
| | | break; |
| | | } |
| | | ResultUtil<Map<String, Object>> resultUtil1 = payMoneyUtil.queryWXOrder("", code, "JSAPI"); |
| | | if (resultUtil1.getCode() == 200) { |
| | | /** |
| | | * SUCCESS--支付成功 |
| | | * REFUND--转入退款 |
| | | * NOTPAY--未支付 |
| | | * CLOSED--已关闭 |
| | | * REVOKED--已撤销(刷卡支付) |
| | | * USERPAYING--用户支付中 |
| | | * PAYERROR--支付失败(其他原因,如银行返回失败) |
| | | * ACCEPT--已接收,等待扣款 |
| | | */ |
| | | String s = resultUtil1.getData().get("trade_state").toString(); |
| | | if ("REFUND".equals(s) || "CLOSED".equals(s) || "REVOKED".equals(s) || "PAYERROR".equals(s) || num == 10) { |
| | | break; |
| | | } |
| | | if ("SUCCESS".equals(s) || "ACCEPT".equals(s)) { |
| | | String transaction_id = resultUtil1.getData().get("transaction_id").toString(); |
| | | payOrderPrivateCarCallback(orderId, transaction_id, 1); |
| | | break; |
| | | } |
| | | if ("NOTPAY".equals(s) || "USERPAYING".equals(s)) { |
| | | Thread.sleep(w); |
| | | num++; |
| | | } |
| | | } else { |
| | | Thread.sleep(w); |
| | | num++; |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | }).start(); |
| | | }else{ |
| | | resultUtil = ResultUtil.error("支付失败", ""); |
| | | } |
| | |
| | | @Override |
| | | public void payCancelOrderPrivateCar(Integer id, String order_id, Integer type) throws Exception { |
| | | OrderPrivateCar orderPrivateCar = this.selectById(id); |
| | | if(orderPrivateCar.getState() == 10){ |
| | | return; |
| | | } |
| | | PaymentRecord query = paymentRecordService.query(1, null, null, Integer.valueOf(id), 1, type, 1); |
| | | if(null != query){ |
| | | //添加交易明细 |
| | |
| | | @Override |
| | | public void payOrderPrivateCarCallback(Integer id, String order_id, Integer type) throws Exception { |
| | | OrderPrivateCar orderPrivateCar = this.selectById(id); |
| | | if(orderPrivateCar.getState() != 7){ |
| | | return; |
| | | } |
| | | PaymentRecord query = paymentRecordService.query(1, null, null, Integer.valueOf(id), 1, type, 1); |
| | | if(null != query){ |
| | | //添加交易明细 |
| | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 查询微信支付订单 |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public ResultUtil queryWXOrder() throws Exception{ |
| | | public ResultUtil<Map<String, Object>> queryWXOrder(String transaction_id, String out_trade_no, String tradeType) throws Exception{ |
| | | String url = "https://api.mch.weixin.qq.com/pay/orderquery"; |
| | | String nonce_str = UUIDUtil.getRandomCode(16); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("appid", appid); |
| | | map.put("appid", "APP".equals(tradeType) ? appid : appletsAppid); |
| | | map.put("mch_id", mchId); |
| | | map.put("transaction_id", nonce_str);//微信订单号 |
| | | map.put("transaction_id", transaction_id);//微信订单号 |
| | | map.put("out_trade_no", out_trade_no);//商户订单号 |
| | | map.put("nonce_str", nonce_str);//随机字符串 |
| | | String s = this.weixinSignature(map); |
| | | map.put("sign", s); |
| | | |
| | | |
| | | //设置请求头 |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.setContentType(MediaType.APPLICATION_XML); |
| | |
| | | xmlString.append("<" + keys[l] + ">" + map.get(keys[l]) + "</" + keys[l] + ">"); |
| | | } |
| | | xmlString.append("</xml>"); |
| | | |
| | | |
| | | Map<String, String> map1 = null; |
| | | String body1 = httpClientUtil.pushHttpRequsetXml(url, xmlString.toString(), new HashMap<>()).getData(); |
| | | HttpResult httpResult = httpClientUtil.pushHttpRequsetXml(url, xmlString.toString(), new HashMap<>()); |
| | | String body1 = httpResult.getData(); |
| | | //将结果xml解析成map |
| | | body1 = body1.replaceAll("<!\\[CDATA\\[",""); |
| | | body1 = body1.replaceAll("]]>", ""); |
| | |
| | | String result_code = map1.get("result_code"); |
| | | if("SUCCESS".equals(result_code)){ |
| | | String type = map1.get("trade_type"); |
| | | switch (type){ |
| | | case "JSAPI": |
| | | break; |
| | | case "NATIVE": |
| | | String code_url = map1.get("code_url"); |
| | | return ResultUtil.success(code_url); |
| | | case "APP": |
| | | String trade_state = map1.get("trade_state"); |
| | | String time_end = map1.get("time_end"); |
| | | Map<String, Object> map2 = new HashMap<>(); |
| | | map2.put("trade_state", trade_state);//订单状态SUCCESS—支付成功,REFUND—转入退款,NOTPAY—未支付,CLOSED—已关闭,REVOKED—已撤销(刷卡支付),USERPAYING--用户支付中,PAYERROR--支付失败(其他原因,如银行返回失败) |
| | | map2.put("time_end", time_end);//订单支付时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。 |
| | | return ResultUtil.success(map2); |
| | | } |
| | | return null; |
| | | Map<String, Object> map2 = new HashMap<>(); |
| | | String trade_state = map1.get("trade_state"); |
| | | String time_end = map1.get("time_end"); |
| | | String transactionId = map1.get("transaction_id"); |
| | | map2.put("result_code", result_code); |
| | | map2.put("trade_state", trade_state);//订单状态SUCCESS—支付成功,REFUND—转入退款,NOTPAY—未支付,CLOSED—已关闭,REVOKED—已撤销(刷卡支付),USERPAYING--用户支付中,PAYERROR--支付失败(其他原因,如银行返回失败) |
| | | map2.put("time_end", time_end);//订单支付时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。 |
| | | map2.put("transaction_id", transactionId); |
| | | return ResultUtil.success(map2); |
| | | } |
| | | if("FAIL".equals(result_code)){//订单不存在 |
| | | Map<String, Object> map2 = new HashMap<>(); |
| | | map2.put("result_code", result_code); |
| | | return ResultUtil.success(map2); |
| | | }else{ |
| | | System.err.println(map1.get("err_code_des")); |
| | | return ResultUtil.error(map1.get("err_code_des")); |