Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gic-qywx-self
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
haoban3.0
gic-qywx-self
Commits
9061e66d
Commit
9061e66d
authored
Aug 07, 2023
by
徐高华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
自建
parent
14ea63ab
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
17 deletions
+28
-17
HttpClient.java
src/main/java/com/gic/qywx/self/HttpClient.java
+23
-12
QywxController.java
src/main/java/com/gic/qywx/self/QywxController.java
+5
-5
No files found.
src/main/java/com/gic/qywx/self/HttpClient.java
View file @
9061e66d
...
@@ -56,19 +56,29 @@ import com.alibaba.fastjson.JSON;
...
@@ -56,19 +56,29 @@ import com.alibaba.fastjson.JSON;
public
class
HttpClient
{
public
class
HttpClient
{
private
static
Logger
logger
=
LogManager
.
getLogger
(
HttpClient
.
class
);
private
static
Logger
logger
=
LogManager
.
getLogger
(
HttpClient
.
class
);
private
static
org
.
apache
.
http
.
client
.
HttpClient
mHttpClient
;
private
static
Map
<
String
,
org
.
apache
.
http
.
client
.
HttpClient
>
map
=
new
HashMap
<>()
;
//private static
public
static
final
int
DEFAULT_MAX_CONNECTIONS
=
1000
;
public
static
final
int
DEFAULT_MAX_CONNECTIONS
=
1000
;
public
static
final
int
DEFAULT_MAX_ROUTE_CONNECTIONS
=
100
;
public
static
final
int
DEFAULT_MAX_ROUTE_CONNECTIONS
=
100
;
public
static
final
int
DEFAULT_SOCKET_TIMEOUT
=
20
*
1000
;
public
static
final
int
DEFAULT_SOCKET_TIMEOUT
=
20
*
1000
;
public
static
final
int
DEFAULT_CONNECT_TIMEOUT
=
30
*
1000
;
public
static
final
int
DEFAULT_CONNECT_TIMEOUT
=
30
*
1000
;
public
static
final
int
DEFAULT_SOCKET_BUFFER_SIZE
=
8192
;
public
static
final
int
DEFAULT_SOCKET_BUFFER_SIZE
=
8192
;
protected
static
org
.
apache
.
http
.
client
.
HttpClient
getHttpClient
()
{
protected
static
org
.
apache
.
http
.
client
.
HttpClient
getHttpClient
(
String
ip
)
{
org
.
apache
.
http
.
client
.
HttpClient
mHttpClient
=
map
.
get
(
ip
)
;
logger
.
info
(
"clientSize={}"
,
map
.
size
());
if
(
null
!=
mHttpClient
)
{
return
mHttpClient
;
}
/**
/**
* old version
* old version
* **/
* **/
if
(
null
==
mHttpClient
)
{
if
(
null
==
mHttpClient
)
{
synchronized
(
HttpClient
.
class
)
{
synchronized
(
HttpClient
.
class
)
{
mHttpClient
=
map
.
get
(
ip
)
;
if
(
null
!=
mHttpClient
)
{
return
mHttpClient
;
}
if
(
null
==
mHttpClient
)
{
if
(
null
==
mHttpClient
)
{
HttpParams
params
=
new
BasicHttpParams
();
HttpParams
params
=
new
BasicHttpParams
();
HttpProtocolParams
.
setVersion
(
params
,
HttpVersion
.
HTTP_1_1
);
HttpProtocolParams
.
setVersion
(
params
,
HttpVersion
.
HTTP_1_1
);
...
@@ -92,22 +102,23 @@ public class HttpClient {
...
@@ -92,22 +102,23 @@ public class HttpClient {
ClientConnectionManager
conMgr
=
new
ThreadSafeClientConnManager
(
params
,
schReg
);
ClientConnectionManager
conMgr
=
new
ThreadSafeClientConnManager
(
params
,
schReg
);
mHttpClient
=
new
DefaultHttpClient
(
conMgr
,
params
);
mHttpClient
=
new
DefaultHttpClient
(
conMgr
,
params
);
map
.
put
(
ip
,
mHttpClient
)
;
}
}
}
}
}
}
return
mHttpClient
;
return
mHttpClient
;
}
}
public
static
Map
<
String
,
Object
>
getWinxinResByJson
(
String
url
,
String
jsonStr
,
byte
[]
b
)
{
public
static
Map
<
String
,
Object
>
getWinxinResByJson
(
String
url
,
String
jsonStr
,
byte
[]
b
,
String
ip
)
{
return
getWinxinResByJson
(
url
,
jsonStr
,
null
,
b
);
return
getWinxinResByJson
(
url
,
jsonStr
,
null
,
b
,
ip
);
}
}
p
ublic
static
Map
<
String
,
Object
>
getWinxinResByJson
(
String
url
,
String
jsonStr
,
Map
<
String
,
String
>
header
,
byte
[]
b
)
{
p
rivate
static
Map
<
String
,
Object
>
getWinxinResByJson
(
String
url
,
String
jsonStr
,
Map
<
String
,
String
>
header
,
byte
[]
b
,
String
ip
)
{
long
begin
=
new
Date
().
getTime
();
long
begin
=
new
Date
().
getTime
();
String
resInfo
=
null
;
String
resInfo
=
null
;
Map
<
String
,
Object
>
weixinMap
=
new
HashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
weixinMap
=
new
HashMap
<
String
,
Object
>();
org
.
apache
.
http
.
client
.
HttpClient
client
=
getHttpClient
();
org
.
apache
.
http
.
client
.
HttpClient
client
=
getHttpClient
(
ip
);
setIp
(
client
,
b
)
;
setIp
(
client
,
b
)
;
HttpPost
post
=
new
HttpPost
(
url
);
HttpPost
post
=
new
HttpPost
(
url
);
StringBuilder
builder
=
new
StringBuilder
();
StringBuilder
builder
=
new
StringBuilder
();
...
@@ -143,7 +154,7 @@ public class HttpClient {
...
@@ -143,7 +154,7 @@ public class HttpClient {
return
weixinMap
;
return
weixinMap
;
}
}
public
static
Map
<
String
,
Object
>
getWinxinResByFile
(
String
url
,
Map
<
String
,
ContentBody
>
map
,
byte
[]
b
)
{
public
static
Map
<
String
,
Object
>
getWinxinResByFile
(
String
url
,
Map
<
String
,
ContentBody
>
map
,
byte
[]
b
,
String
ip
)
{
long
begin
=
new
Date
().
getTime
();
long
begin
=
new
Date
().
getTime
();
String
entityStr
=
null
;
String
entityStr
=
null
;
...
@@ -155,7 +166,7 @@ public class HttpClient {
...
@@ -155,7 +166,7 @@ public class HttpClient {
}
}
Map
<
String
,
Object
>
obj
=
null
;
Map
<
String
,
Object
>
obj
=
null
;
org
.
apache
.
http
.
client
.
HttpClient
client
=
getHttpClient
();
org
.
apache
.
http
.
client
.
HttpClient
client
=
getHttpClient
(
ip
);
setIp
(
client
,
b
)
;
setIp
(
client
,
b
)
;
HttpPost
post
=
new
HttpPost
(
url
);
HttpPost
post
=
new
HttpPost
(
url
);
StringBuilder
builder
=
new
StringBuilder
();
StringBuilder
builder
=
new
StringBuilder
();
...
@@ -177,9 +188,9 @@ public class HttpClient {
...
@@ -177,9 +188,9 @@ public class HttpClient {
return
obj
;
return
obj
;
}
}
p
ublic
static
Map
<
String
,
Object
>
getHttpByGet
(
String
url
,
String
userName
,
String
password
,
byte
[]
b
)
{
p
rivate
static
Map
<
String
,
Object
>
getHttpByGet
(
String
url
,
String
userName
,
String
password
,
byte
[]
b
,
String
ip
)
{
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
org
.
apache
.
http
.
client
.
HttpClient
client
=
getHttpClient
();
org
.
apache
.
http
.
client
.
HttpClient
client
=
getHttpClient
(
ip
);
setIp
(
client
,
b
)
;
setIp
(
client
,
b
)
;
if
(
userName
!=
null
&&
password
!=
null
)
{
if
(
userName
!=
null
&&
password
!=
null
)
{
CredentialsProvider
credsProvider
=
new
BasicCredentialsProvider
();
CredentialsProvider
credsProvider
=
new
BasicCredentialsProvider
();
...
@@ -210,8 +221,8 @@ public class HttpClient {
...
@@ -210,8 +221,8 @@ public class HttpClient {
}
}
public
static
Map
<
String
,
Object
>
getHttpByGet
(
String
url
,
byte
[]
b
)
{
public
static
Map
<
String
,
Object
>
getHttpByGet
(
String
url
,
byte
[]
b
,
String
ip
)
{
return
getHttpByGet
(
url
,
null
,
null
,
b
);
return
getHttpByGet
(
url
,
null
,
null
,
b
,
ip
);
}
}
private
static
Map
<
String
,
Object
>
doResponse
(
HttpResponse
response
)
{
private
static
Map
<
String
,
Object
>
doResponse
(
HttpResponse
response
)
{
...
...
src/main/java/com/gic/qywx/self/QywxController.java
View file @
9061e66d
...
@@ -29,7 +29,7 @@ public class QywxController {
...
@@ -29,7 +29,7 @@ public class QywxController {
public
Object
selfPost
(
HttpServletRequest
request
,
String
url
,
String
json
,
String
ip
)
{
public
Object
selfPost
(
HttpServletRequest
request
,
String
url
,
String
json
,
String
ip
)
{
String
traceid
=
request
.
getParameter
(
"tranceid"
)
;
String
traceid
=
request
.
getParameter
(
"tranceid"
)
;
logger
.
info
(
"自建post,url={},json={},{},{}"
,
url
,
json
,
traceid
,
ip
);
logger
.
info
(
"自建post,url={},json={},{},{}"
,
url
,
json
,
traceid
,
ip
);
Map
<
String
,
Object
>
map
=
HttpClient
.
getWinxinResByJson
(
url
,
json
,
getIp
(
ip
));
Map
<
String
,
Object
>
map
=
HttpClient
.
getWinxinResByJson
(
url
,
json
,
getIp
(
ip
)
,
ip
);
return
map
;
return
map
;
}
}
...
@@ -37,7 +37,7 @@ public class QywxController {
...
@@ -37,7 +37,7 @@ public class QywxController {
public
Object
selfPostJson
(
HttpServletRequest
request
,
String
url
,
@RequestBody
String
json
,
String
ip
)
{
public
Object
selfPostJson
(
HttpServletRequest
request
,
String
url
,
@RequestBody
String
json
,
String
ip
)
{
String
traceid
=
request
.
getParameter
(
"tranceid"
)
;
String
traceid
=
request
.
getParameter
(
"tranceid"
)
;
logger
.
info
(
"自建post json,url={},json={},{},{}"
,
url
,
json
,
traceid
,
ip
);
logger
.
info
(
"自建post json,url={},json={},{},{}"
,
url
,
json
,
traceid
,
ip
);
Map
<
String
,
Object
>
map
=
HttpClient
.
getWinxinResByJson
(
url
,
json
,
getIp
(
ip
));
Map
<
String
,
Object
>
map
=
HttpClient
.
getWinxinResByJson
(
url
,
json
,
getIp
(
ip
)
,
ip
);
return
map
;
return
map
;
}
}
...
@@ -45,7 +45,7 @@ public class QywxController {
...
@@ -45,7 +45,7 @@ public class QywxController {
public
Object
selfGet
(
HttpServletRequest
request
,
String
url
,
String
ip
)
{
public
Object
selfGet
(
HttpServletRequest
request
,
String
url
,
String
ip
)
{
String
traceid
=
request
.
getParameter
(
"tranceid"
)
;
String
traceid
=
request
.
getParameter
(
"tranceid"
)
;
logger
.
info
(
"自建get,url={},{},{}"
,
url
,
traceid
,
ip
);
logger
.
info
(
"自建get,url={},{},{}"
,
url
,
traceid
,
ip
);
Map
<
String
,
Object
>
map
=
HttpClient
.
getHttpByGet
(
url
,
getIp
(
ip
));
Map
<
String
,
Object
>
map
=
HttpClient
.
getHttpByGet
(
url
,
getIp
(
ip
)
,
ip
);
return
map
;
return
map
;
}
}
...
@@ -56,7 +56,7 @@ public class QywxController {
...
@@ -56,7 +56,7 @@ public class QywxController {
byte
[]
data
=
CommonUtil
.
getFileByte
(
fileUrl
);
byte
[]
data
=
CommonUtil
.
getFileByte
(
fileUrl
);
Map
<
String
,
ContentBody
>
paramsMap
=
new
HashMap
<
String
,
ContentBody
>();
Map
<
String
,
ContentBody
>
paramsMap
=
new
HashMap
<
String
,
ContentBody
>();
paramsMap
.
put
(
"media"
,
new
ByteArrayBody
(
data
,
ContentType
.
DEFAULT_BINARY
,
fileName
));
paramsMap
.
put
(
"media"
,
new
ByteArrayBody
(
data
,
ContentType
.
DEFAULT_BINARY
,
fileName
));
Map
<
String
,
Object
>
map
=
HttpClient
.
getWinxinResByFile
(
url
,
paramsMap
,
getIp
(
ip
));
Map
<
String
,
Object
>
map
=
HttpClient
.
getWinxinResByFile
(
url
,
paramsMap
,
getIp
(
ip
)
,
ip
);
logger
.
info
(
"自建upload end={}"
,
traceid
);
logger
.
info
(
"自建upload end={}"
,
traceid
);
return
map
;
return
map
;
}
}
...
@@ -71,7 +71,7 @@ public class QywxController {
...
@@ -71,7 +71,7 @@ public class QywxController {
byte
[]
data
=
mf
.
getBytes
();
byte
[]
data
=
mf
.
getBytes
();
Map
<
String
,
ContentBody
>
paramsMap
=
new
HashMap
<
String
,
ContentBody
>();
Map
<
String
,
ContentBody
>
paramsMap
=
new
HashMap
<
String
,
ContentBody
>();
paramsMap
.
put
(
"media"
,
new
ByteArrayBody
(
data
,
ContentType
.
DEFAULT_BINARY
,
fileName
));
paramsMap
.
put
(
"media"
,
new
ByteArrayBody
(
data
,
ContentType
.
DEFAULT_BINARY
,
fileName
));
Map
<
String
,
Object
>
map
=
HttpClient
.
getWinxinResByFile
(
url
,
paramsMap
,
getIp
(
ip
));
Map
<
String
,
Object
>
map
=
HttpClient
.
getWinxinResByFile
(
url
,
paramsMap
,
getIp
(
ip
)
,
ip
);
logger
.
info
(
"自建upload-data end={}"
,
traceid
);
logger
.
info
(
"自建upload-data end={}"
,
traceid
);
return
map
;
return
map
;
}
}
...
...
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