Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
项目统一框架
amos-boot-biz
Commits
58685b41
Commit
58685b41
authored
Jun 16, 2023
by
caotao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增锦浪云数据采集公共处理
parent
35458a49
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
1 deletion
+102
-1
GoLangHeaderUtils.java
...eejoin/amos/api/householdapi/Utils/GoLangHeaderUtils.java
+81
-0
HouseholdPvUtils.java
...yeejoin/amos/api/householdapi/Utils/HouseholdPvUtils.java
+21
-1
No files found.
amos-boot-data/amos-boot-data-accessapi/src/main/java/com/yeejoin/amos/api/householdapi/Utils/GoLangHeaderUtils.java
0 → 100644
View file @
58685b41
package
com
.
yeejoin
.
amos
.
api
.
householdapi
.
Utils
;
import
org.apache.commons.codec.binary.Base64
;
import
javax.crypto.Mac
;
import
javax.crypto.SecretKey
;
import
javax.crypto.spec.SecretKeySpec
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
//锦浪云 header处理类
public
class
GoLangHeaderUtils
{
// public static void main(String[] args) {
// try {
// String key = "";
// String keySecret = "";
// Map<String,Object> map = new HashMap();
// map.put("pageNo",1);
// map.put("pageSize",10);
// String body = JSON.toJSONString(map);
// String ContentMd5 = getDigest(body);
// String Date = getGMTTime();
// String path = "/v1/api/userStationList";
// String param = "POST" + "\n" + ContentMd5 + "\n" + "application/json" + "\n" + Date + "\n" + path;
// String sign = HmacSHA1Encrypt(param, keySecret);
// String url = "url" + path ;
// OkHttpClient client = new OkHttpClient();
// MediaType xmlType = MediaType.parse("application/json;charset=UTF-8");
// okhttp3.RequestBody requestBody = okhttp3.RequestBody.create(xmlType,body);
// okhttp3.Request request = new okhttp3.Request.Builder()
// .url(url)
// .addHeader("Content-type", "application/json;charset=UTF-8")
// .addHeader("Authorization","API "+key+":"+sign)
// .addHeader("Content-MD5",ContentMd5)
// .addHeader("Date",Date)
// .post(requestBody)
// .build();
// Response response = client.newCall(request).execute();
// String string = response.body().string();
// System.out.println(string);
//
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
public
static
String
HmacSHA1Encrypt
(
String
encryptText
,
String
KeySecret
)
throws
Exception
{
byte
[]
data
=
KeySecret
.
getBytes
(
"UTF-8"
);
SecretKey
secretKey
=
new
SecretKeySpec
(
data
,
"HmacSHA1"
);
Mac
mac
=
Mac
.
getInstance
(
"HmacSHA1"
);
mac
.
init
(
secretKey
);
byte
[]
text
=
encryptText
.
getBytes
(
"UTF-8"
);
byte
[]
result
=
mac
.
doFinal
(
text
);
return
Base64
.
encodeBase64String
(
result
);
}
public
static
String
getGMTTime
(){
Calendar
cd
=
Calendar
.
getInstance
();
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"EEE, d MMM yyyy HH:mm:ss 'GMT'"
,
Locale
.
US
);
sdf
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"GMT"
));
String
str
=
sdf
.
format
(
cd
.
getTime
());
return
str
;
}
//获取header中的 Content-MD5
public
static
String
getDigest
(
String
test
)
{
String
result
=
""
;
try
{
MessageDigest
md
=
MessageDigest
.
getInstance
(
"MD5"
);
md
.
update
(
test
.
getBytes
());
byte
[]
b
=
md
.
digest
();
result
=
java
.
util
.
Base64
.
getEncoder
().
encodeToString
(
b
);
}
catch
(
NoSuchAlgorithmException
e
)
{
e
.
printStackTrace
();
}
return
result
;
}
}
amos-boot-data/amos-boot-data-accessapi/src/main/java/com/yeejoin/amos/api/householdapi/Utils/HouseholdPvUtils.java
View file @
58685b41
...
...
@@ -14,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
java.util.Date
;
import
java.util.HashMap
;
@Component
...
...
@@ -54,6 +55,13 @@ public class HouseholdPvUtils {
JSONObject
jsonObject
=
JSON
.
parseObject
(
response
);
hashMaphead
.
put
(
"Authorization"
,
(
String
)
jsonObject
.
get
(
"data"
));
hashMap
.
put
(
"header"
,
hashMaphead
);
}
else
if
(
PVProducerInfoEnum
.
JLY
.
getCode
().
equals
(
code
)){
hashMaphead
.
put
(
"Content-type"
,
"application/json;charset=UTF-8"
);
hashMaphead
.
put
(
"Authorization"
,
"API "
+
householdPvProducerInfo
.
getProdcerAppid
());
hashMaphead
.
put
(
"Content-MD5"
,
null
);
hashMaphead
.
put
(
"Date"
,
GoLangHeaderUtils
.
getGMTTime
());
hashMap
.
put
(
"header"
,
hashMaphead
);
hashMap
.
put
(
"appsecret"
,
householdPvProducerInfo
.
getProdcerAppsecret
());
}
return
hashMap
;
}
...
...
@@ -61,9 +69,21 @@ public class HouseholdPvUtils {
HouseholdPvApiDto
householdPvApiDto
=
this
.
householdPvApiServiceImpl
.
queryBySeq
(
seq
);
HashMap
<
String
,
Object
>
producerInfo
=
this
.
getHeaderByProducerCode
(
householdPvApiDto
.
getProducerId
());
HashMap
<
String
,
String
>
headMap
=
(
HashMap
<
String
,
String
>)
producerInfo
.
get
(
"header"
);
if
(
PVProducerInfoEnum
.
JLY
.
getCode
().
equals
(
householdPvApiDto
.
getProducerId
())){
String
contentMD5
=
GoLangHeaderUtils
.
getDigest
(
householdPvApiDto
.
getParamInfo
());
String
param
=
"POST"
+
"\n"
+
contentMD5
+
"\n"
+
"application/json"
+
"\n"
+
headMap
.
get
(
"Date"
)+
"\n"
+
householdPvApiDto
.
getApiUrl
();
String
sign
=
""
;
try
{
sign
=
GoLangHeaderUtils
.
HmacSHA1Encrypt
(
param
,
(
String
)
producerInfo
.
get
(
"appsecret"
));
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
headMap
.
put
(
"Content-MD5"
,
contentMD5
);
headMap
.
put
(
"Authorization"
,
headMap
.
get
(
"Authorization"
)+
":"
+
sign
);
}
String
respone
=
""
;
if
(
householdPvApiDto
.
getRequestMethod
().
equals
(
"POST"
)){
respone
=
HttpUtil
.
createPost
(
producerInfo
.
get
(
"apiurl"
)+
householdPvApiDto
.
getApiUrl
()).
headerMap
(
headMap
,
tru
e
).
respone
=
HttpUtil
.
createPost
(
producerInfo
.
get
(
"apiurl"
)+
householdPvApiDto
.
getApiUrl
()).
headerMap
(
headMap
,
fals
e
).
body
(
householdPvApiDto
.
getParamInfo
()).
execute
().
body
();
}
if
(
householdPvApiDto
.
getRequestMethod
().
equals
(
"GET"
)){
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment