master
parent
64b5e5e567
commit
8679be33df
@ -0,0 +1,23 @@
|
|||||||
|
package com.rehome.jpahefengweather.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Entity
|
||||||
|
public class HefengProvince implements Serializable{
|
||||||
|
@Id
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
private Date createDate;
|
||||||
|
|
||||||
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
|
private Date lastUpdateDate;
|
||||||
|
}
|
||||||
@ -1,15 +1,34 @@
|
|||||||
package com.rehome.jpahefengweather.service;
|
package com.rehome.jpahefengweather.service;
|
||||||
|
|
||||||
import com.liuhuiyu.util.model.Result;
|
import com.rehome.jpahefengweather.entity.HefengCity;
|
||||||
import com.rehome.jpahefengweather.entity.CityList;
|
import com.rehome.jpahefengweather.entity.HefengProvince;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface CityService {
|
public interface CityService {
|
||||||
void saveCitys(List<CityList> cityLists);
|
/**
|
||||||
|
* 保存省份列表
|
||||||
|
* @param provinceList
|
||||||
|
*/
|
||||||
|
void saveProvinceList(List<HefengProvince> provinceList);
|
||||||
|
/**
|
||||||
|
* 保存城市列表
|
||||||
|
* @param cityList
|
||||||
|
*/
|
||||||
|
void saveCityList(List<HefengCity> cityList);
|
||||||
|
/**
|
||||||
|
* 查询全国3000+个市县区
|
||||||
|
* @return List
|
||||||
|
*/
|
||||||
|
List<HefengCity> findAllCity();
|
||||||
|
/**
|
||||||
|
* 查询全国3000+个市县区
|
||||||
|
* @return List
|
||||||
|
*/
|
||||||
|
List<HefengCity> findCityByProvinceCode(String provinceCode);
|
||||||
/**
|
/**
|
||||||
* 查询全国3000+个市县区
|
* 查询全国3000+个市县区
|
||||||
* @return List
|
* @return List
|
||||||
*/
|
*/
|
||||||
List<CityList> findAllCitys();
|
List<HefengProvince> findAllProvince();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,66 @@
|
|||||||
|
package com.rehome.jpahefengweather.utils;
|
||||||
|
|
||||||
|
import net.i2p.crypto.eddsa.EdDSAEngine;
|
||||||
|
import net.i2p.crypto.eddsa.EdDSAPrivateKey;
|
||||||
|
import net.i2p.crypto.eddsa.spec.EdDSANamedCurveTable;
|
||||||
|
import net.i2p.crypto.eddsa.spec.EdDSAParameterSpec;
|
||||||
|
import okhttp3.Interceptor;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
import org.springframework.lang.NonNull;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.PrivateKey;
|
||||||
|
import java.security.Signature;
|
||||||
|
import java.security.spec.PKCS8EncodedKeySpec;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
|
public class JwtUtils {
|
||||||
|
public static String getJwt(){
|
||||||
|
try {
|
||||||
|
// Private key
|
||||||
|
String privateKeyString = "MC4CAQAwBQYDK2VwBCIEIOtI2Yuhkyor4Zfny9OUMbzMmZCEJ7hqIpuoDhk0zYcy";
|
||||||
|
privateKeyString = privateKeyString.trim().replace("-----BEGIN PRIVATE KEY-----", "").replace("-----END PRIVATE KEY-----", "").trim();
|
||||||
|
byte[] privateKeyBytes = Base64.getDecoder().decode(privateKeyString);
|
||||||
|
PKCS8EncodedKeySpec encoded = new PKCS8EncodedKeySpec(privateKeyBytes);
|
||||||
|
PrivateKey privateKey = new EdDSAPrivateKey(encoded);
|
||||||
|
|
||||||
|
// Header
|
||||||
|
String headerJson = "{\"alg\": \"EdDSA\", \"kid\": \"C4B98RHV2D\"}";
|
||||||
|
|
||||||
|
// Payload
|
||||||
|
long iat = ZonedDateTime.now(ZoneOffset.UTC).toEpochSecond() - 30;
|
||||||
|
long exp = iat + 900;
|
||||||
|
String payloadJson = "{\"sub\": \"278AVHGU9W\", \"iat\": " + iat + ", \"exp\": " + exp + "}";
|
||||||
|
|
||||||
|
// Base64url header+payload
|
||||||
|
String headerEncoded = Base64.getUrlEncoder().encodeToString(headerJson.getBytes(StandardCharsets.UTF_8));
|
||||||
|
String payloadEncoded = Base64.getUrlEncoder().encodeToString(payloadJson.getBytes(StandardCharsets.UTF_8));
|
||||||
|
String data = headerEncoded + "." + payloadEncoded;
|
||||||
|
|
||||||
|
EdDSAParameterSpec spec = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.ED_25519);
|
||||||
|
|
||||||
|
// Sign
|
||||||
|
final Signature s = new EdDSAEngine(MessageDigest.getInstance(spec.getHashAlgorithm()));
|
||||||
|
s.initSign(privateKey);
|
||||||
|
s.update(data.getBytes(StandardCharsets.UTF_8));
|
||||||
|
byte[] signature = s.sign();
|
||||||
|
|
||||||
|
String signatureString = Base64.getUrlEncoder().encodeToString(signature);
|
||||||
|
|
||||||
|
System.out.println("Signature: \n" + signatureString);
|
||||||
|
|
||||||
|
// Print Token
|
||||||
|
String jwt = data + "." + signatureString;
|
||||||
|
System.out.println("JWT: \n" + jwt);
|
||||||
|
return jwt;
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue