From e68a90d29289858e4106a0fb5e615408b41ea102 Mon Sep 17 00:00:00 2001 From: kongdeqiang <kongdeqiang960204@163.com> Date: 星期一, 18 三月 2024 13:45:37 +0800 Subject: [PATCH] 提交更新 --- src/main/java/com/boying/controller/phone/YCPayController.java | 473 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 465 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/boying/controller/phone/YCPayController.java b/src/main/java/com/boying/controller/phone/YCPayController.java index f31113e..368f811 100644 --- a/src/main/java/com/boying/controller/phone/YCPayController.java +++ b/src/main/java/com/boying/controller/phone/YCPayController.java @@ -1,15 +1,27 @@ package com.boying.controller.phone; +import cn.hutool.http.Header; +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.boying.common.R; +import com.boying.common.ReturnData; import com.boying.common.SystemConfigProperties; import com.boying.entity.*; import com.boying.service.*; import com.boying.util.DateUtilOther; +import com.boying.util.HTTPEntityUtil; +import com.google.gson.Gson; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; @@ -18,7 +30,10 @@ import java.nio.file.Paths; import java.nio.file.Files; import java.text.SimpleDateFormat; +import java.time.Duration; +import java.time.LocalDateTime; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -34,13 +49,17 @@ @RequiredArgsConstructor public class YCPayController { private final OutParkService outParkService; + private final PayLogService payLogService; private final ParkService parkService; private final OrderRecordService orderRecordService; private final TicketService ticketService; private final TicketBlackService ticketBlackService; + private final SystemConfigProperties systemConfigProperties; private final WhiteListService whiteListService; private final EnterParkService enterParkService; + private final WXService wxService; + private final OutParkLogService outParkLogService; /** * 鏌ヨ璁㈠崟鎺ュ彛 @@ -107,12 +126,276 @@ if(StringUtils.isBlank(outPark.getPayCode())){ String logs = sdf.format(new Date())+" 杞︾墝鍙蜂负锛�"+outPark.getCarNo()+",鐢宠缂磋垂------銆媆n"; writeTxt(logs); + List<EnterPark> byCarNo = enterParkService.findByCarNo(outPark.getCarNo(),outPark.getParkId()); + if(byCarNo.size()>0){ + EnterPark enterPark = byCarNo.get(0); + if(enterPark != null && enterPark.getIsPay() == 1){ + if(outPark.getPrice()==enterPark.getPrice()){ + return R.failed("宸茬即璐�"); + }else { + outPark.setPrice(outPark.getPrice()-enterPark.getPrice()); + outParkService.updateById(outPark); + } + } + } addOrderRecord(outPark); return R.ok("璺宠浆閭偍鏀粯","https://openpayment.psbc.com/h5/static/router.html?rurl=router&router=psbc&appid=CUP14094502391¶ms={\"payMode\":\"B\",\"payItemNo\":\"41304508000500\",\"userNo\":"+id+"}"); }else { return R.failed("鍑洪敊"); } } + + + /** + * 鍒ゆ柇鏄惁缂磋垂 + */ + @PostMapping("parkXT") + public Object parkXT(Long id){ + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss"); + OutPark outPark = outParkService.getById(id); + System.out.println("id:"+id); + if(id == null){ + return R.failed("鏈壘鍒版暟鎹紝璇风◢鍚庨噸鏂扮偣鍑�"); + } + if(outPark.getPrice()==0){ + updateOutPark(outPark.getId(),"03"); + return R.failed("鏈鍋滆溅鏃犻渶鏀粯璐圭敤"); + } + + //鍒ゆ柇鏄惁鍦ㄧ櫧鍚嶅崟 + QueryWrapper<WhiteList> wrapper = new QueryWrapper<>(); + wrapper.lambda() + .eq(WhiteList::getCarNo,outPark.getCarNo()); + List<WhiteList> all = whiteListService.list(wrapper); + for(WhiteList w : all){ + if(w.getType()==0){ + updateOutPark(outPark.getId(),"03"); + return R.failed("鏈鍋滆溅鏃犻渶鏀粯璐圭敤!"); + }else{ + if(StringUtils.isNotBlank(w.getParkIds())){ + if(w.getParkIds().contains(outPark.getParkId()+"")){ + if(w.getEndTime()!=null){ + if(System.currentTimeMillis()<w.getEndTime().getTime()){ + updateOutPark(outPark.getId(),"03"); + return R.failed("鏈鍋滆溅鏃犻渶鏀粯璐圭敤!"); + } + } + } + + } + } + } + if(StringUtils.isNotBlank(outPark.getPayCode()) && outPark.getStatus() == 0){ + String logs = sdf.format(new Date())+" 杞︾墝鍙蜂负锛�"+outPark.getCarNo()+",鐢宠缂磋垂2------銆媆n"; + writeTxt(logs); + OutParkLog byOutPark = outParkLogService.getByOutPark(outPark.getCarNo(), outPark.getId()); + byOutPark.setPayStartTime(LocalDateTime.now()); + outParkLogService.saveOrUpdate(byOutPark); + return R.ok(null,"璺宠浆閭㈠彴閾惰鏀粯"); + }else if(StringUtils.isNotBlank(outPark.getPayCode()) && outPark.getStatus() == 1){ + return R.failed("宸茬即璐�"); + } + + if(StringUtils.isBlank(outPark.getPayCode())){ + String logs = sdf.format(new Date())+" 杞︾墝鍙蜂负锛�"+outPark.getCarNo()+",鐢宠缂磋垂------銆媆n"; + writeTxt(logs); + List<EnterPark> byCarNo = enterParkService.findByCarNo(outPark.getCarNo(),outPark.getParkId()); + if(byCarNo.size()>0){ + EnterPark enterPark = byCarNo.get(0); + if(enterPark != null && enterPark.getIsPay() == 1){ + if(outPark.getPrice()==enterPark.getPrice()){ + return R.failed("宸茬即璐�"); + }else { + outPark.setPrice(outPark.getPrice()-enterPark.getPrice()); + outParkService.updateById(outPark); + OutParkLog byOutPark = outParkLogService.getByOutPark(outPark.getCarNo(), outPark.getId()); + byOutPark.setPayStartTime(LocalDateTime.now()); + outParkLogService.saveOrUpdate(byOutPark); + } + } + } + addOrderRecord(outPark); + return R.ok(null,"璺宠浆閭㈠彴閾惰鏀粯"); + }else { + return R.failed("鍑洪敊"); + } + } + + /** + * 闃块噷缂磋垂 + */ + @PostMapping("payByAli") + public Object payByAli(Long id){ + OutPark outPark = outParkService.getById(id); + String xtyhpay = systemConfigProperties.getXTYHPAY(); + LocalDateTime date3 = LocalDateTime.now(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); + String format = sdf.format(new Date()); + Map<String,Object> map = new HashMap<>(); + map.put("encoding","UTF-8"); + map.put("signMethod","01"); + map.put("sdkAppId",systemConfigProperties.getXTYHMERID()); + map.put("txnType","1007"); + map.put("txnSubType","100702"); + map.put("txnAccType","03"); + map.put("aesWay","01"); + map.put("merId",systemConfigProperties.getXTYHMERID()); + map.put("merName",systemConfigProperties.getXTYHMERNAME()); + map.put("backEndUrl",systemConfigProperties.getXTYHRESULT()); + map.put("txnOrderId",outPark.getId()+""+format); + map.put("txnOrderTime",format); + map.put("txnOrderBody",outPark.getCarNo()+"娉婅溅缂磋垂"); + map.put("txnAmt",Math.round(outPark.getPrice() * 100)+""); + map.put("txnCcyType","156"); + if(outPark.getPayTime() != null){ + LocalDateTime date4 = outPark.getPayTime(); + Duration duration = Duration.between(date3, date4); + long l = duration.toMinutes(); + if(l<3){ + map.put("preTxnSsn",outPark.getCode2()); + } + } + + Map<String, String> stringStringMap = wxService.addSign(map); + map.put("certId",stringStringMap.get("certId")); + map.put("signAture",stringStringMap.get("signAture")); + Gson gson =new Gson(); + String str = gson.toJson(map); + System.out.println("璇锋眰鎶ユ枃锛�"+str); + writeTxt2(outPark.getId()+"ALipay璇锋眰: "+str); + + String body = HttpRequest.post(xtyhpay) + .header(Header.CONTENT_TYPE, "application/json") + .body(str) + .timeout(15000) + .execute() + .body(); + System.out.println(outPark.getId()+"鍝嶅簲鎶ユ枃锛�"+body); + + writeTxt2(outPark.getId()+"ALipay鍝嶅簲: "+body); + JSONObject map1 = JSON.parseObject(body); + String respCode = (String)map1.get("respCode"); + if(respCode.equals("0000")){ + String respTxnSsn = (String)map1.get("respTxnSsn"); + String respData = (String)map1.get("respData"); + String respTxnTime = (String)map1.get("respTxnTime"); + Map map2 = gson.fromJson(respData, Map.class); + String qrCode = (String)map2.get("qrCode"); + PayLog payLog = new PayLog(); + payLog.setOutParkId(outPark.getId()); + payLog.setCode2(respTxnSsn); + payLog.setQrCode(qrCode); + payLog.setPayTime(LocalDateTime.now()); + payLog.setTxnOrderId(outPark.getId()+""+format); + payLog.setTxnOrderTime(format); + payLog.setRespTxnTime(respTxnTime); + payLogService.save(payLog); + return R.ok(null,qrCode); + } + String respMsg = (String)map1.get("respMsg"); + return R.failed(respCode+":"+respMsg); + } + + /** + * 鑾峰彇寰俊openid + */ + @PostMapping("getOpenId") + public Object park(Long id,String code){ + OutPark outPark = outParkService.getById(id); + String openIdByCode = wxService.getOpenIdByCode(code); + writeTxt2(outPark.getId()+"鑾峰彇openid涓猴細"+openIdByCode); + return payByWX(id,openIdByCode); + } + + /** + * 寰俊缂磋垂 + */ + @PostMapping("payByWX") + public Object payByWX(Long id,String openId){ + System.out.println("寮�濮嬫敮浠�"); + OutPark outPark = outParkService.getById(id); + String xtyhpay = systemConfigProperties.getXTYHPAY(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); + String format = sdf.format(new Date()); + LocalDateTime date3 = LocalDateTime.now(); + Map<String,Object> map = new HashMap<>(); + map.put("encoding","UTF-8"); + map.put("signMethod","01"); + map.put("sdkAppId",systemConfigProperties.getXTYHMERID()); + map.put("txnType","1006"); + map.put("txnSubType","100603"); + map.put("txnAccType","02"); + map.put("secMerAppId",systemConfigProperties.getXTYHAPPID()); + map.put("txnSubOpenid",openId); + map.put("txnProductId",outPark.getId()+""); + map.put("aesWay","01"); + map.put("merId",systemConfigProperties.getXTYHMERID()); + map.put("merName",systemConfigProperties.getXTYHMERNAME()); + map.put("backEndUrl",systemConfigProperties.getXTYHRESULT()); + map.put("txnOrderId",outPark.getId()+""+format); + map.put("txnOrderTime",format); + map.put("txnOrderBody",outPark.getCarNo()+"娉婅溅缂磋垂"); + map.put("txnAmt",Math.round(outPark.getPrice() * 100)+""); + map.put("txnCcyType","156"); + if(outPark.getPayTime() != null){ + LocalDateTime date4 = outPark.getPayTime(); + Duration duration = Duration.between(date3, date4); + long l = duration.toMinutes(); + if(l<3){ + map.put("preTxnSsn",outPark.getCode2()); + } + } + Map<String, String> stringStringMap = wxService.addSign(map); + map.put("certId",stringStringMap.get("certId")); + map.put("signAture",stringStringMap.get("signAture")); + Gson gson =new Gson(); + String str = gson.toJson(map); + System.out.println("璇锋眰鎶ユ枃锛�"+str); + writeTxt2(outPark.getId()+"WXpay璇锋眰: "+str); + + String body = HttpRequest.post(xtyhpay) + .header(Header.CONTENT_TYPE, "application/json") + .body(str) + .timeout(15000) + .execute() + .body(); + System.out.println(outPark.getId()+"鍝嶅簲鎶ユ枃锛�"+body); + + writeTxt2(outPark.getId()+"WXpay鍝嶅簲: "+body); + JSONObject map1 = JSON.parseObject(body); + String respCode = (String)map1.get("respCode"); + if(respCode.equals("0000")){ + String respTxnSsn = (String)map1.get("respTxnSsn"); + String respTxnTime = (String)map1.get("respTxnTime"); + String respData = (String)map1.get("respData"); + Map map2 = gson.fromJson(respData, Map.class); + String appId = (String)map2.get("appId"); + String timeStamp = (String)map2.get("timeStamp"); + String nonceStr = (String)map2.get("nonceStr"); + String signType = (String)map2.get("signType"); + String package1 = (String)map2.get("package"); + String paySign = (String)map2.get("paySign"); + Map<String,String> resultMap = new HashMap<>(); + resultMap.put("appId",appId); + resultMap.put("timeStamp",timeStamp); + resultMap.put("nonceStr",nonceStr); + resultMap.put("signType",signType); + resultMap.put("package",package1); + resultMap.put("paySign",paySign); + PayLog payLog = new PayLog(); + payLog.setOutParkId(outPark.getId()); + payLog.setCode2(respTxnSsn); + payLog.setPayTime(LocalDateTime.now()); + payLog.setTxnOrderId(outPark.getId()+""+format); + payLog.setTxnOrderTime(format); + payLog.setRespTxnTime(respTxnTime); + payLogService.save(payLog); + return R.ok(resultMap,null); + } + String respMsg = (String)map1.get("respMsg"); + return R.failed(respCode+":"+respMsg); + } + /** * 鏀粯鍥炶皟鎺ュ彛 @@ -131,6 +414,12 @@ updateOrderRecord(queryId,"03"); String logs = sdf.format(new Date())+" 杞︾墝鍙蜂负锛�"+byId.getCarNo()+",缂磋垂鎴愬姛------銆媆n"; writeTxt(logs); + List<EnterPark> byCarNo = enterParkService.findByCarNo(byId.getCarNo(),byId.getParkId()); + if(byCarNo.size()>0){ + EnterPark enterPark = byCarNo.get(0); + enterPark.setIsPay(1); + enterParkService.updateById(enterPark); + } return R.ok(null,"鍥炶皟鎴愬姛"); }else { String logs = sdf.format(new Date())+" 鍑哄満id涓猴細"+queryId+",缂磋垂澶辫触------銆媆n"; @@ -140,6 +429,61 @@ } return R.ok(byId,"鍥炶皟鎴愬姛"); } + + + /** + * 閭㈠彴閾惰鏀粯鍥炶皟鎺ュ彛 + * @param + * @return + */ + @PostMapping("/getResult") + public Object getResult(HttpServletRequest request){ + System.out.println("getResult鏀跺埌璁块棶"); + String respCode = request.getParameter("respCode"); + String respTxnSsn = request.getParameter("respTxnSsn"); +// String respCode = map.get("respCode"); +// String respTxnSsn = map.get("respTxnSsn"); + System.out.println(respCode+":"+respTxnSsn); + if(respCode != null){ + if(respCode.equals("0000")){ + //浜ゆ槗鎴愬姛,鏍规嵁娴佹按鍙锋煡璇㈠嚭鍦鸿褰� + PayLog payLog = payLogService.findByPayCode(respTxnSsn); + if(payLog == null){ + return R.failed("鏈煡璇㈠埌娴佹按璁板綍"); + }else { + OutPark byPayCode = outParkService.getById(payLog.getOutParkId()); + writeTxt2(byPayCode.getId()+"鏀跺埌鍥炴墽\n"); + if(byPayCode == null){ + return R.failed("鏈煡璇㈠埌璁㈠崟"); + }else { + if(byPayCode.getStatus() == 1){ + return R.ok(null,"璁㈠崟宸叉敮浠�"); + }else { + OutParkLog byOutPark = outParkLogService.getByOutPark(byPayCode.getCarNo(), byPayCode.getId()); + byOutPark.setPayEndTime(LocalDateTime.now()); + outParkLogService.saveOrUpdate(byOutPark); + updateOrderRecord((long)byPayCode.getId(),"03"); + List<EnterPark> byCarNo = enterParkService.findByCarNo(byPayCode.getCarNo(),byPayCode.getParkId()); + if(byCarNo.size()>0){ + EnterPark enterPark = byCarNo.get(0); + enterPark.setIsPay(1); + enterParkService.updateById(enterPark); + } + return R.ok(null,"鍥炶皟鎴愬姛"); + } + } + } + }else if(respCode.equals("0002") || respCode.equals("0003") || respCode.equals("0003") || respCode.equals("0012")){ + //浜ゆ槗鎴愬姛锛岃秴鏃讹紝鏈槑锛岀◢鍚庡彂璧锋煡璇� + }else if(respCode.equals("0011")){ + //浜ゆ槗 + } + }else { + return R.failed("鏈帴鏀跺埌鍏ュ弬"); + } + return R.failed(null,"璇锋眰澶辫触"); + } + /** * 瀵硅处鎺ュ彛 @@ -161,6 +505,102 @@ return R.failed(null,"鏂囦欢涓嶅瓨鍦�"); } } + + /** + * 閭㈠彴閾惰瀵硅处鎺ュ彛 + * @param + * @return + */ + @PostMapping ("/checkbillXTYH") + public Object checkbillXTYH(String date){ + String xtyhpay = systemConfigProperties.getXTYHPAY(); + Map<String,Object> map = new HashMap<>(); + map.put("encoding","UTF-8"); + map.put("signMethod","01"); + map.put("txnType","4001"); + map.put("txnSubType","400102"); + map.put("billType","00"); + map.put("billDate",date); + map.put("merId","8202309110000001"); + + Map<String, String> stringStringMap = wxService.addSign(map); + map.put("certId",stringStringMap.get("certId")); + map.put("signAture",stringStringMap.get("signAture")); + Gson gson =new Gson(); + String str = gson.toJson(map); + System.out.println("璇锋眰鎶ユ枃锛�"+str); + writeTxt2(date+"瀵硅处璇锋眰: "+str); + + String body = HttpRequest.post(xtyhpay) + .header(Header.CONTENT_TYPE, "application/json") + .body(str) + .timeout(15000) + .execute() + .body(); + + writeTxt2(date+"瀵硅处鍝嶅簲: "+body); + JSONObject map1 = JSON.parseObject(body); + String respCode = (String)map1.get("respCode"); + if(respCode.equals("0000")){ + String billDownloadUrl = (String)map1.get("billDownloadUrl"); + String respData = (String)map1.get("respData"); + return R.ok(null,billDownloadUrl); + } + String respMsg = (String)map1.get("respMsg"); + return R.failed(respCode+":"+respMsg); + } + + /** + * 浜ゆ槗鐘舵�佹煡璇� + * @param + * @return + */ + @PostMapping ("/searchPayStatus") + public Object searchPayStatus(String txnOrderId,String txnOrderTime){ + OutPark outPark = outParkService.findByOrderId(txnOrderId); + if(outPark == null){ + return R.failed("鏈壘鍒拌璁㈠崟"); + } + String xtyhpay = systemConfigProperties.getXTYHPAY(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); + Map<String,Object> map = new HashMap<>(); + map.put("encoding","UTF-8"); + map.put("signMethod","01"); + map.put("sdkAppId","8202309110000001"); + map.put("txnType","1009"); + map.put("txnSubType","100900"); + map.put("merId","8202309110000001"); + map.put("origTxnOrderId",txnOrderId); + map.put("origTxnOrderTime",txnOrderTime); + + Map<String, String> stringStringMap = wxService.addSign(map); + map.put("certId",stringStringMap.get("certId")); + map.put("signAture",stringStringMap.get("signAture")); + Gson gson =new Gson(); + String str = gson.toJson(map); + System.out.println("璇锋眰鎶ユ枃锛�"+str); + writeTxt2(txnOrderId+"鐘舵�佹煡璇㈣姹�: "+str); + + String body = HttpRequest.post(xtyhpay) + .header(Header.CONTENT_TYPE, "application/json") + .body(str) + .timeout(15000) + .execute() + .body(); + System.out.println(txnOrderId+"鐘舵�佹煡璇㈠搷搴旀姤鏂囷細"+body); + + writeTxt2(txnOrderId+"鐘舵�佹煡璇㈠搷搴�: "+body); + JSONObject map1 = JSON.parseObject(body); + String respCode = (String)map1.get("respCode"); + if(respCode.equals("0000")){ + result((long)outPark.getId(),0,0); + return R.ok(null,"鏌ヨ鎴愬姛"); + } + String respMsg = (String)map1.get("respMsg"); + return R.failed(respCode+":"+respMsg); + } + + @@ -236,7 +676,7 @@ //鏇存柊鍑哄満 public void updateOutPark(Integer outParkId, String status){ OutPark outPark = outParkService.getById(outParkId); - if(outPark!=null){ + if(outPark!=null && outPark.getEnterTime() !=null){ if(status.equals("03")){ outPark.setStatus(1); outParkService.saveOrUpdate(outPark); @@ -259,9 +699,16 @@ String logs = sdf.format(new Date())+" 杞︾墝鍙蜂负锛�"+outPark.getCarNo()+",鍒涘缓璁㈠崟------銆媆n"; writeTxt(logs); outPark.setPayCode(outPark.getId()+""); + List<EnterPark> byCarNo = enterParkService.findByCarNo(outPark.getCarNo(),outPark.getParkId()); outParkService.updateById(outPark); Park park = parkService.getById(outPark.getParkId()); OrderRecord orderRecord = new OrderRecord(); + if(byCarNo.size() >0){ + EnterPark enterPark = byCarNo.get(0); + if(enterPark != null && enterPark.getImgId() != null){ + orderRecord.setImgInId(enterPark.getImgId()); + } + } orderRecord.setAddress(park.getName()); orderRecord.setCarNo(outPark.getCarNo()); orderRecord.setCode(outPark.getCode()); @@ -273,13 +720,6 @@ orderRecord.setPayCode(outPark.getPayCode()); if(outPark.getImgId() != null){ orderRecord.setImgOutId(outPark.getImgId()); - } - List<EnterPark> byCarNo = enterParkService.findByCarNo(outPark.getCarNo(),outPark.getParkId()); - if(byCarNo.size() >0){ - EnterPark enterPark = byCarNo.get(0); - if(enterPark != null && enterPark.getImgId() != null){ - orderRecord.setImgInId(enterPark.getImgId()); - } } orderRecordService.saveOrUpdate(orderRecord); } @@ -316,6 +756,23 @@ } } + private void writeTxt2( String txt) + { + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); + try + { + FileWriter f = new FileWriter(systemConfigProperties.getLogPath()+"閭㈠彴閾惰鏀粯鏃ュ織"+sdf.format(new Date())+".txt",true); + BufferedWriter bw=new BufferedWriter(f); + bw.write(txt); + bw.newLine(); + bw.close(); + } + catch(Exception e) + { + System.out.println("鎵撳嵃閿欒"); + } + } + public static void main(String[] args) { Path path = Paths.get("E:\\ycCheckBill\\Bank_PSBC_20350421.txt"); try { -- Gitblit v1.9.1