环境2
This commit is contained in:
parent
c1167e93f9
commit
d584216406
6
pom.xml
6
pom.xml
|
|
@ -25,7 +25,11 @@
|
|||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper-spring-boot-starter</artifactId>
|
||||
<version>1.2.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
|
|
|
|||
|
|
@ -13,4 +13,5 @@ public class RedisCst {
|
|||
public static final String TABLE_CART = "TABLE:CART:";
|
||||
public static final String PRODUCT = "PRODUCT:";
|
||||
|
||||
public static final String INTEGRAL_COIN_KEY = "";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,7 @@ import com.alibaba.fastjson.JSONObject;
|
|||
import com.alibaba.fastjson.serializer.SerializeConfig;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Stone
|
||||
|
|
@ -205,6 +204,34 @@ public class JSONUtil {
|
|||
private static void logError(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
public static JSONObject sortJSONObject(JSONObject jsonObject, Map<String, String> keyMap) {
|
||||
// 提取JSONObject中的键值对到一个列表中
|
||||
// List<Map.Entry<String, Object>> list = new ArrayList<>(jsonObject.toJavaObject(Map.class).entrySet());
|
||||
List<String> list = new ArrayList<>(jsonObject.keySet());
|
||||
|
||||
// 对键值对列表按照键的ASCII顺序进行排序
|
||||
// list.sort(Map.Entry.comparingByKey());
|
||||
Collections.sort(list);
|
||||
// 遍历排序后的列表,将键值对转换为字符串并拼接起来
|
||||
TreeMap<String, Object> sortedMap = new TreeMap<>();
|
||||
for (String key : list) {
|
||||
if (!keyMap.containsKey(key)) {
|
||||
sortedMap.put(key, jsonObject.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
// 返回排序后的字符串
|
||||
return new JSONObject(sortedMap);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String str = "{\"openId\": \"or1l864NBOoJZhC5x_yeziZ26j6c\",\"num\": 0,\"type\": \"sub\",\"userSign\": \"66a4e4464d4e4ffda8ff729ed0e28d63\"}";
|
||||
JSONObject jsonObject = JSON.parseObject(str);
|
||||
System.out.println(sortJSONObject(jsonObject,CacheMap.map));
|
||||
System.out.println(MD5Util.encrypt(sortJSONObject(jsonObject,CacheMap.map).toJSONString()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ import java.util.concurrent.TimeUnit;
|
|||
@SuppressWarnings({"unchecked", "all"})
|
||||
public class RedisUtils {
|
||||
private static final Logger log = LoggerFactory.getLogger(RedisUtils.class);
|
||||
@Resource
|
||||
private RedisTemplate<Object, Object> redisTemplate;
|
||||
@Value("${jwt.online-key}")
|
||||
private String onlineKey;
|
||||
|
|
@ -772,5 +773,13 @@ public class RedisUtils {
|
|||
return reString;
|
||||
|
||||
}
|
||||
public boolean lock(String key, long timeout, TimeUnit timeUnit) {
|
||||
String value = UUID.randomUUID().toString();
|
||||
Boolean success = redisTemplate.opsForValue().setIfAbsent(key, value, timeout, timeUnit);
|
||||
return success != null && success;
|
||||
}
|
||||
|
||||
public void releaseLock(String key) {
|
||||
redisTemplate.delete(key);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.chaozhanggui.system.cashierservice.util;
|
|||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.JwtBuilder;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
|
|
@ -57,7 +58,15 @@ public class TokenUtil {
|
|||
|
||||
return generateToken(claims);
|
||||
}
|
||||
public static String generateJfToken(String openId,String userSign) throws Exception {
|
||||
Map<String, Object> claims = new HashMap<>(1);
|
||||
claims.put("openId",openId);
|
||||
claims.put("userSign",userSign);
|
||||
|
||||
|
||||
|
||||
return generateToken(claims);
|
||||
}
|
||||
/**
|
||||
* 生成token
|
||||
* @param claims
|
||||
|
|
@ -105,12 +114,13 @@ public class TokenUtil {
|
|||
* @param token token
|
||||
* @return 用户Id
|
||||
*/
|
||||
public static Object parseParamFromToken(final String token, final String paramName ) {
|
||||
public static JSONObject parseParamFromToken(final String token) {
|
||||
Claims claims = Jwts.parser()
|
||||
.setSigningKey(TOKEN_SECRET)
|
||||
.parseClaimsJws(token)
|
||||
.getBody();
|
||||
return claims.get(paramName);
|
||||
JSONObject jsonObject = (JSONObject) JSONObject.toJSON(claims);
|
||||
return jsonObject;
|
||||
}
|
||||
public static void main(String[] args){
|
||||
System.out.println(refreshToken("eyJhbGciOiJIUzUxMiJ9.eyJleHAiOjE1OTY4Nzc5MjEsInN1YiI6ImRkZGRkIiwiaWF0IjoxNTk2Njk3OTIxfQ.lrg3KF9h9izbmyD2q5onqnZIKBqanWy9xCcroFpjxPKmJz6kz27G9lVlFpVanrL1I4SFf3Dz3q3Xu01DX2T_dw"));
|
||||
|
|
|
|||
Loading…
Reference in New Issue