Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
loginservice
Overview
Overview
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
lanmw
loginservice
Commits
2ca98103
Commit
2ca98103
authored
Jan 29, 2021
by
chenzx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
教育局单点登陆
parent
35121208
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
221 additions
and
60 deletions
+221
-60
pom.xml
pom.xml
+12
-0
SecurityConfig.java
src/main/java/com/keymobile/proxy/conf/SecurityConfig.java
+56
-58
HttpClientUtil.java
src/main/java/com/keymobile/proxy/util/HttpClientUtil.java
+147
-0
application-test.yml
src/main/resources/application-test.yml
+6
-2
No files found.
pom.xml
View file @
2ca98103
...
...
@@ -98,6 +98,18 @@
<artifactId>
fastjson
</artifactId>
<version>
1.2.73
</version>
</dependency>
<!--json-lib -->
<dependency>
<groupId>
net.sf.json-lib
</groupId>
<artifactId>
json-lib
</artifactId>
<version>
2.4
</version>
<classifier>
jdk15
</classifier>
</dependency>
<dependency>
<groupId>
net.sf.flexjson
</groupId>
<artifactId>
flexjson
</artifactId>
<version>
3.3
</version>
</dependency>
</dependencies>
<dependencyManagement>
...
...
src/main/java/com/keymobile/proxy/conf/SecurityConfig.java
View file @
2ca98103
This diff is collapsed.
Click to expand it.
src/main/java/com/keymobile/proxy/util/HttpClientUtil.java
0 → 100644
View file @
2ca98103
package
com
.
keymobile
.
proxy
.
util
;
import
org.apache.http.NameValuePair
;
import
org.apache.http.client.entity.UrlEncodedFormEntity
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.client.utils.URIBuilder
;
import
org.apache.http.entity.ContentType
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.message.BasicNameValuePair
;
import
org.apache.http.util.EntityUtils
;
import
java.io.IOException
;
import
java.net.URI
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Map
;
/**
* @author zhouzc@ewhale.com
* @version 1.0Z
* @description
* @data Created in 2018/11/17 0017 11:00
*/
public
class
HttpClientUtil
{
public
static
String
doGet
(
String
url
,
Map
<
String
,
String
>
param
)
{
// 创建Httpclient对象
CloseableHttpClient
httpclient
=
HttpClients
.
createDefault
();
String
resultString
=
""
;
CloseableHttpResponse
response
=
null
;
try
{
// 创建uri
URIBuilder
builder
=
new
URIBuilder
(
url
);
if
(
param
!=
null
)
{
for
(
String
key
:
param
.
keySet
())
{
builder
.
addParameter
(
key
,
param
.
get
(
key
));
}
}
URI
uri
=
builder
.
build
();
// 创建http GET请求
HttpGet
httpGet
=
new
HttpGet
(
uri
);
// 执行请求
response
=
httpclient
.
execute
(
httpGet
);
// 判断返回状态是否为200
if
(
response
.
getStatusLine
().
getStatusCode
()
==
200
)
{
resultString
=
EntityUtils
.
toString
(
response
.
getEntity
(),
"UTF-8"
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
if
(
response
!=
null
)
{
response
.
close
();
}
httpclient
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
return
resultString
;
}
public
static
String
doGet
(
String
url
)
{
return
doGet
(
url
,
null
);
}
public
static
String
doPost
(
String
url
,
Map
<
String
,
String
>
param
)
{
// 创建Httpclient对象
CloseableHttpClient
httpClient
=
HttpClients
.
createDefault
();
CloseableHttpResponse
response
=
null
;
String
resultString
=
""
;
try
{
// 创建Http Post请求
HttpPost
httpPost
=
new
HttpPost
(
url
);
// 创建参数列表
if
(
param
!=
null
)
{
List
<
NameValuePair
>
paramList
=
new
ArrayList
<>();
for
(
String
key
:
param
.
keySet
())
{
paramList
.
add
(
new
BasicNameValuePair
(
key
,
param
.
get
(
key
)));
}
// 模拟表单
UrlEncodedFormEntity
entity
=
new
UrlEncodedFormEntity
(
paramList
);
httpPost
.
setEntity
(
entity
);
}
// 执行http请求
response
=
httpClient
.
execute
(
httpPost
);
resultString
=
EntityUtils
.
toString
(
response
.
getEntity
(),
"utf-8"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
response
.
close
();
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
}
return
resultString
;
}
public
static
String
doPost
(
String
url
)
{
return
doPost
(
url
,
null
);
}
public
static
String
doPostJson
(
String
url
,
String
json
)
{
// 创建Httpclient对象
CloseableHttpClient
httpClient
=
HttpClients
.
createDefault
();
CloseableHttpResponse
response
=
null
;
String
resultString
=
""
;
try
{
// 创建Http Post请求
HttpPost
httpPost
=
new
HttpPost
(
url
);
// 创建请求内容
StringEntity
entity
=
new
StringEntity
(
json
,
ContentType
.
APPLICATION_JSON
);
httpPost
.
setEntity
(
entity
);
// 执行http请求
response
=
httpClient
.
execute
(
httpPost
);
resultString
=
EntityUtils
.
toString
(
response
.
getEntity
(),
"utf-8"
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
response
.
close
();
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
}
return
resultString
;
}
public
static
void
main
(
String
[]
args
)
{
String
data
=
HttpClientUtil
.
doPost
(
"https://openapi.bestsign.cn:443/openapi/v2/contract/download/?developerId=1865813619904610913&rtick=15361564521240&signType=token&sign=eyJkZXZlbG9wZXJJZCI6IjE4NjU4MTM2MTk5MDQ2MTA5MTMiLCJjYXRhbG9nSWQiOiIiLCJjb250cmFjdElkIjoiMTUzNjE1NjQ1MDAxMDAwMDE0IiwiZXhwaXJlQXQiOiIxNjkzODM2NDUyIiwiYWNjb3VudCI6IjEzOTc2ODI5MDA2In0uMTUzNjE1NjQ1MjEyNDk5ODk_.fff1696b916f709a7c812a4aa41a9a27&contractId=153615645001000014&expireTime=1693836452"
);
if
(
data
.
equals
(
"Can't find any router. (requestPath: /openapi/v2/contract/download/)"
)){
System
.
out
.
println
(
"11111111111111111"
);
}
System
.
out
.
println
(
"data = "
+
data
);
}
}
src/main/resources/application-test.yml
View file @
2ca98103
...
...
@@ -58,4 +58,8 @@ security:
authPwd
:
pwd
sso
:
url
:
http://localhost:8764/token
\ No newline at end of file
url
:
http://localhost:8764/token
client
:
id
:
xxx
secret
:
\ No newline at end of file
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