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
e70fe2d5
Commit
e70fe2d5
authored
Mar 04, 2024
by
caotao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增首航请求工具类
parent
25bda25c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
54 deletions
+83
-54
GoodWeRequestUtil.java
...eejoin/amos/api/householdapi/Utils/GoodWeRequestUtil.java
+0
-9
SofarRequestUtil.java
...yeejoin/amos/api/householdapi/Utils/SofarRequestUtil.java
+39
-45
SoFarConstant.java
...yeejoin/amos/api/householdapi/constant/SoFarConstant.java
+44
-0
No files found.
amos-boot-data/amos-boot-data-housepvapi/src/main/java/com/yeejoin/amos/api/householdapi/Utils/GoodWeRequestUtil.java
View file @
e70fe2d5
package
com
.
yeejoin
.
amos
.
api
.
householdapi
.
Utils
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.http.Header
;
import
cn.hutool.http.HttpUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.yeejoin.amos.api.householdapi.constant.GoLangConstant
;
import
com.yeejoin.amos.api.householdapi.constant.GoodWeConstant
;
import
com.yeejoin.amos.api.householdapi.face.orm.houseapi.entity.houseapi.HouseholdPvProducerInfo
;
import
com.yeejoin.amos.api.householdapi.face.orm.mapper.tdengine.GolangStationMapper
;
import
com.yeejoin.amos.api.householdapi.face.service.impl.HouseholdPvProducerInfoServiceImpl
;
import
com.yeejoin.amos.openapi.enums.PVProducerInfoEnum
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.typroject.tyboot.component.cache.Redis
;
import
java.util.*
;
@Component
public
class
GoodWeRequestUtil
{
private
final
String
redisKey
=
"GOODWE_REQUEST_TOKEN"
;
...
...
amos-boot-data/amos-boot-data-housepvapi/src/main/java/com/yeejoin/amos/api/householdapi/Utils/SofarRequestUtil.java
View file @
e70fe2d5
...
...
@@ -2,9 +2,12 @@ package com.yeejoin.amos.api.householdapi.Utils;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.http.HttpUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.yeejoin.amos.api.householdapi.constant.GoLangConstant
;
import
com.yeejoin.amos.api.householdapi.constant.GoodWeConstant
;
import
com.yeejoin.amos.api.householdapi.constant.SoFarConstant
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.ObjectUtils
;
...
...
@@ -16,23 +19,39 @@ import java.util.List;
public
class
SofarRequestUtil
{
private
final
String
redisKey
=
"SOFAR_REQUEST_TOKEN"
;
@Autowired
private
RedisUtils
redisUtils
;
/**
* @return HashMap<String, Object> 发送请求前的准备 准备header信息
* @deprecated 根据厂商编码获取厂商的hearer
*/
public
HashMap
<
String
,
Object
>
getHeaderOfGolang
()
{
HashMap
<
String
,
Object
>
hashMap
=
new
HashMap
<>();
HashMap
<
String
,
String
>
hashMaphead
=
new
HashMap
<>();
String
url
=
GoLangConstant
.
baseurl
+
GoLangConstant
.
tokenurl
;
hashMap
.
put
(
"apiurl"
,
GoLangConstant
.
baseurl
);
hashMaphead
.
put
(
"Content-type"
,
"application/json;charset=UTF-8"
);
hashMaphead
.
put
(
"Authorization"
,
"API "
+
GoLangConstant
.
prodcerappid
);
hashMaphead
.
put
(
"Content-MD5"
,
null
);
hashMaphead
.
put
(
"Date"
,
GoLangHeaderUtils
.
getGMTTime
());
hashMap
.
put
(
"header"
,
hashMaphead
);
hashMap
.
put
(
"appsecret"
,
GoLangConstant
.
prodcerappsecret
);
return
hashMap
;
public
HashMap
<
String
,
String
>
getHeaderOfSofar
()
{
HashMap
<
String
,
String
>
requestHeader
=
new
HashMap
<>();
if
(
ObjectUtil
.
isNotEmpty
(
redisUtils
.
get
(
redisKey
))){
requestHeader
.
put
(
"token"
,
redisUtils
.
get
(
redisKey
).
toString
());
return
requestHeader
;
}
HashMap
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"accountName"
,
SoFarConstant
.
account
);
map
.
put
(
"appId"
,
SoFarConstant
.
appId
);
map
.
put
(
"appSecret"
,
SoFarConstant
.
appSecret
);
map
.
put
(
"corporationId"
,
SoFarConstant
.
corporationId
);
map
.
put
(
"accountType"
,
2
);
String
body
=
JSON
.
toJSONString
(
map
);
String
url
=
SoFarConstant
.
baseurl
+
SoFarConstant
.
tokenurl
;
String
response
=
HttpUtil
.
createPost
(
url
).
body
(
body
).
execute
().
body
();
JSONObject
jsonObject
=
JSON
.
parseObject
(
response
);
if
(
jsonObject
.
getString
(
"msg"
).
equals
(
"success"
)){
JSONObject
jsonObject1
=
jsonObject
.
getJSONObject
(
"data"
);
String
token
=
jsonObject1
.
getString
(
"token"
);
requestHeader
.
put
(
"authorization"
,
token
);
redisUtils
.
set
(
redisKey
,
token
,
5183900
);
}
return
requestHeader
;
}
/**
...
...
@@ -50,19 +69,15 @@ public class SofarRequestUtil {
String
params
=
""
;
JSONArray
jsonArray
=
null
;
List
<
T
>
result
=
new
ArrayList
<>();
try
{
HashMap
<
String
,
Object
>
producerInfo
=
getHeaderOfGolang
();
String
baseurl
=
(
String
)
producerInfo
.
get
(
"apiurl"
);
HashMap
<
String
,
String
>
headMap
=
(
HashMap
<
String
,
String
>)
producerInfo
.
get
(
"header"
);
String
orginalAuthorization
=
headMap
.
get
(
"Authorization"
)
+
":"
;
String
url
=
baseurl
+
apiurl
;
String
appsecret
=
(
String
)
producerInfo
.
get
(
"appsecret"
);
JLYHeaderMapHandler
(
params
,
headMap
,
orginalAuthorization
,
appsecret
,
apiurl
);
HashMap
<
String
,
String
>
headMap
=
getHeaderOfSofar
();
String
url
=
GoodWeConstant
.
baseurl
+
apiurl
;
respone
=
sendRequest
(
requestMethod
,
url
,
requestParmInfo
,
headMap
);
jsonArray
=
handlerResponseByResultResolverule
(
ResultResolveRule
,
respone
);
if
(!
ObjectUtils
.
isEmpty
(
jsonArray
))
{
result
=
JSONArray
.
parseArray
(
jsonArray
.
toJSONString
(),
tClass
);
}
//
jsonArray = handlerResponseByResultResolverule(ResultResolveRule, respone);
//
if (!ObjectUtils.isEmpty(jsonArray)) {
//
result = JSONArray.parseArray(jsonArray.toJSONString(), tClass);
//
}
}
catch
(
Exception
exception
)
{
return
result
;
}
...
...
@@ -112,27 +127,6 @@ public class SofarRequestUtil {
return
respone
;
}
/***
*
* @param params 参数字符窜
* @param headMap header头
* @param orginalAuthorization 原始的orginalAuthorization
* @param appsecret appsecret
* @desc 锦浪云请求参数及head头处理
*/
public
void
JLYHeaderMapHandler
(
String
params
,
HashMap
<
String
,
String
>
headMap
,
String
orginalAuthorization
,
String
appsecret
,
String
apiurl
)
{
String
contentMD5
=
GoLangHeaderUtils
.
getDigest
(
params
);
headMap
.
put
(
"Date"
,
GoLangHeaderUtils
.
getGMTTime
());
String
param
=
"POST"
+
"\n"
+
contentMD5
+
"\n"
+
"application/json"
+
"\n"
+
headMap
.
get
(
"Date"
)
+
"\n"
+
apiurl
;
String
sign
=
""
;
try
{
sign
=
GoLangHeaderUtils
.
HmacSHA1Encrypt
(
param
,
appsecret
);
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
headMap
.
put
(
"Content-MD5"
,
contentMD5
);
headMap
.
put
(
"Authorization"
,
orginalAuthorization
+
sign
);
}
/**
* @param pageSizeResovle
...
...
amos-boot-data/amos-boot-data-housepvapi/src/main/java/com/yeejoin/amos/api/householdapi/constant/SoFarConstant.java
View file @
e70fe2d5
package
com
.
yeejoin
.
amos
.
api
.
householdapi
.
constant
;
import
java.time.format.DateTimeFormatter
;
import
java.util.HashMap
;
/**
* 首航常量
*/
public
class
SoFarConstant
{
public
static
final
HashMap
<
String
,
String
>
stationStaus
=
new
HashMap
<
String
,
String
>()
{
{
put
(
"-1"
,
"离线"
);
put
(
"0"
,
"待机"
);
put
(
"1"
,
"正常"
);
put
(
"2"
,
"停机"
);
}
};
public
static
String
baseurl
=
"https://openapi.sofarsolarmonitor.com"
;
public
static
String
appId
=
"447430219192733696"
;
public
static
String
appSecret
=
"5881ee8c062817016a2b34425c45937d"
;
public
static
String
corporationId
=
"447430928264990720"
;
public
static
String
account
=
"18120415291"
;
public
static
String
password
=
"ZXNK123456.."
;
public
static
String
tokenurl
=
"/account/auth/createToken"
;
public
static
String
stationListUrl
=
"/api/OpenApi/GetUserPowerStation"
;
public
static
String
stationListStatusUrl
=
"/api/OpenApi/QueryPowerStationMonitor"
;
public
static
String
stationDetailUrl
=
"/api/OpenApi/GetPowerStationMonitorDetail"
;
public
static
String
collectorListUrl
=
"/v1/api/collectorList"
;
public
static
String
collectorDetailUrl
=
"/v1/api/collectorDetail"
;
public
static
String
inverterListUrl
=
"/v1/api/inverterList"
;
public
static
String
inverterDetailUrl
=
"/v1/api/inverterDetail"
;
public
static
String
alarmListUrl
=
"/v1/api/alarmList"
;
public
static
String
stationDayGenUrl
=
"/v1/api/stationDayEnergyList"
;
public
static
String
stationMonthEnergyList
=
"/v1/api/stationDayEnergyList"
;
public
static
String
stationYearEnergyList
=
"/v1/api/stationDayEnergyList"
;
public
static
String
inverterDayURL
=
"/v1/api/inverterDay"
;
public
static
String
inverterMonthURL
=
"/v1/api/inverterMonth"
;
public
static
String
inverterYearURL
=
"/v1/api/inverterYear"
;
public
static
String
resovleRule_data_page_records
=
"data,page,records"
;
public
static
String
resovleRule_data_list
=
"data,list"
;
public
static
String
resovleRule_data_records
=
"data,records"
;
public
static
String
resovleRule_data
=
"data"
;
public
static
String
requestPost
=
"POST"
;
public
static
String
requestGet
=
"GET"
;
public
static
String
datePattern
=
"yyyy-MM-dd HH:mm:ss.SSS"
;
public
static
DateTimeFormatter
formatter
=
DateTimeFormatter
.
ofPattern
(
datePattern
);
public
static
Double
kwhToMwh
=
0.0001
;
public
static
Double
mwhTokwh
=
1000.0
;
}
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