feat:外部接口接入
This commit is contained in:
@@ -236,7 +236,9 @@ public enum ErrorCodeEnum {
|
||||
UPDATE_INVESTMENT_MANAGER_FAIL(131005,"当前用户已经为该门店招商经理",null),
|
||||
CONFIRM_THE_APPROVER(131006,"您提交的铺位暂时找不到选址审批人,请联系系统管理员配置选址审批权限后再提交铺位审批",null),
|
||||
|
||||
TALLY_BOOK_NOT_EXIST(180001, "记账本数据不存在", null)
|
||||
TALLY_BOOK_NOT_EXIST(180001, "记账本数据不存在", null),
|
||||
|
||||
THIRD_API_ERROR(151001,"第三方服务异常->{0}",null),
|
||||
;
|
||||
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.*;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
@@ -32,6 +34,13 @@ public class CoolDateUtils {
|
||||
public static final String DATE_FORMAT_SEC_5 = "yyyy.MM.dd HH:mm";
|
||||
public static final String DATE_FORMAT_SEC_6 = "yyyy.MM.dd";
|
||||
public static final String DATE_FORMAT_SEC_7 = "yyyy/MM/dd HH:mm";
|
||||
|
||||
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
|
||||
private static final DateTimeFormatter getDateFormatter(String format){
|
||||
return DateTimeFormatter.ofPattern(format);
|
||||
}
|
||||
|
||||
/**
|
||||
* 几天后的当前
|
||||
* @param d
|
||||
@@ -128,4 +137,26 @@ public class CoolDateUtils {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取当前日期字符串 (yyyy-MM-dd)
|
||||
*/
|
||||
public static String getCurrentDate() {
|
||||
return LocalDate.now().format(getDateFormatter(DATE_FORMAT_DAY));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取上月同一天的日期字符串 (yyyy-MM-dd)
|
||||
* 如果上个月没有同一天(如当前是3月31日,但2月没有31日),则返回上个月的最后一天
|
||||
*/
|
||||
public static String getSameDayLastMonth() {
|
||||
LocalDate today = LocalDate.now();
|
||||
LocalDate lastMonthSameDay = today.minusMonths(1);
|
||||
|
||||
// 处理跨月情况(如3月31日,2月没有31日)
|
||||
if (lastMonthSameDay.getDayOfMonth() != today.getDayOfMonth()) {
|
||||
lastMonthSameDay = lastMonthSameDay.with(TemporalAdjusters.lastDayOfMonth());
|
||||
}
|
||||
|
||||
return lastMonthSameDay.format(getDateFormatter(DATE_FORMAT_DAY));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.cool.store.utils;
|
||||
import java.util.BitSet;
|
||||
/**
|
||||
* @Author suzhuhong
|
||||
* @Date 2025/4/1 20:39
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
public class GeoHashUtils {
|
||||
private static final String BASE32 = "0123456789bcdefghjkmnpqrstuvwxyz";
|
||||
private static final int[] BITS = {16, 8, 4, 2, 1};
|
||||
|
||||
public static String encode(double lat, double lon, int precision) {
|
||||
BitSet latBits = getBits(lat, -90, 90);
|
||||
BitSet lonBits = getBits(lon, -180, 180);
|
||||
|
||||
StringBuilder hash = new StringBuilder();
|
||||
for (int i = 0; i < precision; i++) {
|
||||
int index = 0;
|
||||
for (int j = 0; j < 5; j++) {
|
||||
boolean lonBit = lonBits.get(i * 5 + j);
|
||||
boolean latBit = latBits.get(i * 5 + j);
|
||||
index = (index << 1) | (lonBit ? 1 : 0);
|
||||
index = (index << 1) | (latBit ? 1 : 0);
|
||||
}
|
||||
hash.append(BASE32.charAt(index));
|
||||
}
|
||||
return hash.toString();
|
||||
}
|
||||
|
||||
private static BitSet getBits(double val, double min, double max) {
|
||||
BitSet bits = new BitSet();
|
||||
for (int i = 0; i < 30; i++) {
|
||||
double mid = (min + max) / 2;
|
||||
if (val >= mid) {
|
||||
bits.set(i);
|
||||
min = mid;
|
||||
} else {
|
||||
max = mid;
|
||||
}
|
||||
}
|
||||
return bits;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.cool.store.utils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author suzhuhong
|
||||
* @Date 2025/3/26 19:39
|
||||
* @Version 1.0
|
||||
*/
|
||||
|
||||
public class JsonUtils {
|
||||
private static final Gson gson = new Gson();
|
||||
|
||||
public static String toJson(Object obj) {
|
||||
return gson.toJson(obj);
|
||||
}
|
||||
|
||||
public static Map<String, Object> parseJsonToMap(String json) {
|
||||
return gson.fromJson(json, new TypeToken<Map<String, Object>>() {}.getType());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.cool.store.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @Author suzhuhong
|
||||
* @Date 2025/3/26 19:32
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Slf4j
|
||||
public class SignatureUtils {
|
||||
|
||||
/**
|
||||
* 生成 HmacSHA256 签名
|
||||
* @param data 待签名字符串
|
||||
* @param secret 密钥
|
||||
* @return 签名(Hex小写)
|
||||
*/
|
||||
public static String hmacSha256(String data, String secret) {
|
||||
try {
|
||||
Mac mac = Mac.getInstance("HmacSHA256");
|
||||
SecretKeySpec secretKey = new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
|
||||
mac.init(secretKey);
|
||||
byte[] hash = mac.doFinal(data.getBytes(StandardCharsets.UTF_8));
|
||||
return bytesToHex(hash).toLowerCase();
|
||||
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
|
||||
throw new RuntimeException("HmacSHA256签名失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成待签名字符串(参数按字母排序 + appkey + timestamp)
|
||||
* @param params 请求参数Map(需提前过滤空值)
|
||||
* @param appKey 应用Key
|
||||
* @param timestamp 时间戳(毫秒)
|
||||
*/
|
||||
public static String buildSignString(Map<String, Object> params, String appKey, long timestamp) {
|
||||
TreeMap<String, Object> sortedParams = new TreeMap<>(params);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
// 拼接排序后的参数
|
||||
sortedParams.forEach((key, value) ->{
|
||||
if (Objects.isNull(value)||(value instanceof Double &&((Double) value).intValue()==0)){
|
||||
log.info("0或者空值不参与签名");
|
||||
}else {
|
||||
if (value instanceof Double){
|
||||
sb.append(key).append("=").append(((Double) value).intValue()).append("&");
|
||||
}else {
|
||||
sb.append(key).append("=").append(value).append("&");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
sb.append("appkey=").append(appKey).append("×tamp=").append(timestamp);
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private static String bytesToHex(byte[] bytes) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (byte b : bytes) {
|
||||
sb.append(String.format("%02x", b));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user