From 5dc40fcd64b0513150f1d8335ab849e6d8cdc28e Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期五, 04 七月 2025 19:42:49 +0800 Subject: [PATCH] 支付版本更新 根据资金流向使用V2或V3服务商版本支付 --- cloud-server-other/src/main/java/com/dsh/other/controller/SiteController.java | 171 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 161 insertions(+), 10 deletions(-) diff --git a/cloud-server-other/src/main/java/com/dsh/other/controller/SiteController.java b/cloud-server-other/src/main/java/com/dsh/other/controller/SiteController.java index 8c26b25..e5f51b0 100644 --- a/cloud-server-other/src/main/java/com/dsh/other/controller/SiteController.java +++ b/cloud-server-other/src/main/java/com/dsh/other/controller/SiteController.java @@ -15,12 +15,15 @@ import com.dsh.other.feignclient.model.BillingDataRequestVo; import com.dsh.other.feignclient.model.SiteChangeStateVO; import com.dsh.other.feignclient.model.SiteVo; +import com.dsh.other.mapper.TOperatorUserMapper; import com.dsh.other.model.*; import com.dsh.other.model.dto.siteDto.TSiteDTO; import com.dsh.other.model.vo.siteVo.ExpireSiteSearchVO; import com.dsh.other.model.vo.siteVo.SiteSearchVO; import com.dsh.other.service.*; import com.dsh.other.util.*; +import com.dsh.other.util.wx.WxV3PayConfig; +import com.wechat.pay.contrib.apache.httpclient.util.AesUtil; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; @@ -33,7 +36,10 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.BufferedReader; import java.io.PrintWriter; +import java.math.BigDecimal; +import java.nio.charset.StandardCharsets; import java.text.SimpleDateFormat; import java.util.*; import java.util.stream.Collectors; @@ -66,6 +72,8 @@ @Resource private CityManagerClient cityManagerClient; + @Autowired + private IOperatorUserService operatorUserService; @Autowired private TGameConfigService gameConfigService; @@ -75,9 +83,12 @@ @Resource private CourseRecordClient courseRecordClient; +@Resource +private StoreService storeService; @Autowired private RedisUtil redisUtil; + @@ -95,8 +106,44 @@ @RequestMapping("/base/getSMIDByOperatorId") @ResponseBody public String getSMIDByOperatorId(Integer id) { - // 获取运营商的管理员 return siteService.getSMIDByOperatorId(id); + } + /** + * 通过运营商id查询运营商对应的微信商户号 + */ + @RequestMapping("/base/getmerchantNumberByOperatorId/{id}") + @ResponseBody + public String getmerchantNumberByOperatorId(@PathVariable("id")Integer id) { + return siteService.getmerchantNumberByOperatorId(id); + } + + /** + * 通过运营商id 获取支付宝商户号 + * @param id + * @return + */ + @RequestMapping("/base/getmerchantNumberAliByOperatorId/{id}") + @ResponseBody + public String getmerchantNumberAliByOperatorId(@PathVariable("id")Integer id) { + return siteService.getmerchantNumberAliByOperatorId(id); + } + /** + * 根据运营商id获取对应运营商分账比例 返回格式: 微信分账比例,支付宝分账比例 + */ + @RequestMapping("/base/getProportionByOperatorId/{id}") + @ResponseBody + public String getProportionByOperatorId(@PathVariable("id")Integer id) { + OperatorUser operatorId = operatorUserService.getOne( + new QueryWrapper<OperatorUser>().eq("operatorId",id) + ); + if (operatorId.getWechatProportion() == null){ + operatorId.setWechatProportion("0"); + } + if (operatorId.getAlipayProportion() == null){ + operatorId.setAlipayProportion("0"); + } + System.err.println("查询分账比例"+operatorId); + return operatorId.getWechatProportion()+","+operatorId.getAlipayProportion(); } /** * 获取所有场地 @@ -289,6 +336,22 @@ return null; } } + /** + * 根据id获取数据 + * + * @param ids + * @return + */ + @ResponseBody + @PostMapping("/site/querySiteByStoreIds") + public List<Site> querySiteByStoreIds(@RequestBody String ids) { + try { + return siteService.lambdaQuery().in(Site::getStoreId,Arrays.asList(ids.split(","))).list(); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } @ResponseBody @@ -319,9 +382,60 @@ * @param response */ @ResponseBody + @PostMapping("/base/site/weChatPaymentSiteCallback1") + public void weChatPaymentSiteCallback1(HttpServletRequest request, HttpServletResponse response) { + try { + System.err.println("微信回调"); + System.err.println("请求" + request); + BufferedReader reader = request.getReader(); + String string1 = reader.toString(); + System.err.println("请求reader" + string1); + StringBuilder requestBody = new StringBuilder(); + String line; + while ((line = reader.readLine()) != null) { + requestBody.append(line); + } + System.err.println("全部请求体" + requestBody); + JSONObject jsonObject = JSONObject.parseObject(requestBody.toString()); + JSONObject resource = jsonObject.getJSONObject("resource"); + + AesUtil aesUtil = new AesUtil(WxV3PayConfig.apiV3Key.getBytes(StandardCharsets.UTF_8)); + String decryptedData = aesUtil.decryptToString(resource.getString("associated_data").getBytes(StandardCharsets.UTF_8), resource.getString("nonce").getBytes(StandardCharsets.UTF_8), + resource.getString("ciphertext")); + System.err.println("微信解密的字符串信息" + decryptedData); + JSONObject jsonInfo = (JSONObject) JSONObject.parse(decryptedData); + String code = jsonInfo.getString("out_trade_no"); + String transaction_id = jsonInfo.getString("transaction_id"); + String trade_state = jsonInfo.getString("trade_state"); + if (trade_state.equals("SUCCESS")) { + SiteBooking siteBooking = siteBookingService.getOne(new QueryWrapper<SiteBooking>().eq("orderNo", code).eq("state", 1)); + if (siteBooking.getStatus() == 0) { + siteBooking.setPayTime(new Date()); + siteBooking.setStatus(1); + siteBooking.setPayOrderNo(transaction_id); + siteBookingService.updateById(siteBooking); + PrintWriter out = response.getWriter(); + out.write("SUCCESS"); + out.flush(); + out.close(); + } + + } + } catch (Exception e) { + e.printStackTrace(); + } + } + /** + * 购买课程微信支付回调 + * + * @param request + * @param response + */ + @ResponseBody @PostMapping("/base/site/weChatPaymentSiteCallback") public void weChatPaymentSiteCallback(HttpServletRequest request, HttpServletResponse response) { try { + System.err.println("预约场地回调"); Map<String, String> map = payMoneyUtil.weixinpayCallback(request); if (null != map) { String code = map.get("out_trade_no"); @@ -333,18 +447,54 @@ siteBooking.setStatus(1); siteBooking.setPayOrderNo(transaction_id); siteBookingService.updateById(siteBooking); - + Store byId = service.getById(siteBooking.getStoreId()); +// if (byId.getOperatorId()!=null && byId.getOperatorId()!=0){ +// System.err.println("预约场地分账"); +// // 休眠两分钟后再调用分账接口 避免提示订单正在处理中 +// Thread.sleep(120000); +// // 根据运营商id获取对应运营商分账比例 返回格式: 微信分账比例,支付宝分账比例 +// OperatorUser operatorId = operatorUserService.getOne( +// new QueryWrapper<OperatorUser>().eq("operatorId",byId.getOperatorId()) +// ); +// if (operatorId.getWechatProportion() == null){ +// operatorId.setWechatProportion("0"); +// } +// if (operatorId.getAlipayProportion() == null){ +// operatorId.setAlipayProportion("0"); +// } +// String proportion= operatorId.getWechatProportion()+","+operatorId.getAlipayProportion(); +// String[] split = proportion.split(","); +// String s1 = split[0]; +// if (!s1.equals("未设置")){ +// BigDecimal bigDecimal = new BigDecimal(s1); +// // 分账比例 +// BigDecimal bigDecimal1 = bigDecimal.divide(new BigDecimal(100)).setScale(2); +// // 微信商户号 +// String s2 =siteService.getmerchantNumberByOperatorId(byId.getOperatorId()); +// String nonce_str = UUIDUtil.getRandomCode(16); +// BigDecimal bigDecimal2 = new BigDecimal(siteBooking.getPayMoney()); +// ResultUtil fenzhang = payMoneyUtil.fenzhang(transaction_id, bigDecimal2.multiply(bigDecimal1), s2,nonce_str,"预约场地分账"); +// if (!fenzhang.getCode().equals(200)){ +// System.err.println("分账失败 原因是:"+fenzhang.getMsg()); +// }else{ +// siteBooking.setFenzhangNo(fenzhang.getData().toString()); +// siteBooking.setFenzhangOrderNo(nonce_str); +// siteBooking.setFenzhangAmount(bigDecimal2.multiply(bigDecimal1)); +// siteBookingService.updateById(siteBooking); +// } +// } +// } PrintWriter out = response.getWriter(); out.write(result); out.flush(); out.close(); } + } } catch (Exception e) { e.printStackTrace(); } } - /** * 预约场地支付宝回调 * @@ -433,7 +583,7 @@ map.put("space_id", spaceId + ""); map.put("sutu_id", sutuId + ""); - String s = HttpRequestUtil.postRequest("https://try.daowepark.com/v7/user_api/general/gameStart", map); + String s = HttpRequestUtil.postRequest("https://port.daowepark.com/v7/user_api/general/gameStart", map); JSONObject jsonObject = JSONObject.parseObject(s); Object code = jsonObject.get("code"); if (String.valueOf(code) != null && "200".equals(String.valueOf(code))) { @@ -478,12 +628,15 @@ public ResultUtil<Map<String, Object>> queryMySiteById(Integer id) { try { HashMap<String, Object> map = new HashMap<>(); + System.err.println("预约id"+id); SiteBooking siteBooking = siteBookingService.getById(id); + System.err.println("预约"+siteBooking); Integer storeId = siteBooking.getStoreId(); Store byId1 = service.getById(storeId); Site site = siteService.getById(siteBooking.getSiteId()); map.put("siteName", byId1.getName()); SiteType siteType = siteTypeService.getById(site.getSiteTypeId()); + System.err.println("预约类型"+siteType); map.put("siteType", siteType.getName()); map.put("shopName", byId1.getName()); map.put("shopAddress", byId1.getAddress()); @@ -513,7 +666,9 @@ BeanUtils.copyProperties(siteBooking, siteBookingVo); siteBookingVo.setStartTime(siteBooking.getStartTime().getTime()); siteBookingVo.setEndTime(siteBooking.getEndTime().getTime()); - siteBookingVo.setPayTime(siteBooking.getPayTime().getTime()); + if (siteBooking.getPayTime()!=null){ + siteBookingVo.setPayTime(siteBooking.getPayTime().getTime()); + } map.put("data", siteBookingVo); map.put("ids", ids); return ResultUtil.success(map); @@ -524,7 +679,7 @@ } public List<Integer> getIds(Integer siteId) { - HttpRequest httpRequest = HttpRequest.get("https://try.daowepark.com/v7/user_api/general/get_space_area?space_id=" + siteId); + HttpRequest httpRequest = HttpRequest.get("https://port.daowepark.com/v7/user_api/general/get_space_area?space_id=" + siteId); HttpResponse execute = httpRequest.execute(); String body = execute.body(); JSONObject jsonObject = JSONObject.parseObject(body); @@ -686,10 +841,6 @@ @Autowired private StoreService service; - - @Autowired - private IOperatorUserService operatorUserService; - @ResponseBody @PostMapping("/base/site/game") -- Gitblit v1.7.1