mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-06-11 18:59:51 +08:00
新增 软杰道闸系统对接
This commit is contained in:
@@ -0,0 +1,43 @@
|
|||||||
|
package com.jsowell.ruanjie;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.jsowell.common.annotation.Anonymous;
|
||||||
|
import com.jsowell.common.core.controller.BaseController;
|
||||||
|
import com.jsowell.common.response.RestApiResponse;
|
||||||
|
import com.jsowell.pile.dto.ruanjie.UseCouponDTO;
|
||||||
|
import com.jsowell.thirdparty.ruanjie.service.RJService;
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 软杰controller
|
||||||
|
*
|
||||||
|
* @author Lemon
|
||||||
|
* @Date 2023/9/22 9:00
|
||||||
|
*/
|
||||||
|
@Anonymous
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/ruanjie")
|
||||||
|
public class RJController extends BaseController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RJService rjService;
|
||||||
|
|
||||||
|
@PostMapping("/useCoupon")
|
||||||
|
public RestApiResponse<?> useCoupon(@RequestBody UseCouponDTO dto) {
|
||||||
|
logger.info("软杰--使用优惠券 params:{}", JSON.toJSONString(dto));
|
||||||
|
RestApiResponse<?> response = null;
|
||||||
|
try {
|
||||||
|
String result = rjService.useCoupon(dto);
|
||||||
|
response = new RestApiResponse<>(result);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("软杰--使用优惠券 error, ", e);
|
||||||
|
response = new RestApiResponse<>(e);
|
||||||
|
}
|
||||||
|
logger.info("软杰--使用优惠券 result:{}", response);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package com.jsowell.pile.dto.ruanjie;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.annotation.JSONField;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 软杰使用优惠券DTO
|
||||||
|
*
|
||||||
|
* @author Lemon
|
||||||
|
* @Date 2023/9/22 8:42
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class UseCouponDTO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 客户编号
|
||||||
|
* 该值由厂商提供
|
||||||
|
*/
|
||||||
|
private String fCustNo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 车牌号码
|
||||||
|
* 该值来源进场数据
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "fPlateCode")
|
||||||
|
private String fPlateCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券类型ID
|
||||||
|
* 0 表示 免费停车
|
||||||
|
* 1 表示 抵扣金额(元)
|
||||||
|
* 2 表示 抵扣时间
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "fCouponType")
|
||||||
|
private String fCouponType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券面值
|
||||||
|
* fCouponType=0 时 fCouponValue=”0” 免费停车优惠券
|
||||||
|
* fCouponType=1时 fCouponValue 表示实际抵扣金额,单位元。
|
||||||
|
* fCouponType=2时 fCouponValue 表示实际抵扣时间,单位分钟
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "fCouponValue")
|
||||||
|
private String fCouponValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券编号
|
||||||
|
*/
|
||||||
|
@JsonProperty(value = "fCouponCode")
|
||||||
|
private String fCouponCode;
|
||||||
|
}
|
||||||
19
jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/ruanjie/service/RJService.java
vendored
Normal file
19
jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/ruanjie/service/RJService.java
vendored
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package com.jsowell.thirdparty.ruanjie.service;
|
||||||
|
|
||||||
|
import com.jsowell.pile.dto.ruanjie.UseCouponDTO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 软杰Service
|
||||||
|
*
|
||||||
|
* @author Lemon
|
||||||
|
* @Date 2023/9/22 8:41
|
||||||
|
*/
|
||||||
|
public interface RJService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 软杰--使用优惠券
|
||||||
|
* @param dto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String useCoupon(UseCouponDTO dto);
|
||||||
|
}
|
||||||
76
jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/ruanjie/service/impl/RJServiceImpl.java
vendored
Normal file
76
jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/ruanjie/service/impl/RJServiceImpl.java
vendored
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
package com.jsowell.thirdparty.ruanjie.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.http.HttpUtil;
|
||||||
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.jsowell.common.util.sign.MD5Util;
|
||||||
|
import com.jsowell.pile.dto.ruanjie.UseCouponDTO;
|
||||||
|
import com.jsowell.thirdparty.lutongyunting.service.impl.LTYTServiceImpl;
|
||||||
|
import com.jsowell.thirdparty.ruanjie.service.RJService;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO
|
||||||
|
*
|
||||||
|
* @author Lemon
|
||||||
|
* @Date 2023/9/22 8:46
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class RJServiceImpl implements RJService {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(LTYTServiceImpl.class);
|
||||||
|
|
||||||
|
private static final String BASE_URL = "https://redpay.ruanjiesh.com/ThirdAPI";
|
||||||
|
|
||||||
|
private static final String SECRET_KEY = "ced9ar3ingZ";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 软杰--使用优惠券
|
||||||
|
* @param dto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String useCoupon(UseCouponDTO dto) {
|
||||||
|
String url = BASE_URL + "/api/Coupon/UseCoupon";
|
||||||
|
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("fCustID", 0);
|
||||||
|
jsonObject.put("fCustNo", "390099");
|
||||||
|
jsonObject.put("fBusID", 0);
|
||||||
|
jsonObject.put("fInTime", 0);
|
||||||
|
jsonObject.put("fPlateCode", dto.getFPlateCode());
|
||||||
|
jsonObject.put("fCouponType", dto.getFCouponType());
|
||||||
|
jsonObject.put("fCouponValue", dto.getFCouponValue());
|
||||||
|
jsonObject.put("fCouponCode", dto.getFCouponCode());
|
||||||
|
jsonObject.put("fStatus", "1"); // 1-有效
|
||||||
|
// 获取sign
|
||||||
|
String sign = getSign(jsonObject, SECRET_KEY);
|
||||||
|
|
||||||
|
jsonObject.put("sign", sign);
|
||||||
|
// 发送post请求
|
||||||
|
log.info("软杰--使用优惠券 params:{}, url:{}", JSON.toJSONString(jsonObject), url);
|
||||||
|
String result = HttpUtil.post(url, JSON.toJSONString(jsonObject));
|
||||||
|
log.info("软杰--使用优惠券 result:{}", result);
|
||||||
|
JSONObject resultJson = JSONObject.parseObject(result);
|
||||||
|
|
||||||
|
return resultJson.getString("return_msg");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getSign(JSONObject jsonObject, String secretKey) {
|
||||||
|
// String secretKey = "";
|
||||||
|
TreeMap<String, Object> params = new TreeMap<>(jsonObject);
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (String key : params.keySet()) {
|
||||||
|
sb.append(key).append("=").append(params.get(key)).append("&");
|
||||||
|
}
|
||||||
|
sb.deleteCharAt(sb.length() - 1);
|
||||||
|
sb.append("&key=").append(secretKey);
|
||||||
|
return MD5Util.MD5Encode(sb.toString()).toLowerCase(Locale.ROOT);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user