新增 路通云停平台 给车辆绑定优惠券接口

This commit is contained in:
Lemon
2023-08-24 10:33:26 +08:00
parent afe370fc8a
commit 318f46123e
4 changed files with 72 additions and 9 deletions

View File

@@ -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;
}

View File

@@ -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<String, Object> map = new LinkedMap<>();
// map.put("appId", "appId");