diff --git a/jsowell-admin/src/test/java/SpringBootTestController.java b/jsowell-admin/src/test/java/SpringBootTestController.java index 7fc643e33..9d5737460 100644 --- a/jsowell-admin/src/test/java/SpringBootTestController.java +++ b/jsowell-admin/src/test/java/SpringBootTestController.java @@ -45,6 +45,7 @@ import com.jsowell.pile.domain.ykcCommond.IssueQRCodeCommand; import com.jsowell.pile.domain.ykcCommond.ProofreadTimeCommand; import com.jsowell.pile.dto.*; import com.jsowell.pile.dto.amap.GetStationInfoDTO; +import com.jsowell.pile.dto.lutongyunting.BindCouponDTO; import com.jsowell.pile.dto.lutongyunting.GetTokenDTO; import com.jsowell.pile.mapper.MemberBasicInfoMapper; import com.jsowell.pile.mapper.PileBillingTemplateMapper; @@ -402,12 +403,22 @@ public class SpringBootTestController { } @Test - public void testParking() { - GetTokenDTO dto = new GetTokenDTO(); + public void testParking() throws UnsupportedEncodingException { + // GetTokenDTO dto = new GetTokenDTO(); + // dto.setAppId("I2qa3hdr116100dc"); + // dto.setSecretKey("2qa3hdr13754a8e"); + // String token = ltytService.getToken(dto); + // System.out.println(token); + + BindCouponDTO dto = new BindCouponDTO(); dto.setAppId("I2qa3hdr116100dc"); dto.setSecretKey("2qa3hdr13754a8e"); - String token = ltytService.getToken(dto); - System.out.println(token); + dto.setMerchantId("3prv98bm8db70a9"); + dto.setCouponId("3prvd0q7a4817bf"); + dto.setPlateNumber("贵A12345"); + dto.setPlateColor(1); + String s = ltytService.bindCoupon(dto); + System.out.println(s); } @Test diff --git a/jsowell-pile/src/main/java/com/jsowell/pile/dto/lutongyunting/BindCouponDTO.java b/jsowell-pile/src/main/java/com/jsowell/pile/dto/lutongyunting/BindCouponDTO.java index 5ad814a6e..7bc733a13 100644 --- a/jsowell-pile/src/main/java/com/jsowell/pile/dto/lutongyunting/BindCouponDTO.java +++ b/jsowell-pile/src/main/java/com/jsowell/pile/dto/lutongyunting/BindCouponDTO.java @@ -10,6 +10,10 @@ import lombok.Data; */ @Data public class BindCouponDTO { + private String appId; + + private String secretKey; + /** * 优惠券商家标识 */ @@ -28,5 +32,5 @@ public class BindCouponDTO { /** * 车牌颜色 */ - private String plateColor; + private Integer plateColor; } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lutongyunting/service/LTYTService.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lutongyunting/service/LTYTService.java index 6adfa3da5..43638939c 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lutongyunting/service/LTYTService.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lutongyunting/service/LTYTService.java @@ -3,8 +3,10 @@ package com.jsowell.thirdparty.lutongyunting.service; import com.jsowell.pile.dto.lutongyunting.BindCouponDTO; import com.jsowell.pile.dto.lutongyunting.GetTokenDTO; +import java.io.UnsupportedEncodingException; + /** - * TODO + * 路通云停 Service * * @author Lemon * @Date 2023/8/23 11:07 @@ -23,5 +25,5 @@ public interface LTYTService { * @param dto * @return */ - String bindCoupon(BindCouponDTO dto); + String bindCoupon(BindCouponDTO dto) throws UnsupportedEncodingException; } diff --git a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lutongyunting/service/impl/LTYTServiceImpl.java b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lutongyunting/service/impl/LTYTServiceImpl.java index 4af8620cd..752e0880e 100644 --- a/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lutongyunting/service/impl/LTYTServiceImpl.java +++ b/jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lutongyunting/service/impl/LTYTServiceImpl.java @@ -5,17 +5,21 @@ import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.jsowell.common.constant.CacheConstants; import com.jsowell.common.core.redis.RedisCache; +import com.jsowell.common.exception.BusinessException; import com.jsowell.common.util.DateUtils; import com.jsowell.common.util.StringUtils; import com.jsowell.common.util.sign.MD5Util; import com.jsowell.pile.dto.lutongyunting.BindCouponDTO; import com.jsowell.pile.dto.lutongyunting.GetTokenDTO; +import com.jsowell.thirdparty.lutongyunting.common.LTYTCommonParams; import com.jsowell.thirdparty.lutongyunting.service.LTYTService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.util.*; import java.util.concurrent.TimeUnit; @@ -89,11 +93,53 @@ public class LTYTServiceImpl implements LTYTService { * @return */ @Override - public String bindCoupon(BindCouponDTO dto) { + public String bindCoupon(BindCouponDTO dto) throws UnsupportedEncodingException { + // 获取令牌 + GetTokenDTO tokenDTO = new GetTokenDTO(); + tokenDTO.setAppId(dto.getAppId()); + tokenDTO.setSecretKey(dto.getSecretKey()); + String token = getToken(tokenDTO); + if (StringUtils.isBlank(token)) { + throw new BusinessException("", "路通云停系统 给指定车辆绑定优惠券 方法获取令牌失败"); + } + // LTYTCommonParams params = new LTYTCommonParams(); + // params.setAppId(dto.getAppId()); + // params.setAccTime(DateUtils.dateTimeNow(DateUtils.YYYYMMDDHHMMSS)); + // params.setToken(token); + // params.setVersion("1.0"); + + String url = BASE_URL + "bindCoupon"; + JSONObject jsonObject = new JSONObject(); + // 公共参数 + jsonObject.put("appId", dto.getAppId()); + jsonObject.put("token", token); + jsonObject.put("accTime", DateUtils.dateTimeNow(DateUtils.YYYYMMDDHHMMSS)); + jsonObject.put("version", "1.0"); + // 业务参数 + jsonObject.put("merchantId", dto.getMerchantId()); + jsonObject.put("couponId", dto.getCouponId()); + jsonObject.put("plateNumber", dto.getPlateNumber()); + jsonObject.put("plateColor", dto.getPlateColor()); + + String encodeData = URLEncoder.encode(JSON.toJSONString(jsonObject), "UTF-8"); + jsonObject.put("data", encodeData); + + // 发送请求 + String result = HttpUtil.post(url, JSON.toJSONString(jsonObject)); + log.info("给指定车辆绑定优惠券 params:{}, result:{}", JSON.toJSONString(jsonObject), result); + return null; } - public static void main(String[] args) { + public static void main(String[] args) throws UnsupportedEncodingException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("merchantId", "merchantId"); + jsonObject.put("couponId", "couponId"); + jsonObject.put("plateNumber", "plateNumber"); + jsonObject.put("plateColor", 2); + + String encodeData = URLEncoder.encode(JSON.toJSONString(jsonObject), "UTF-8"); + System.out.println(encodeData); // String accTime = DateUtils.dateTimeNow(DateUtils.YYYYMMDDHHMMSS); // Map map = new LinkedMap<>(); // map.put("appId", "appId");