签名
This commit is contained in:
@@ -71,6 +71,25 @@
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger2</artifactId>
|
||||
<version>2.9.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>2.8.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -4,14 +4,17 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.cloud.openfeign.EnableFeignClients;
|
||||
|
||||
/**
|
||||
* @description:
|
||||
* @author: dimengzhe
|
||||
* @date: 2024/12/6
|
||||
**/
|
||||
|
||||
@EnableDiscoveryClient
|
||||
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
|
||||
@EnableFeignClients
|
||||
public class GatewayApiApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -1,14 +1,28 @@
|
||||
package com.yxt.external;
|
||||
|
||||
//import com.yxt.external.feign.protal.organizationappkey.OrganizationAppKey;
|
||||
//import com.yxt.external.feign.protal.organizationappkey.OrganizationAppKeyFeign;
|
||||
import com.yxt.external.feign.protal.organizationappkey.OrganizationAppKey;
|
||||
import com.yxt.external.feign.protal.organizationappkey.OrganizationAppKeyFeign;
|
||||
import com.yxt.external.utils.AppKeyConfig;
|
||||
import com.yxt.external.utils.ResultBean;
|
||||
import com.yxt.external.utils.SignatureUtil;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.time.Instant;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @description:系统参数和签名校验
|
||||
@@ -17,14 +31,25 @@ import java.util.Map;
|
||||
**/
|
||||
//@RestController
|
||||
//@RequestMapping("/signature")
|
||||
@Component
|
||||
//@Component
|
||||
@Service
|
||||
public class Signature {
|
||||
|
||||
@Autowired
|
||||
private AppKeyConfig appKeyConfig;
|
||||
|
||||
OrganizationAppKeyFeign organizationAppKeyFeign;
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public HttpMessageConverters messageConverters(ObjectProvider<HttpMessageConverter<?>> converters) {
|
||||
return new HttpMessageConverters(converters.orderedStream().collect(Collectors.toList()));
|
||||
}
|
||||
public String getSecret(String appKey) {
|
||||
return appKeyConfig.getKeys().get(appKey);
|
||||
ResultBean<OrganizationAppKey> organizationAppKeyResultBean = organizationAppKeyFeign.checkByAppKey(appKey);
|
||||
OrganizationAppKey data = organizationAppKeyResultBean.getData();
|
||||
if(!organizationAppKeyResultBean.getCode().equals("200")){
|
||||
return "";
|
||||
}
|
||||
return data.getSecret();
|
||||
// return "";
|
||||
}
|
||||
|
||||
//验证
|
||||
@@ -70,6 +95,27 @@ public class Signature {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws NoSuchAlgorithmException {
|
||||
String secret="af3489cc";
|
||||
long time = new Date().getTime();
|
||||
String a="_app=63d9351bc400&_t="+time/1000+"&orgSid=1";
|
||||
String b =secret+a+secret;
|
||||
String s = md5(b);
|
||||
System.out.println(s);
|
||||
}
|
||||
/**
|
||||
* MD5加密
|
||||
*
|
||||
* @param content 要计算 MD5 的字符串
|
||||
* @return MD5 值
|
||||
*/
|
||||
private static String md5(String content) throws NoSuchAlgorithmException {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
byte[] bytes = md.digest(content.getBytes());
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (byte b : bytes) {
|
||||
sb.append(String.format("%02x", b));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
4
externalgateway/src/main/java/com/yxt/external/feign/package-info.java
vendored
Normal file
4
externalgateway/src/main/java/com/yxt/external/feign/package-info.java
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* 宇信通监管项目-光伏(山海新能源)项目后台逻辑和接口-接口声明
|
||||
*/
|
||||
package com.yxt.external.feign;
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
package com.yxt.external.feign.protal.organizationappkey;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author wangpengfei
|
||||
* @date 2025/1/21 11:19
|
||||
*/
|
||||
@Data
|
||||
|
||||
public class OrganizationAppKey {
|
||||
private String orgSid;
|
||||
private String appKey;
|
||||
private String secret;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.yxt.external.feign.protal.organizationappkey;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author wangpengfei
|
||||
* @date 2025/1/21 11:19
|
||||
*/
|
||||
@Data
|
||||
public class OrganizationAppKeyDto {
|
||||
private String orgSid;
|
||||
private String appKey;
|
||||
private String secret;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.yxt.external.feign.protal.organizationappkey;
|
||||
|
||||
import com.yxt.external.utils.ResultBean;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
||||
@Api(tags = "组织appkey申请")
|
||||
@FeignClient(
|
||||
contextId = "ss-common-portal-OrganizationAppKey",
|
||||
name = "ss-common-portal",
|
||||
path = "/apiadmin/organizationappkey")
|
||||
public interface OrganizationAppKeyFeign {
|
||||
/**
|
||||
* 申请appkey
|
||||
*
|
||||
* @return 申请appkey
|
||||
*/
|
||||
@ApiOperation("申请appkey")
|
||||
@ResponseBody
|
||||
@PostMapping("/saveAppKey")
|
||||
public ResultBean saveAppKey(@RequestBody OrganizationAppKeyDto dto);
|
||||
@ApiOperation("根据组织查询appeky")
|
||||
@ResponseBody
|
||||
@GetMapping("/initialization/{orgSid}")
|
||||
public ResultBean initialization(@PathVariable("orgSid") String orgSid);
|
||||
@ApiOperation("校验是否存在")
|
||||
@ResponseBody
|
||||
@GetMapping("/checkByAppKey/{appKey}")
|
||||
public ResultBean<OrganizationAppKey> checkByAppKey(@PathVariable("appKey") String appKey);
|
||||
|
||||
}
|
||||
@@ -31,4 +31,4 @@ ignore:
|
||||
|
||||
whitesTwo: #包含所有
|
||||
- /upload/**
|
||||
- /external/apiadmin/supplierinfo/getSupplierCountByOrgSid/**
|
||||
# - /external/apiadmin/supplierinfo/getSupplierCountByOrgSid**
|
||||
|
||||
@@ -31,4 +31,4 @@ ignore:
|
||||
|
||||
whitesTwo: #包含所有
|
||||
- /upload/**
|
||||
- /external/apiadmin/supplierinfo/getSupplierCountByOrgSid/**
|
||||
# - /external/apiadmin/supplierinfo/getSupplierCountByOrgSid**
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user