| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | |
| | | @Resource |
| | | private CourseRecordClient courseRecordClient; |
| | | |
| | | @Resource |
| | | private StoreService storeService; |
| | | |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | |
| | | @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获取对应运营商分账比例 返回格式: 微信分账比例,支付宝分账比例 |
| | |
| | | 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 |
| | |
| | | * @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 { |
| | |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | // 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(); |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 预约场地支付宝回调 |
| | | * |