mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-05-08 12:00:11 +08:00
新增 路通云停系统获取令牌接口
This commit is contained in:
@@ -45,6 +45,7 @@ import com.jsowell.pile.domain.ykcCommond.IssueQRCodeCommand;
|
|||||||
import com.jsowell.pile.domain.ykcCommond.ProofreadTimeCommand;
|
import com.jsowell.pile.domain.ykcCommond.ProofreadTimeCommand;
|
||||||
import com.jsowell.pile.dto.*;
|
import com.jsowell.pile.dto.*;
|
||||||
import com.jsowell.pile.dto.amap.GetStationInfoDTO;
|
import com.jsowell.pile.dto.amap.GetStationInfoDTO;
|
||||||
|
import com.jsowell.pile.dto.lutongyunting.GetTokenDTO;
|
||||||
import com.jsowell.pile.mapper.MemberBasicInfoMapper;
|
import com.jsowell.pile.mapper.MemberBasicInfoMapper;
|
||||||
import com.jsowell.pile.mapper.PileBillingTemplateMapper;
|
import com.jsowell.pile.mapper.PileBillingTemplateMapper;
|
||||||
import com.jsowell.pile.service.*;
|
import com.jsowell.pile.service.*;
|
||||||
@@ -63,6 +64,7 @@ import com.jsowell.thirdparty.lianlian.service.LianLianService;
|
|||||||
import com.jsowell.thirdparty.lianlian.util.Cryptos;
|
import com.jsowell.thirdparty.lianlian.util.Cryptos;
|
||||||
import com.jsowell.thirdparty.lianlian.util.Encodes;
|
import com.jsowell.thirdparty.lianlian.util.Encodes;
|
||||||
import com.jsowell.thirdparty.lianlian.util.GBSignUtils;
|
import com.jsowell.thirdparty.lianlian.util.GBSignUtils;
|
||||||
|
import com.jsowell.thirdparty.lutongyunting.service.LTYTService;
|
||||||
import com.jsowell.wxpay.common.WeChatPayParameter;
|
import com.jsowell.wxpay.common.WeChatPayParameter;
|
||||||
import com.jsowell.wxpay.dto.AppletTemplateMessageSendDTO;
|
import com.jsowell.wxpay.dto.AppletTemplateMessageSendDTO;
|
||||||
import com.jsowell.wxpay.response.WechatPayRefundRequest;
|
import com.jsowell.wxpay.response.WechatPayRefundRequest;
|
||||||
@@ -200,6 +202,9 @@ public class SpringBootTestController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private OrderPileOccupyService orderPileOccupyService;
|
private OrderPileOccupyService orderPileOccupyService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private LTYTService ltytService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 手动变更银行卡信息
|
* 手动变更银行卡信息
|
||||||
*/
|
*/
|
||||||
@@ -396,6 +401,15 @@ public class SpringBootTestController {
|
|||||||
System.out.println(memberPlateInfoByVinCode);
|
System.out.println(memberPlateInfoByVinCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testParking() {
|
||||||
|
GetTokenDTO dto = new GetTokenDTO();
|
||||||
|
dto.setAppId("I2qa3hdr116100dc");
|
||||||
|
dto.setSecretKey("2qa3hdr13754a8e");
|
||||||
|
String token = ltytService.getToken(dto);
|
||||||
|
System.out.println(token);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateConnectorStatus() {
|
public void testUpdateConnectorStatus() {
|
||||||
String pileConnectorCode = "8800000000000101";
|
String pileConnectorCode = "8800000000000101";
|
||||||
|
|||||||
@@ -136,15 +136,20 @@ public class CacheConstants {
|
|||||||
public static final String COMPONENT_ACCESS_TOKEN = "component_access_token:";
|
public static final String COMPONENT_ACCESS_TOKEN = "component_access_token:";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接口调用令牌
|
* 微信第三方平台 接口调用令牌
|
||||||
*/
|
*/
|
||||||
public static final String AUTHORIZER_ACCESS_TOKEN = "authorizer_access_token:";
|
public static final String AUTHORIZER_ACCESS_TOKEN = "authorizer_access_token:";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 刷新令牌
|
* 微信第三方平台 刷新令牌
|
||||||
*/
|
*/
|
||||||
public static final String AUTHORIZER_REFRESH_TOKEN = "authorizer_refresh_token:";
|
public static final String AUTHORIZER_REFRESH_TOKEN = "authorizer_refresh_token:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 路通云停系统 通过appid获取的接口调用令牌
|
||||||
|
*/
|
||||||
|
public static final String LTYT_TOKEN_BY_APPID = "ltyt_token_by_appid:";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 桩硬件故障
|
* 桩硬件故障
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.jsowell.pile.dto.lutongyunting;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 路通云停道闸系统请求获取tokenDTO
|
||||||
|
*
|
||||||
|
* @author Lemon
|
||||||
|
* @Date 2023/8/23 11:11
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class GetTokenDTO {
|
||||||
|
private String stationId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 唯一标识
|
||||||
|
*/
|
||||||
|
private String appId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 平台密钥
|
||||||
|
*/
|
||||||
|
private String secretKey;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 请求时间,格式:YYYYMMDDHHMMSS
|
||||||
|
*/
|
||||||
|
private String accTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1.0
|
||||||
|
*/
|
||||||
|
private String version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用签名公式获得
|
||||||
|
*/
|
||||||
|
private String sign;
|
||||||
|
}
|
||||||
21
jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lutongyunting/service/LTYTService.java
vendored
Normal file
21
jsowell-thirdparty/src/main/java/com/jsowell/thirdparty/lutongyunting/service/LTYTService.java
vendored
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package com.jsowell.thirdparty.lutongyunting.service;
|
||||||
|
|
||||||
|
import com.jsowell.pile.dto.lutongyunting.GetTokenDTO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO
|
||||||
|
*
|
||||||
|
* @author Lemon
|
||||||
|
* @Date 2023/8/23 11:07
|
||||||
|
*/
|
||||||
|
public interface LTYTService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取平台令牌
|
||||||
|
* @param dto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
String getToken(GetTokenDTO dto);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,125 @@
|
|||||||
|
package com.jsowell.thirdparty.lutongyunting.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.http.HttpUtil;
|
||||||
|
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.util.DateUtils;
|
||||||
|
import com.jsowell.common.util.StringUtils;
|
||||||
|
import com.jsowell.common.util.sign.MD5Util;
|
||||||
|
import com.jsowell.pile.dto.lutongyunting.GetTokenDTO;
|
||||||
|
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.util.*;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO
|
||||||
|
*
|
||||||
|
* @author Lemon
|
||||||
|
* @Date 2023/8/23 11:19
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class LTYTServiceImpl implements LTYTService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisCache redisCache;
|
||||||
|
|
||||||
|
// private static final String APP_ID = "I2qa3hdr116100dc"; // I2qa3hdr116100dc I2qa3jfnd96f267c
|
||||||
|
|
||||||
|
// private static final String SECRET_KEY = "2qa3hdr13754a8e"; // 2qa3hdr13754a8e 2qa3jfndb37926d
|
||||||
|
|
||||||
|
private static final String BASE_URL = "https://entry-openapi.sn6.co/api/";
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(LTYTServiceImpl.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 路通云停系统获取令牌
|
||||||
|
* @param dto
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String getToken(GetTokenDTO dto) {
|
||||||
|
// 检查缓存中是否有token
|
||||||
|
String key = CacheConstants.LTYT_TOKEN_BY_APPID + dto.getAppId();
|
||||||
|
String token = redisCache.getCacheObject(key);
|
||||||
|
if (StringUtils.isNotBlank(token)) {
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
// String appId = "I2qa3hdr116100dc";
|
||||||
|
String accTime = DateUtils.dateTimeNow(DateUtils.YYYYMMDDHHMMSS);
|
||||||
|
|
||||||
|
String url = BASE_URL + "getApiToken";
|
||||||
|
|
||||||
|
// 封装参数
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("appId", dto.getAppId());
|
||||||
|
jsonObject.put("accTime", accTime);
|
||||||
|
jsonObject.put("version", "1.0");
|
||||||
|
|
||||||
|
// Map<String, Object> map = new LinkedHashMap<>();
|
||||||
|
// map.put("appId", dto.getAppId());
|
||||||
|
// map.put("accTime", accTime);
|
||||||
|
// map.put("version", "1.0");
|
||||||
|
|
||||||
|
// 获取sign签名
|
||||||
|
String sign = getSign(jsonObject, dto.getSecretKey());
|
||||||
|
// map.put("sign", sign);
|
||||||
|
|
||||||
|
jsonObject.put("sign", sign);
|
||||||
|
|
||||||
|
// 发送请求
|
||||||
|
String result = HttpUtil.post(url, JSON.toJSONString(jsonObject));
|
||||||
|
log.info("路通云停系统获取令牌 result:{}", result);
|
||||||
|
JSONObject resultJson = JSONObject.parseObject(result);
|
||||||
|
Integer code = resultJson.getInteger("code");
|
||||||
|
if (code == 200) {
|
||||||
|
token = resultJson.getJSONObject("data").getString("token");
|
||||||
|
Integer expiredTime = resultJson.getJSONObject("data").getInteger("expiry");
|
||||||
|
// 存入缓存
|
||||||
|
redisCache.setCacheObject(key, token, expiredTime, TimeUnit.HOURS);
|
||||||
|
return redisCache.getCacheObject(key);
|
||||||
|
}else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// String accTime = DateUtils.dateTimeNow(DateUtils.YYYYMMDDHHMMSS);
|
||||||
|
// Map<String, Object> map = new LinkedMap<>();
|
||||||
|
// map.put("appId", "appId");
|
||||||
|
// map.put("accTime", accTime);
|
||||||
|
// map.put("version", "version");
|
||||||
|
// System.out.println(map);
|
||||||
|
// // 排序
|
||||||
|
// TreeMap<String, Object> params = new TreeMap<String, Object>(map);
|
||||||
|
//
|
||||||
|
// StringBuilder sb = new StringBuilder();
|
||||||
|
// for (String key : params.keySet()) {
|
||||||
|
// sb.append(key).append("=").append(params.get(key)).append("&");
|
||||||
|
// }
|
||||||
|
// sb.deleteCharAt(sb.length() - 1);
|
||||||
|
//
|
||||||
|
// String dataStr = sb + "secretKey";
|
||||||
|
// String sign = MD5Util.MD5Encode(dataStr).toLowerCase(Locale.ROOT);
|
||||||
|
// System.out.println(sign);
|
||||||
|
}
|
||||||
|
|
||||||
|
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(secretKey);
|
||||||
|
return MD5Util.MD5Encode(sb.toString()).toLowerCase(Locale.ROOT);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user