From ea127a1c094fb67521c73f46f5c022959a4de8ce Mon Sep 17 00:00:00 2001 From: kongdeqiang <123456> Date: 星期三, 20 九月 2023 17:18:24 +0800 Subject: [PATCH] 修改 --- src/main/java/com/boying/entity/OutPark.java | 27 +++ src/main/java/com/boying/common/SystemConfigProperties.java | 3 src/main/java/com/boying/controller/phone/YCPayController.java | 407 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 437 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/boying/common/SystemConfigProperties.java b/src/main/java/com/boying/common/SystemConfigProperties.java index ffe6f0f..0aff976 100644 --- a/src/main/java/com/boying/common/SystemConfigProperties.java +++ b/src/main/java/com/boying/common/SystemConfigProperties.java @@ -75,4 +75,7 @@ @Value("${ffzf.getNumber}") private String getNumber; + @Value("${ffzf.XTYHPAY}") + private String XTYHPAY; + } diff --git a/src/main/java/com/boying/controller/phone/YCPayController.java b/src/main/java/com/boying/controller/phone/YCPayController.java index fb7ea9c..c48444d 100644 --- a/src/main/java/com/boying/controller/phone/YCPayController.java +++ b/src/main/java/com/boying/controller/phone/YCPayController.java @@ -1,15 +1,26 @@ 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.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 +29,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; @@ -41,6 +55,7 @@ private final SystemConfigProperties systemConfigProperties; private final WhiteListService whiteListService; private final EnterParkService enterParkService; + private final WXService wxService; /** * 鏌ヨ璁㈠崟鎺ュ彛 @@ -126,6 +141,243 @@ } } + + /** + * 鍒ゆ柇鏄惁缂磋垂 + */ + @PostMapping("parkXT") + public Object parkXT(Long id){ + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss"); + OutPark outPark = outParkService.getById(id); + 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); + 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); + } + } + } + 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","8202309110000001"); + map.put("txnType","1007"); + map.put("txnSubType","100702"); + map.put("txnAccType","03"); + map.put("aesWay","01"); + map.put("merId","8202309110000001"); + map.put("merName","閭兏甯傚嘲宄扮熆鍖烘粡婧愬缓璁惧彂灞曟湁闄愬叕鍙�"); + map.put("backEndUrl","http://39.96.92.240:8089/ffzf/api/getResult"); + 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"); + outPark.setCode2(respTxnSsn); + outPark.setQrCode(qrCode); + outPark.setPayTime(LocalDateTime.now()); + outPark.setTxnOrderId(outPark.getId()+""+format); + outPark.setTxnOrderTime(format); + outPark.setRespTxnTime(respTxnTime); + outParkService.updateById(outPark); + 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){ + 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","8202309110000001"); + map.put("txnType","1006"); + map.put("txnSubType","100603"); + map.put("txnAccType","02"); + map.put("secMerAppId","wx46e756aed958f895"); + map.put("txnSubOpenid",openId); + map.put("txnProductId",outPark.getId()+""); + map.put("aesWay","01"); + map.put("merId","8202309110000001"); + map.put("merName","閭兏甯傚嘲宄扮熆鍖烘粡婧愬缓璁惧彂灞曟湁闄愬叕鍙�"); + map.put("backEndUrl","http://39.96.92.240:8089/ffzf/api/getResult"); + 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); + outPark.setCode2(respTxnSsn); + outPark.setPayTime(LocalDateTime.now()); + outPark.setTxnOrderId(outPark.getId()+""+format); + outPark.setTxnOrderTime(format); + outPark.setRespTxnTime(respTxnTime); + outParkService.updateById(outPark); + return R.ok(resultMap,null); + } + String respMsg = (String)map1.get("respMsg"); + return R.failed(respCode+":"+respMsg); + } + + /** * 鏀粯鍥炶皟鎺ュ彛 * @param queryId @@ -159,6 +411,48 @@ 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")){ + //浜ゆ槗鎴愬姛,鏍规嵁娴佹按鍙锋煡璇㈠嚭鍦鸿褰� + OutPark byPayCode = outParkService.findByPayCode(respTxnSsn); + if(byPayCode == null){ + return R.failed("鏈煡璇㈠埌璁㈠崟"); + }else { + 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,"璇锋眰澶辫触"); + } + + /** * 瀵硅处鎺ュ彛 * @param @@ -179,6 +473,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); + } + + @@ -334,6 +724,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 { diff --git a/src/main/java/com/boying/entity/OutPark.java b/src/main/java/com/boying/entity/OutPark.java index ffd9fde..1617838 100644 --- a/src/main/java/com/boying/entity/OutPark.java +++ b/src/main/java/com/boying/entity/OutPark.java @@ -69,6 +69,13 @@ private LocalDateTime enterTime; /** + * 鏀粯鏃堕棿 + */ + @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private LocalDateTime payTime; + + /** * 璁㈠崟鍙� */ private String code; @@ -78,11 +85,31 @@ */ private String code2; + + /** + * 鍟嗘埛娴佹按鍙� + */ + private String txnOrderId; + + /** + * 鍟嗘埛浜ゆ槗鏃堕棿 + */ + private String txnOrderTime; + + /** + * 骞冲彴浜ゆ槗鏃堕棿 + */ + private String respTxnTime; + + /** * 缂存鐮� */ private String payCode; + private String qrCode; + + /** * 0:鏈即璐� 1锛氱即璐� */ -- Gitblit v1.9.1