Commit 27b4ff04 authored by yujicen's avatar yujicen

添加工具类

parent e1ffc866
...@@ -188,3 +188,8 @@ xss: ...@@ -188,3 +188,8 @@ xss:
excludes: /system/notice excludes: /system/notice
# 匹配链接 # 匹配链接
urlPatterns: /system/*,/monitor/*,/tool/* urlPatterns: /system/*,/monitor/*,/tool/*
dsk-acc:
open:
accessKeyId: 5dat74XI0CMWgoskYW32VkpVCD0MXsC0
accessSecret: 1a5G4svf71KQHCg13FU3NyoJUrTp8cES
...@@ -17,6 +17,17 @@ ...@@ -17,6 +17,17 @@
<dependencies> <dependencies>
<dependency>
<groupId>com.gitee.dasikong</groupId>
<artifactId>dsk-acc-open-sdk-java</artifactId>
<version>1.0.4</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.13</version>
</dependency>
<!-- Spring框架基本的核心工具 --> <!-- Spring框架基本的核心工具 -->
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework</groupId>
...@@ -125,6 +136,10 @@ ...@@ -125,6 +136,10 @@
<groupId>javax.servlet</groupId> <groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId> <artifactId>javax.servlet-api</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies> </dependencies>
......
package com.dsk.common.utils.http;
import com.dsk.acc.openapi.api.AccClient;
import com.dsk.acc.openapi.client.Config;
import com.dsk.acc.openapi.client.util.CommonUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
/**
* @author lc
* @date 2022/2/18 11:41
*/
@Slf4j
@Component
public class DskAccClientUtil {
private static String accessKeyId;
private static String accessSecret;
/**
* <b>application/json请求</b>
* @param path 请求路径
* @param bodyMap 参数体
* @return
* */
public static Map<String,Object> requestBody(String path, Map<String, Object> bodyMap){
return request(path, bodyMap, "json");
}
/**
* <b>application/x-www-form-urlencoded请求</b>
* @param path 请求路径
* @param bodyMap 参数体
* @return
*/
public static Map<String,Object> requestForm(String path, Map<String, Object> bodyMap){
return request(path, bodyMap, "form");
}
/**
* <b>开放平台统一请求</b>
* @param path 请求路径
* @param bodyMap 参数体
* @param reqBodyType 请求格式
* @return
*/
public static Map<String,Object> request(String path, Map<String, Object> bodyMap, String reqBodyType){
// try {
//测试沙盒版本
// AccClient.init(new Config(accessKeyId, accessSecret).setEndpoint("sandbox.openapi.jiansheku.com"));
//后期线上版本
AccClient.init(new Config(accessKeyId, accessSecret));
Map<String, ?> res = AccClient.request(reqBodyType, path, bodyMap);
if(!res.containsKey("headers") || !res.containsKey("body")) {
throw new RuntimeException(String.format("请求无返回:path=%s",path));
}
Object resBody = res.get("body");
if(resBody == null) {
return null;
}
return CommonUtils.assertAsMap(resBody);
// } catch (Exception e) {
// log.error("大司空开放平台请求异常 request() ",e);
// throw new RuntimeException(String.format("请求异常:path=%s,err=%s",path,e.getMessage()));
// }
}
public String getAccessKeyId() {
return accessKeyId;
}
@Value("${dsk-acc.open.accessKeyId}")
public void setAccessKeyId(String accessKeyId) {
DskAccClientUtil.accessKeyId = accessKeyId;
}
public String getAccessSecret() {
return accessSecret;
}
@Value("${dsk-acc.open.accessSecret}")
public void setAccessSecret(String accessSecret) {
DskAccClientUtil.accessSecret = accessSecret;
}
public static void main(String[] args) {
DskAccClientUtil.accessKeyId="kUN0ZtZg2H4b1e6z6smXlzo7Enta0bKt";
DskAccClientUtil.accessSecret="LXmIIEZ9vVkRAqAKFDlYCavtkfveIDPi";
// Map<String, Object> map =new HashMap<>();
// map.put("companyId",339447);
Map<String, Object> jsonParam = new HashMap<String, Object>();
jsonParam.put("companyName", "重庆大司空信息科技有限公司");
jsonParam.put("creditCode", "91350203MA2YG0RP5A");
// Map<String,Object> res = DskAccClientUtil.requestBody(DskAccClientUtil.HTTPURLMAP.get("涉金融领域非法集资企业"), jsonParam);
// Map<String, Object> result = requestForm("/zh/jsk/enterprise/ownership", map);
// System.out.println(JSONUtil.toJsonStr(res));
// List<CompanyInfo> list = multiCriteriaQuery("浙江恒欣设计集团股份有限公司");
// System.out.println(list);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment