| @@ -40,6 +40,8 @@ public class WxCarController extends BaseController { | |||
| TJDUtil tjd = new TJDUtil(); | |||
| CYFUtil cyf = new CYFUtil(); | |||
| @Autowired | |||
| WxParkService wxParkService; | |||
| @@ -257,6 +259,8 @@ public class WxCarController extends BaseController { | |||
| // 2. get vendor params | |||
| if (park.getVendorType() == EnumCarVendor.CAR_ETCP.getCode()) { | |||
| return etcpBindCar(paramMap, park, getUserId()); | |||
| } else if (park.getVendorType() == EnumCarVendor.CAE_CYF.getCode()){ | |||
| return cyfBindCar(paramMap,park,getUser()); | |||
| } else { | |||
| // 内部操作 | |||
| return bindCar(paramMap, park, getUserId()); | |||
| @@ -300,6 +304,7 @@ public class WxCarController extends BaseController { | |||
| } | |||
| } | |||
| private ResultData bindCar(Map<String, String> paramMap, WxPark park, Long cuUserId) { | |||
| String carNumber = paramMap.get("carNumber"); | |||
| if (StringUtils.isBlank(carNumber)) { | |||
| @@ -372,6 +377,33 @@ public class WxCarController extends BaseController { | |||
| } | |||
| } | |||
| /** | |||
| * @description 车易付会员车辆信息注册 | |||
| * @Params [paramMap, park, wxCUser] | |||
| * @return com.iformall.common.ResultData | |||
| * @Author furunxin | |||
| * @Date 2020/7/8 下午10:23 | |||
| **/ | |||
| private ResultData cyfBindCar(@RequestBody Map<String, String> paramMap, WxPark park,WxCUser wxCUser) { | |||
| String carNumber = paramMap.get("carNumber"); | |||
| if (StringUtils.isBlank(carNumber)) { | |||
| logger.error("carNumber为空"); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "carNumber为空"); | |||
| } | |||
| String params = park.getVendorParams(); | |||
| JSONObject objParams = JSON.parseObject(params); | |||
| String token = objParams.getString("token"); | |||
| int feeGroupId = objParams.getIntValue("feeGroupId"); | |||
| String ret = cyf.registerCar(token,park.getNumber(),feeGroupId,park.getParkingId(),carNumber,wxCUser.getId(),wxCUser.getNickName()); | |||
| JSONObject retObj = JSON.parseObject(ret); | |||
| if (retObj.getIntValue("result") == 1){ | |||
| addCarInfoToDB(carNumber, EnumCarVendor.getEnum(park.getVendorType()), park, wxCUser.getId()); | |||
| }else { | |||
| return new ResultData(ErrorCode.CAR_BIND_FAIL.getCode(), "绑车牌失败", retObj); | |||
| } | |||
| return null; | |||
| } | |||
| private ResultData tjdInsertToDB(String carNumber, Long newCarId, JSONObject retObj, WxPark park, Long cuUserId) { | |||
| String carId = retObj.getString("carId"); | |||
| // 插入车牌 | |||
| @@ -1010,4 +1042,7 @@ public class WxCarController extends BaseController { | |||
| } | |||
| } | |||
| @@ -0,0 +1,154 @@ | |||
| package com.iformall.controller.callback; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.controller.base.BaseController; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.enums.EnumCarCmd; | |||
| import com.iformall.enums.EnumCarVendor; | |||
| import com.iformall.enums.EnumCouponSendSendType; | |||
| import com.iformall.service.*; | |||
| import com.iformall.utils.car.CYFUtil; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import org.apache.commons.collections.CollectionUtils; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.PostMapping; | |||
| import org.springframework.web.bind.annotation.RequestBody; | |||
| import org.springframework.web.bind.annotation.RequestMapping; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| import java.util.Date; | |||
| import java.util.HashMap; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| /** | |||
| * @author: furunxin | |||
| * @Date: 2020/7/6 15:29 | |||
| * @Description: 车易付回调接口 | |||
| */ | |||
| @Slf4j | |||
| @RestController | |||
| @RequestMapping("/carCallback") | |||
| public class WxCarCYFCallBackController extends BaseController { | |||
| @Autowired | |||
| WxParkService wxParkService; | |||
| @Autowired | |||
| WxCarCmdLogService wxCarCmdLogService; | |||
| @Autowired | |||
| WxCUserService wxCUserService; | |||
| @Autowired | |||
| WxCUserCarService wxCUserCarService; | |||
| @Autowired | |||
| WxCouponSendService wxCouponSendService; | |||
| @Autowired | |||
| WxCarPayRecordService wxCarPayRecordService; | |||
| /** | |||
| * @description 车易付 车辆入场通知 | |||
| * @Params [paramMap] | |||
| * @return com.iformall.common.Result | |||
| * @Author furunxin | |||
| * @Date 2020/7/8 上午8:27 | |||
| **/ | |||
| @PostMapping(value = "/cyfParkInCallback") | |||
| public Map cyfParkInCallback(@RequestBody Map<String, Object> paramMap) { | |||
| log.info("["+getIpAddr()+"] cyfParkInCallback: " + paramMap.toString()); | |||
| //解析车易付参数 | |||
| String carNumber = paramMap.get(CYFUtil.CYF_CAR_NUMBER).toString(); | |||
| String cyfParkId = paramMap.get(CYFUtil.CYF_PARK_ID).toString(); | |||
| String parkName = paramMap.get(CYFUtil.CYF_PARK_NAME).toString(); | |||
| String synId = paramMap.get(CYFUtil.CYF_SYN_ID).toString(); | |||
| String entranceTime = paramMap.get(CYFUtil.CYF_ENTRANCE_TIME).toString(); | |||
| Map map = new HashMap(); | |||
| Date currentDate = new Date(); | |||
| WxCarCmdLog wxCarCmdLog = new WxCarCmdLog(); | |||
| wxCarCmdLog.setVendorType(EnumCarVendor.CAE_CYF.getCode()); | |||
| wxCarCmdLog.setCmdType(EnumCarCmd.CAR_CYF_CALLBACK_PARK_IN.getCode()); | |||
| wxCarCmdLog.setCmdJson(JSON.toJSONString(paramMap)); | |||
| wxCarCmdLog.setCreateDate(currentDate); | |||
| wxCarCmdLog.setUpdateDate(currentDate); | |||
| WxPark parkQ = new WxPark(); | |||
| parkQ.setVendorType(EnumCarVendor.CAE_CYF.getCode()); | |||
| parkQ.setParkingId(cyfParkId); | |||
| WxPark park = wxParkService.getByObj(parkQ); | |||
| if (park == null) { | |||
| log.error("cyfParkInCallback: 车易付车场未找到" + cyfParkId); | |||
| map.put(CYFUtil.CYF_IS_RESULT, CYFUtil.CYF_ERR); | |||
| map.put(CYFUtil.CYF_ERR_MSG, "车场未找到" + cyfParkId); | |||
| return map; | |||
| } else { | |||
| wxCarCmdLog.updateTenantInfo(park); | |||
| } | |||
| try { | |||
| wxCarCmdLogService.saveOrUpdate(wxCarCmdLog); | |||
| } catch (Exception e) { | |||
| log.error("cyfParkInCallback: 入库错误" + paramMap.toString()); | |||
| map.put(CYFUtil.CYF_IS_RESULT, CYFUtil.CYF_ERR); | |||
| map.put(CYFUtil.CYF_ERR_MSG, "入库错误" + cyfParkId); | |||
| return map; | |||
| } | |||
| // 停车发券 | |||
| String phoneStrs = ""; | |||
| if (StringUtils.isNotBlank(carNumber)) { | |||
| // 根据车牌查找用户 | |||
| WxCUserCar userCarQ = new WxCUserCar(); | |||
| userCarQ.updateTenantInfo(park); | |||
| userCarQ.setCarNumber(carNumber); | |||
| userCarQ.setVendorType(EnumCarVendor.CAE_CYF.getCode()); | |||
| // TODO 可能多用户关联同一张车牌 | |||
| List<WxCUserCar> userCarList = wxCUserCarService.getList(userCarQ); | |||
| boolean bFirst = true; | |||
| for (WxCUserCar userCar : userCarList) { | |||
| userCar.setParentTenantId(park.getParentTenantId()); | |||
| wxCouponSendService.sendCouponToUser(EnumCouponSendSendType.CAR_STOP, userCar); | |||
| WxCUser cUser = wxCUserService.getById(userCar.getCUserId()); | |||
| if(cUser != null){ | |||
| if(bFirst) { | |||
| phoneStrs = cUser.getPhone(); | |||
| bFirst = false; | |||
| } else { | |||
| phoneStrs += "," + cUser.getPhone(); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| try { | |||
| // 保存WxCarPayRecord | |||
| WxCarPayRecord record = new WxCarPayRecord(); | |||
| record.updateTenantInfo(park); | |||
| record.setVendorType(wxCarCmdLog.getVendorType()); | |||
| record.setSynId(synId); | |||
| record.setParkId(cyfParkId); | |||
| record.setParkName(parkName); | |||
| record.setPlateNumber(carNumber); | |||
| if(StringUtils.isNotBlank(entranceTime)) { | |||
| record.setEntranceTime(CYFUtil.utcToLocal(entranceTime)); | |||
| } | |||
| record.setPhone(phoneStrs); | |||
| WxCarPayRecord query = new WxCarPayRecord(); | |||
| query.updateTenantInfo(park); | |||
| query.setParkId(cyfParkId); | |||
| query.setSynId(synId); | |||
| PageInfo<WxCarPayRecord> page = wxCarPayRecordService.findCarPayListByPage(query,1,1); | |||
| if(page != null && CollectionUtils.isNotEmpty(page.getList())){ | |||
| record.setId(page.getList().get(0).getId()); | |||
| } | |||
| wxCarPayRecordService.saveOrUpdate(record); | |||
| } catch (Exception e) { | |||
| log.error("WxCarPayRecord: 入库错误 "+e.getMessage()+"," + paramMap.toString()); | |||
| } | |||
| map.put(CYFUtil.CYF_IS_RESULT, CYFUtil.CYF_SUC); | |||
| return map; | |||
| } | |||
| } | |||
| @@ -16,6 +16,7 @@ public enum EnumCarCmd { | |||
| CAR_TJD_CALLBACK_PARK_OUT(612, "停简单离场通知"), | |||
| CAR_TJD_CALLBACK_PAID(613, "停简单支付通知"), | |||
| CAR_TJD_CALLBACK_REFUND(614, "停简单退款通知"), | |||
| CAR_CYF_CALLBACK_PARK_IN(620,"车易付进场通知"), | |||
| ; | |||
| public static EnumCarCmd getEnum(Integer code) { | |||
| @@ -1,9 +1,163 @@ | |||
| package com.iformall.utils.car; | |||
| import com.alibaba.fastjson.JSON; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| import org.apache.http.Consts; | |||
| import org.apache.http.HttpEntity; | |||
| import org.apache.http.HttpResponse; | |||
| import org.apache.http.ParseException; | |||
| import org.apache.http.client.methods.HttpPost; | |||
| import org.apache.http.entity.StringEntity; | |||
| import org.apache.http.impl.client.CloseableHttpClient; | |||
| import org.apache.http.impl.client.HttpClients; | |||
| import org.apache.http.message.BasicHeader; | |||
| import org.apache.http.protocol.HTTP; | |||
| import org.apache.http.util.EntityUtils; | |||
| import java.io.IOException; | |||
| import java.text.SimpleDateFormat; | |||
| import java.time.LocalDateTime; | |||
| import java.time.format.DateTimeFormatter; | |||
| import java.util.Date; | |||
| import java.util.HashMap; | |||
| import java.util.Map; | |||
| import java.util.TimeZone; | |||
| /** | |||
| * @author: furunxin | |||
| * @Date: 2020/7/1 17:16 | |||
| * @Description: | |||
| * @Description: 车易付接口对接参数类 | |||
| */ | |||
| @Slf4j | |||
| public class CYFUtil { | |||
| public static final String CYF_PARK_ID = "parkingId"; | |||
| public static final String CYF_CAR_NUMBER = "plate"; | |||
| public static final String CYF_PARK_NAME = "parking"; | |||
| public static final String CYF_SYN_ID = "recordOrderId"; | |||
| public static final String CYF_ENTRANCE_TIME = "inTime"; | |||
| public static final String CYF_IS_RESULT = "result"; | |||
| public static final String CYF_ERR_MSG = "strError"; | |||
| public static final int CYF_SUC = 1; | |||
| public static final int CYF_ERR = 0; | |||
| //会员车辆信息注册接口地址 | |||
| public static final String REGISTER_CAR_URL = "http://oepn.cheyifu2016.com:8892/openapi/personCar"; | |||
| /** | |||
| * @description UTC时间转化为本地时间 | |||
| * @Params [utcTime] | |||
| * @return java.util.Date | |||
| * @Author furunxin | |||
| * @Date 2020/7/8 下午12:45 | |||
| **/ | |||
| public static Date utcToLocal(String utcTime){ | |||
| SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |||
| sdf.setTimeZone(TimeZone.getTimeZone("UTC")); | |||
| Date utcDate = null; | |||
| try { | |||
| utcDate = sdf.parse(utcTime); | |||
| } catch (ParseException e) { | |||
| e.printStackTrace(); | |||
| } catch (java.text.ParseException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| sdf.setTimeZone(TimeZone.getDefault()); | |||
| Date locatlDate = null; | |||
| String localTime = sdf.format(utcDate.getTime()); | |||
| try { | |||
| locatlDate = sdf.parse(localTime); | |||
| } catch (ParseException e) { | |||
| e.printStackTrace(); | |||
| } catch (java.text.ParseException e) { | |||
| e.printStackTrace(); | |||
| } | |||
| return locatlDate; | |||
| } | |||
| public static String getLocalDate(){ | |||
| LocalDateTime ldt = LocalDateTime.now(); | |||
| DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); | |||
| String nowDate = ldt.format(dtf); | |||
| return nowDate; | |||
| } | |||
| /** | |||
| * @description 会员车辆信息注册 | |||
| * @Params [token, carport, feeGroupId, parkingId, plates, personId, personName] | |||
| * @return java.lang.String | |||
| * @Author furunxin | |||
| * @Date 2020/7/8 下午10:12 | |||
| **/ | |||
| public String registerCar(String token,int carport,int feeGroupId,String parkingId,String plates,long personId,String personName){ | |||
| Map<String, Object> paramMap = new HashMap<>(); | |||
| paramMap.put("token ",token); | |||
| paramMap.put("parkingId",parkingId); | |||
| paramMap.put("beginTime",getLocalDate()); | |||
| paramMap.put("endTime",getLocalDate()); | |||
| paramMap.put("feeGroupId",feeGroupId); | |||
| paramMap.put("lotNumber",carport);s | |||
| paramMap.put("personId",personId); | |||
| paramMap.put("personName",personName); | |||
| paramMap.put("plates",plates); | |||
| String result = Proc(REGISTER_CAR_URL, paramMap); | |||
| return result; | |||
| } | |||
| private static String Proc(String url, Map<String, Object> paramMap) { | |||
| CloseableHttpClient httpClient = HttpClients.createDefault(); | |||
| HttpPost httpPost = new HttpPost(url); | |||
| httpPost.addHeader(HTTP.CONTENT_TYPE,"application/json"); | |||
| httpPost.addHeader("Accept", "application/json"); | |||
| httpPost.addHeader("Accept-Encoding", "UTF-8"); | |||
| String jsonstr = JSON.toJSONString(paramMap); | |||
| log.info("请求报文:"+jsonstr); | |||
| try { | |||
| StringEntity se = new StringEntity(jsonstr, Consts.UTF_8); | |||
| se.setContentType("application/json"); | |||
| se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"UTF-8")); | |||
| httpPost.setEntity(se); | |||
| } catch (Exception e) { | |||
| log.error(e.getMessage()); | |||
| } | |||
| HttpResponse response = null; | |||
| try { | |||
| response = httpClient.execute(httpPost); | |||
| } catch (Exception e) { | |||
| log.error(e.getLocalizedMessage()); | |||
| } | |||
| String result = null; | |||
| //打印StatusLine | |||
| log.debug("StatusLine: " + response.getStatusLine()); | |||
| try{ | |||
| //获取实体 | |||
| HttpEntity httpEntity= response.getEntity(); | |||
| result = EntityUtils.toString(httpEntity, "UTF-8"); | |||
| log.debug(result); | |||
| } catch (Exception e) { | |||
| log.error(e.getLocalizedMessage()); | |||
| } | |||
| try { //关闭流并释放资源 | |||
| httpClient.close(); | |||
| } catch (IOException e) { | |||
| log.error(e.getLocalizedMessage()); | |||
| } | |||
| return result; | |||
| } | |||
| } | |||
| @@ -619,69 +619,69 @@ public class TJDUtil { | |||
| return result; | |||
| } | |||
| private static String Proc(String url, String key, String service, Map<String, String> paramMap) { | |||
| CloseableHttpClient httpClient = HttpClients.createDefault(); | |||
| private static String Proc(String url, String key, String service, Map<String, String> paramMap) { | |||
| CloseableHttpClient httpClient = HttpClients.createDefault(); | |||
| HttpPost httpPost = new HttpPost(url); | |||
| httpPost.addHeader(HTTP.CONTENT_TYPE,"application/json"); | |||
| httpPost.addHeader("Accept", "application/json"); | |||
| httpPost.addHeader("Accept-Encoding", "UTF-8"); | |||
| HttpPost httpPost = new HttpPost(url); | |||
| httpPost.addHeader(HTTP.CONTENT_TYPE,"application/json"); | |||
| httpPost.addHeader("Accept", "application/json"); | |||
| httpPost.addHeader("Accept-Encoding", "UTF-8"); | |||
| String timestamp = getCurrentDate(); | |||
| paramMap.put("timestamp", timestamp); | |||
| String timestamp = getCurrentDate(); | |||
| paramMap.put("timestamp", timestamp); | |||
| paramMap.put("service", service); | |||
| paramMap.put("service", service); | |||
| String sign = null; | |||
| try{ | |||
| sign = getSign(paramMap, key); | |||
| }catch(NoSuchAlgorithmException e) { | |||
| logger.error(e.getLocalizedMessage()); | |||
| } | |||
| String sign = null; | |||
| try{ | |||
| sign = getSign(paramMap, key); | |||
| }catch(NoSuchAlgorithmException e) { | |||
| logger.error(e.getLocalizedMessage()); | |||
| } | |||
| paramMap.put("sign", sign); | |||
| paramMap.put("signType", "md5"); | |||
| paramMap.put("sign", sign); | |||
| paramMap.put("signType", "md5"); | |||
| String jsonstr = JSON.toJSONString(paramMap); | |||
| logger.info(jsonstr); | |||
| String jsonstr = JSON.toJSONString(paramMap); | |||
| logger.info(jsonstr); | |||
| try { | |||
| StringEntity se = new StringEntity(jsonstr, Consts.UTF_8); | |||
| se.setContentType("application/json"); | |||
| se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"UTF-8")); | |||
| httpPost.setEntity(se); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| try { | |||
| StringEntity se = new StringEntity(jsonstr, Consts.UTF_8); | |||
| se.setContentType("application/json"); | |||
| se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"UTF-8")); | |||
| httpPost.setEntity(se); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| } | |||
| HttpResponse response = null; | |||
| try { | |||
| response = httpClient.execute(httpPost); | |||
| } catch (Exception e) { | |||
| logger.error(e.getLocalizedMessage()); | |||
| } | |||
| HttpResponse response = null; | |||
| try { | |||
| response = httpClient.execute(httpPost); | |||
| } catch (Exception e) { | |||
| logger.error(e.getLocalizedMessage()); | |||
| } | |||
| String result = null; | |||
| //打印StatusLine | |||
| logger.debug("StatusLine: " + response.getStatusLine()); | |||
| try{ | |||
| //获取实体 | |||
| HttpEntity httpEntity= response.getEntity(); | |||
| result = EntityUtils.toString(httpEntity, "UTF-8"); | |||
| logger.debug(result); | |||
| } catch (Exception e) { | |||
| logger.error(e.getLocalizedMessage()); | |||
| } | |||
| String result = null; | |||
| //打印StatusLine | |||
| logger.debug("StatusLine: " + response.getStatusLine()); | |||
| try{ | |||
| //获取实体 | |||
| HttpEntity httpEntity= response.getEntity(); | |||
| result = EntityUtils.toString(httpEntity, "UTF-8"); | |||
| logger.debug(result); | |||
| } catch (Exception e) { | |||
| logger.error(e.getLocalizedMessage()); | |||
| } | |||
| try { //关闭流并释放资源 | |||
| httpClient.close(); | |||
| } catch (IOException e) { | |||
| logger.error(e.getLocalizedMessage()); | |||
| } | |||
| try { //关闭流并释放资源 | |||
| httpClient.close(); | |||
| } catch (IOException e) { | |||
| logger.error(e.getLocalizedMessage()); | |||
| } | |||
| return result; | |||
| } | |||
| return result; | |||
| } | |||
| } | |||