Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
Q
queueForTicket_bl
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
mengmeng
queueForTicket_bl
Commits
6d37d496
Commit
6d37d496
authored
Mar 04, 2021
by
lings
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
浙里办
parent
155ab080
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
1075 additions
and
4 deletions
+1075
-4
pom.xml
hmit-api/pom.xml
+18
-1
ZhelibanAPP.java
hmit-api/src/main/java/io/hmit/config/ZhelibanAPP.java
+30
-0
ZhelibanUtils.java
hmit-api/src/main/java/io/hmit/config/ZhelibanUtils.java
+584
-0
ApiLoginController.java
.../src/main/java/io/hmit/controller/ApiLoginController.java
+73
-1
AppointmentOrderController.java
...es/appointment/controller/AppointmentOrderController.java
+30
-1
YynumberDTO.java
...ain/java/io/hmit/modules/appointment/dto/YynumberDTO.java
+32
-0
AppointmentOrderService.java
.../modules/appointment/service/AppointmentOrderService.java
+2
-0
AppointmentOrderServiceImpl.java
...appointment/service/impl/AppointmentOrderServiceImpl.java
+2
-0
pom.xml
hmit-common/pom.xml
+8
-1
HttpRequestUtil.java
...n/src/main/java/io/hmit/common/utils/HttpRequestUtil.java
+211
-0
MD5.java
hmit-common/src/main/java/io/hmit/common/utils/MD5.java
+61
-0
MyX509TrustManager.java
...rc/main/java/io/hmit/common/utils/MyX509TrustManager.java
+24
-0
No files found.
hmit-api/pom.xml
View file @
6d37d496
...
...
@@ -17,6 +17,23 @@
<artifactId>
hmit-common
</artifactId>
<version>
1.0.0
</version>
</dependency>
<dependency>
<groupId>
com.alibaba
</groupId>
<artifactId>
fastjson
</artifactId>
<version>
1.2.60
</version>
<scope>
compile
</scope>
</dependency>
<dependency>
<groupId>
net.sf.json-lib
</groupId>
<artifactId>
json-lib
</artifactId>
<version>
2.4
</version>
</dependency>
<dependency>
<groupId>
net.sf.json-lib
</groupId>
<artifactId>
json-lib
</artifactId>
<version>
2.4
</version>
<classifier>
jdk15
</classifier>
</dependency>
</dependencies>
<build>
...
...
@@ -52,4 +69,4 @@
</plugins>
</build>
</project>
\ No newline at end of file
</project>
hmit-api/src/main/java/io/hmit/config/ZhelibanAPP.java
0 → 100644
View file @
6d37d496
package
io
.
hmit
.
config
;
public
class
ZhelibanAPP
{
// 获取请求app_secret的地址
public
static
final
String
APP_REQUEST_SECRET_URL
=
"http://10.68.138.194/gateway/app/refreshTokenByKey.htm"
;
public
static
final
String
APP_KEY
=
"6465b05327cc4a41897907bf81382c29"
;
public
static
final
String
APP_SECRET
=
"fe07f9be363c46449ffae97ae2ad2bda"
;
public
static
final
String
SIGN
=
""
;
public
static
final
String
APP_ID
=
"4438763045"
;
public
static
final
String
APP_KEY_T
=
"249f09c69fe38bf51fe73976cbed2ead"
;
public
static
final
String
TOKEN_URL
=
""
;
public
static
final
String
BASE_URL
=
"http://a.com/"
;
public
static
final
String
AUTH_LOGIN_URL
=
BASE_URL
+
""
;
public
static
final
String
PUSH_MESSAGE_SIMPLE
=
BASE_URL
+
""
;
public
static
final
String
GET_USER_INFO_BY_MOBILE
=
BASE_URL
+
""
;
public
static
final
String
COMMIT_DATA
=
BASE_URL
+
""
;
//手机
public
static
final
String
SERVICE_CODE
=
"fhcjrzdpyc"
;
public
static
final
String
SERVICE_PASS
=
"fhcjrzdpycpwd"
;
public
static
final
String
APP_BASE_URL
=
"https://puser.zjzwfw.gov.cn/sso/servlet/simpleauth?method="
;
public
static
final
String
VALIDATION_TICKET
=
"ticketValidation"
;
public
static
final
String
USER_INFO
=
"getUserInfo"
;
}
hmit-api/src/main/java/io/hmit/config/ZhelibanUtils.java
0 → 100644
View file @
6d37d496
package
io
.
hmit
.
config
;
import
io.hmit.common.utils.DateUtils
;
import
net.sf.json.JSONObject
;
import
com.google.gson.*
;
import
com.google.gson.reflect.TypeToken
;
import
io.hmit.common.utils.HttpRequestUtil
;
import
io.hmit.common.utils.MD5
;
import
org.apache.commons.lang3.StringEscapeUtils
;
import
org.slf4j.LoggerFactory
;
import
javax.net.ssl.*
;
import
java.io.*
;
import
java.lang.reflect.Type
;
import
java.net.HttpURLConnection
;
import
java.net.MalformedURLException
;
import
java.net.URL
;
import
java.net.URLEncoder
;
import
java.security.NoSuchAlgorithmException
;
import
java.security.cert.X509Certificate
;
import
java.text.MessageFormat
;
import
java.util.*
;
public
class
ZhelibanUtils
{
private
static
org
.
slf4j
.
Logger
logger
=
LoggerFactory
.
getLogger
(
ZhelibanAPP
.
class
);
private
final
static
HostnameVerifier
DO_NOT_VERIFY
=
new
HostnameVerifier
()
{
@Override
public
boolean
verify
(
String
hostname
,
SSLSession
session
)
{
return
true
;
}
};
private
static
Gson
gson
=
new
GsonBuilder
()
.
registerTypeAdapter
(
new
TypeToken
<
Map
<
String
,
Object
>>()
{
}.
getType
(),
new
JsonDeserializer
<
Map
<
String
,
Object
>>()
{
@Override
public
Map
<
String
,
Object
>
deserialize
(
JsonElement
json
,
Type
typeOfT
,
JsonDeserializationContext
context
)
throws
JsonParseException
{
Map
<
String
,
Object
>
treeMap
=
new
HashMap
<
String
,
Object
>();
JsonObject
jsonObject
=
json
.
getAsJsonObject
();
Set
<
Map
.
Entry
<
String
,
JsonElement
>>
entrySet
=
jsonObject
.
entrySet
();
for
(
Map
.
Entry
<
String
,
JsonElement
>
entry
:
entrySet
)
{
treeMap
.
put
(
entry
.
getKey
(),
entry
.
getValue
());
}
return
treeMap
;
}
}).
create
();
public
static
JSONObject
HttpRequest
(
String
request
,
String
RequestMethod
,
String
output
,
String
type
,
Map
<
String
,
Object
>
headParam
){
@SuppressWarnings
(
"unused"
)
JSONObject
jsonObject
=
null
;
StringBuffer
buffer
=
new
StringBuffer
();
try
{
//建立连接
//trustAllHosts();//HTTPS请求需建立信任链接
URL
url
=
new
URL
(
request
);
HttpsURLConnection
connection
=
(
HttpsURLConnection
)
url
.
openConnection
();
if
(
RequestMethod
.
equals
(
"POST"
))
{
connection
.
setDoOutput
(
true
);
}
connection
.
setDoInput
(
true
);
connection
.
setUseCaches
(
false
);
connection
.
setRequestMethod
(
RequestMethod
);
connection
.
setHostnameVerifier
(
DO_NOT_VERIFY
);
//一定要设置 Content-Type 要不然服务端接收不到参数
setHeaderParam
(
connection
,
type
,
headParam
);
connection
.
setRequestProperty
(
"Content-Type"
,
"application/Json; charset=UTF-8"
);
if
(
output
!=
null
){
OutputStream
out
=
connection
.
getOutputStream
();
out
.
write
(
output
.
getBytes
(
"UTF-8"
));
out
.
close
();
}
//流处理
InputStream
input
=
connection
.
getInputStream
();
InputStreamReader
inputReader
=
new
InputStreamReader
(
input
,
"UTF-8"
);
BufferedReader
reader
=
new
BufferedReader
(
inputReader
);
String
line
;
while
((
line
=
reader
.
readLine
())!=
null
){
buffer
.
append
(
line
);
}
//关闭连接、释放资源
reader
.
close
();
inputReader
.
close
();
input
.
close
();
input
=
null
;
connection
.
disconnect
();
logger
.
info
(
buffer
.
toString
());
jsonObject
=
JSONObject
.
fromObject
(
buffer
.
toString
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
jsonObject
;
}
public
static
Map
<
String
,
Object
>
getAccessToken
()
throws
UnsupportedEncodingException
,
NoSuchAlgorithmException
{
Long
current_time
=
System
.
currentTimeMillis
();
Map
<
String
,
Object
>
map
=
null
;
String
para
=
"requestKey="
+
ZhelibanAPP
.
APP_KEY
+
"&requestTime="
+
current_time
+
"&sign="
+
MD5
.
md5
(
ZhelibanAPP
.
APP_KEY
+
ZhelibanAPP
.
APP_SECRET
+
current_time
);
System
.
out
.
println
(
para
);
// Map<String, Object> map_result = HttpRequestUtil.sendPost(ZhelibanAPP.TOKEN_URL, para,false,false);
Map
<
String
,
Object
>
map_result
=
new
HashMap
<>();
String
sp
=
new
Gson
().
toJson
(
map_result
);
if
(
null
!=
sp
&&
!
""
.
equals
(
sp
)
)
{
try
{
map
=
new
Gson
().
fromJson
(
sp
,
new
TypeToken
<
Map
<
String
,
Object
>>()
{
}.
getType
());
if
(
map
.
get
(
"result"
).
toString
().
equals
(
"00"
)){
//获取成功
map
.
put
(
"accessToken"
,
map
.
get
(
"resultmsg"
));
}
else
{
logger
.
info
(
"获取token失败:错误代码--"
+
map
.
get
(
"result"
)+
",错误原因--"
+
map
.
get
(
"resultmsg"
));
}
logger
.
info
(
"获取token成功:"
+
map
.
get
(
"resultmsg"
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
logger
.
error
(
"获取token异常!!"
);
}
}
System
.
out
.
println
(
map
);
return
map
;
}
public
static
Map
<
String
,
Object
>
getUserInfo
(
Map
<
String
,
Object
>
map
)
{
Map
<
String
,
Object
>
result_map
=
ZhelibanUtils
.
getAppToken
(
map
);
String
current_time
=
String
.
valueOf
(
new
Date
().
getTime
());
if
(
result_map
!=
null
){
System
.
out
.
println
(
result_map
);
if
(
"0"
.
equals
(
result_map
.
get
(
"result"
).
toString
())){
String
params_vailidation
=
"&servicecode="
+
ZhelibanAPP
.
SERVICE_CODE
+
"&time="
+
current_time
+
"&sign="
+
MD5
.
md5
(
ZhelibanAPP
.
SERVICE_CODE
+
ZhelibanAPP
.
SERVICE_PASS
+
current_time
)+
"&token="
+
result_map
.
get
(
"token"
).
toString
()+
"&datatype=json"
;
// String user_result = HttpRequestUtil.sendGet(ZhelibanAPP.APP_BASE_URL);
String
user_result
=
"ssss"
;
System
.
out
.
println
(
" ---------------- aaa ----------- "
+
user_result
);
return
new
Gson
().
fromJson
(
user_result
,
new
TypeToken
<
Map
<
String
,
Object
>>()
{
}.
getType
());
}
else
{
return
result_map
;
}
}
return
null
;
}
public
static
Map
<
String
,
Object
>
getRootUserInfo
(
Map
<
String
,
Object
>
map
)
{
Long
current_time
=
System
.
currentTimeMillis
();
String
params_vailidation
=
"token="
+
map
.
get
(
"ssotoken"
).
toString
();
String
user_result
=
"sssss"
;
// String user_result = HttpRequestUtil.sendHeaderPost(ZhelibanAPP.ROOT_USER_INFO,params_vailidation,false,false);
System
.
out
.
println
(
"111 "
+
user_result
);
return
new
Gson
().
fromJson
(
user_result
,
new
TypeToken
<
Map
<
String
,
Object
>>()
{
}.
getType
());
}
/***
* 验证令牌并获取用户的登录信息
*
* @param ssotoken
*/
public
static
JSONObject
doQuery
(
String
ssotoken
,
String
projectId
,
String
projectSecret
)
{
JSONObject
param
=
new
JSONObject
();
param
.
put
(
"token"
,
ssotoken
);
// 获取请求签名值
// String signature = DigestHelper.getSignature(param.toString(), projectSecret);
String
signature
=
"ss"
;
// 设置请求的Headers头信息
LinkedHashMap
<
String
,
String
>
headers
=
new
LinkedHashMap
<
String
,
String
>();
headers
.
put
(
"x-esso-project-id"
,
projectId
);
headers
.
put
(
"x-esso-signature"
,
signature
);
headers
.
put
(
"Content-Type"
,
"application/json"
);
headers
.
put
(
"Charset"
,
"UTF-8"
);
// 验证令牌并获取用户的登录信息接口调用地址
String
QUERY_URL
=
"http://ssoapi.zjzwfw.gov.cn/rest/user/query"
;
JSONObject
jsonObj
=
sendPOST
(
QUERY_URL
,
param
.
toString
(),
headers
);
if
(
null
!=
jsonObj
)
{
int
errCode
=
jsonObj
.
getInt
(
"errCode"
);
String
msg
=
jsonObj
.
getString
(
"msg"
);
if
(
0
==
errCode
)
{
/* 用户信息 */
String
info
=
jsonObj
.
getString
(
"info"
);
System
.
out
.
println
(
"用户信息 = "
+
info
);
}
else
{
System
.
out
.
println
(
"验证令牌并获取用户的登录信息失败:"
+
msg
);
}
}
return
jsonObj
;
}
/***
* 向指定URL发送POST方法的请求
*
* @param apiUrl
* @param data
* @param headers
* @return
*/
public
static
JSONObject
sendPOST
(
String
apiUrl
,
String
data
,
LinkedHashMap
<
String
,
String
>
headers
)
{
StringBuffer
strBuffer
=
null
;
String
result
=
null
;
JSONObject
jsonObj
=
null
;
try
{
// 建立连接
URL
url
=
new
URL
(
apiUrl
);
/* 获取客户端向服务器端传送数据所依据的协议名称 */
String
protocol
=
url
.
getProtocol
();
if
(
"https"
.
equalsIgnoreCase
(
protocol
))
{
/* 获取HTTPS请求的SSL证书 */
try
{
// SSLUtils.ignoreSsl();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
HttpURLConnection
httpURLConnection
=
(
HttpURLConnection
)
url
.
openConnection
();
// 需要输出
httpURLConnection
.
setDoOutput
(
true
);
// 需要输入
httpURLConnection
.
setDoInput
(
true
);
// 不允许缓存
httpURLConnection
.
setUseCaches
(
false
);
httpURLConnection
.
setRequestMethod
(
"POST"
);
// 设置Headers
if
(
null
!=
headers
)
{
for
(
String
key
:
headers
.
keySet
())
{
httpURLConnection
.
setRequestProperty
(
key
,
headers
.
get
(
key
));
}
}
// 连接会话
httpURLConnection
.
connect
();
// 建立输入流,向指向的URL传入参数
DataOutputStream
dos
=
new
DataOutputStream
(
httpURLConnection
.
getOutputStream
());
// 设置请求参数
dos
.
write
(
data
.
getBytes
(
"UTF-8"
));
dos
.
flush
();
dos
.
close
();
// 获得响应状态
int
http_StatusCode
=
httpURLConnection
.
getResponseCode
();
String
http_ResponseMessage
=
httpURLConnection
.
getResponseMessage
();
if
(
HttpURLConnection
.
HTTP_OK
==
http_StatusCode
)
{
strBuffer
=
new
StringBuffer
();
String
readLine
=
new
String
();
BufferedReader
responseReader
=
new
BufferedReader
(
new
InputStreamReader
(
httpURLConnection
.
getInputStream
(),
"UTF-8"
));
while
((
readLine
=
responseReader
.
readLine
())
!=
null
)
{
strBuffer
.
append
(
readLine
);
}
responseReader
.
close
();
result
=
strBuffer
.
toString
();
if
(
null
==
result
||
result
.
length
()
==
0
)
{
throw
new
Exception
(
"获取企业(法人)信息失败"
);
}
else
{
jsonObj
=
JSONObject
.
fromObject
(
result
);
}
}
else
{
throw
new
Exception
(
MessageFormat
.
format
(
"请求失败,失败原因: Http状态码 = {0} , {1}"
,
http_StatusCode
,
http_ResponseMessage
));
}
// 断开连接
httpURLConnection
.
disconnect
();
}
catch
(
MalformedURLException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
jsonObj
;
}
public
static
Map
<
String
,
Object
>
getAppToken
(
Map
<
String
,
Object
>
map
)
{
// String current_time = DateUtils.getCurrentTimes();
String
current_time
=
String
.
valueOf
(
new
Date
().
getTime
());
String
params_vailidation
=
"&servicecode="
+
ZhelibanAPP
.
SERVICE_CODE
+
"&time="
+
current_time
+
"&sign="
+
MD5
.
md5
(
ZhelibanAPP
.
SERVICE_CODE
+
ZhelibanAPP
.
SERVICE_PASS
+
current_time
)+
"&st="
+
map
.
get
(
"ticket"
).
toString
()+
"&datatype=json"
;
// String valid_result = HttpRequestUtil.sendGet(ZhelibanAPP.APP_BASE_URL+ZhelibanAPP.VALIDATION_TICKET);
String
valid_result
=
"sss"
;
return
new
Gson
().
fromJson
(
valid_result
,
new
TypeToken
<
Map
<
String
,
Object
>>()
{
}.
getType
());
}
public
static
Map
<
String
,
Object
>
getAAccessToken
()
{
JSONObject
jsonObject
=
HttpRequest
(
ZhelibanAPP
.
TOKEN_URL
,
"GET"
,
null
,
"AccessToken"
,
null
);
String
accessToken
=
null
;
String
expireTime
=
null
;
Map
<
String
,
Object
>
map
=
null
;
// 如果请求成功
if
(
null
!=
jsonObject
)
{
try
{
if
(
jsonObject
.
getString
(
"status"
).
equals
(
"0"
)){
//获取成功
map
=
new
HashMap
<
String
,
Object
>();
JSONObject
tokenObject
=
jsonObject
.
getJSONObject
(
"data"
);
accessToken
=
tokenObject
.
getString
(
"accessToken"
);
expireTime
=
tokenObject
.
getString
(
"expireTime"
);
map
.
put
(
"accessToken"
,
accessToken
);
map
.
put
(
"expireTime"
,
expireTime
);
}
else
{
logger
.
info
(
"获取token失败:错误代码--"
+
jsonObject
.
getString
(
"status"
)+
",错误原因--"
+
jsonObject
.
getString
(
"message"
));
}
logger
.
info
(
"获取token成功:"
+
accessToken
+
",过期时间:"
+
expireTime
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
logger
.
error
(
"获取token异常!!"
);
}
}
return
map
;
}
public
static
HttpURLConnection
setHeaderParam
(
HttpURLConnection
connection
,
String
type
,
Map
<
String
,
Object
>
headParam
)
{
if
(
type
.
equals
(
"AccessToken"
))
{
connection
.
setRequestProperty
(
"appId"
,
ZhelibanAPP
.
APP_ID
);
connection
.
setRequestProperty
(
"appSecret"
,
ZhelibanAPP
.
APP_SECRET
);
}
else
if
(
type
.
equals
(
"authlogin"
))
{
connection
.
setRequestProperty
(
"accessToken"
,
headParam
.
get
(
"accessToken"
).
toString
());
connection
.
setRequestProperty
(
"token"
,
headParam
.
get
(
"token"
).
toString
());
}
else
if
(
type
.
equals
(
"pushMessage"
))
{
connection
.
setRequestProperty
(
"accessToken"
,
headParam
.
get
(
"accessToken"
).
toString
());
connection
.
setRequestProperty
(
"orgSecret"
,
headParam
.
get
(
"orgSecret"
).
toString
());
//connection.setRequestProperty("uid", headParam.get("uid").toString());
}
else
if
(
type
.
equals
(
"getUserInfoByMobile"
))
{
connection
.
setRequestProperty
(
"accessToken"
,
headParam
.
get
(
"accessToken"
).
toString
());
connection
.
setRequestProperty
(
"orgSecret"
,
headParam
.
get
(
"orgSecret"
).
toString
());
}
return
connection
;
}
private
static
void
trustAllHosts
()
{
// Create a trust manager that does not validate certificate chains
TrustManager
[]
trustAllCerts
=
new
TrustManager
[]{
new
X509TrustManager
()
{
@Override
public
X509Certificate
[]
getAcceptedIssuers
()
{
return
new
X509Certificate
[]{};
}
@Override
public
void
checkClientTrusted
(
X509Certificate
[]
chain
,
String
authType
)
{
}
@Override
public
void
checkServerTrusted
(
X509Certificate
[]
chain
,
String
authType
)
{
}
}};
// Install the all-trusting trust manager
try
{
SSLContext
sc
=
SSLContext
.
getInstance
(
"TLS"
);
sc
.
init
(
null
,
trustAllCerts
,
new
java
.
security
.
SecureRandom
());
HttpsURLConnection
.
setDefaultSSLSocketFactory
(
sc
.
getSocketFactory
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
public
static
Map
<
String
,
Object
>
authLogin
(
String
accessToken
,
String
token
)
{
Map
<
String
,
Object
>
headParam
=
new
HashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
result
=
null
;
headParam
.
put
(
"accessToken"
,
accessToken
);
headParam
.
put
(
"token"
,
token
);
logger
.
info
(
"auth login"
);
try
{
JSONObject
jsonObject
=
HttpRequest
(
ZhelibanAPP
.
AUTH_LOGIN_URL
,
"GET"
,
null
,
"authlogin"
,
headParam
);
if
(
jsonObject
!=
null
&&
jsonObject
.
getString
(
"status"
).
equals
(
"0"
))
{
logger
.
info
(
"免登授权请求成功"
);
result
=
new
HashMap
<
String
,
Object
>();
JSONObject
userInfo
=
jsonObject
.
getJSONObject
(
"data"
);
result
.
put
(
"uid"
,
userInfo
.
getString
(
"uid"
));
result
.
put
(
"mobile"
,
userInfo
.
getString
(
"mobile"
));
result
.
put
(
"name"
,
userInfo
.
getString
(
"name"
));
result
.
put
(
"orgSecret"
,
userInfo
.
getString
(
"orgSecret"
));
}
else
{
logger
.
info
(
"无返回值"
);
return
null
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
logger
.
error
(
"免登授权请求失败!"
);
}
return
result
;
}
public
static
Map
<
String
,
Object
>
pushMessage
(
String
accessToken
,
String
orgSecret
,
String
uid
,
String
queryParam
)
{
Map
<
String
,
Object
>
headParam
=
new
HashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
result
=
null
;
headParam
.
put
(
"accessToken"
,
accessToken
);
headParam
.
put
(
"orgSecret"
,
orgSecret
);
headParam
.
put
(
"uid"
,
uid
);
logger
.
info
(
"pushMessage start!!"
);
try
{
JSONObject
jsonObject
=
HttpRequest
(
ZhelibanAPP
.
PUSH_MESSAGE_SIMPLE
,
"POST"
,
queryParam
,
"pushMessage"
,
headParam
);
if
(
jsonObject
!=
null
&&
jsonObject
.
getString
(
"status"
).
equals
(
"0"
))
{
logger
.
info
(
"消息推送成功"
);
result
=
new
HashMap
<
String
,
Object
>();
result
.
put
(
"status"
,
jsonObject
.
getString
(
"status"
));
result
.
put
(
"success"
,
jsonObject
.
getString
(
"success"
));
}
else
{
logger
.
info
(
"消息推送失败"
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
logger
.
error
(
"消息推送失败!"
);
}
return
result
;
}
public
static
Map
<
String
,
Object
>
getUserInfoByMobile
(
String
accessToken
,
String
orgSecret
,
String
mobile
)
{
Map
<
String
,
Object
>
headParam
=
new
HashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
result
=
null
;
headParam
.
put
(
"accessToken"
,
accessToken
);
headParam
.
put
(
"orgSecret"
,
orgSecret
);
headParam
.
put
(
"mobile"
,
mobile
);
logger
.
info
(
"getUserInfoByMobile start!!"
);
try
{
JSONObject
jsonObject
=
HttpRequestGetUserInfoByMobile
(
ZhelibanAPP
.
GET_USER_INFO_BY_MOBILE
,
headParam
,
"getUserInfoByMobile"
);
if
(
jsonObject
!=
null
&&
jsonObject
.
getString
(
"status"
).
equals
(
"0"
))
{
logger
.
info
(
"获取用户信息成功"
);
result
=
new
HashMap
<
String
,
Object
>();
JSONObject
userInfo
=
jsonObject
.
getJSONObject
(
"data"
);
result
.
put
(
"uid"
,
userInfo
.
getString
(
"uid"
));
result
.
put
(
"name"
,
userInfo
.
getString
(
"name"
));
}
else
{
logger
.
info
(
"获取用户信息失败!"
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
logger
.
error
(
"获取用户信息失败!"
);
}
return
result
;
}
public
static
JSONObject
HttpRequestGetUserInfoByMobile
(
String
request
,
Map
<
String
,
Object
>
headParam
,
String
type
){
@SuppressWarnings
(
"unused"
)
JSONObject
jsonObject
=
null
;
StringBuffer
buffer
=
new
StringBuffer
();
try
{
//建立连接
trustAllHosts
();
//HTTPS请求需建立信任链接
URL
url
=
new
URL
(
request
+
"?"
+
"mobile="
+
headParam
.
get
(
"mobile"
).
toString
());
HttpsURLConnection
connection
=
(
HttpsURLConnection
)
url
.
openConnection
();
connection
.
setRequestMethod
(
"GET"
);
connection
.
setUseCaches
(
false
);
setHeaderParam
(
connection
,
type
,
headParam
);
connection
.
setHostnameVerifier
(
DO_NOT_VERIFY
);
//流处理
InputStream
input
=
connection
.
getInputStream
();
InputStreamReader
inputReader
=
new
InputStreamReader
(
input
,
"UTF-8"
);
BufferedReader
reader
=
new
BufferedReader
(
inputReader
);
String
line
;
while
((
line
=
reader
.
readLine
())!=
null
){
buffer
.
append
(
line
);
}
//关闭连接、释放资源
reader
.
close
();
inputReader
.
close
();
input
.
close
();
input
=
null
;
connection
.
disconnect
();
logger
.
info
(
buffer
.
toString
());
jsonObject
=
JSONObject
.
fromObject
(
buffer
.
toString
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
jsonObject
;
}
/* public static void pushMessageToUser(String title, String content, String action, String departmentLabel) {
CaiYunUtil caiYunUtil = new CaiYunUtil();
caiYunUtil.pushMessageTo(title, content, action, departmentLabel);
}*/
/*public static void pushMessageTo(String title, String content, String action, String departmentLabel) {
String[] s1 = null;
List<String> stringList = yspQueryService.queryMobileByDepartmentLabel(departmentLabel);
for (int i = 0; i < stringList.size(); i++) {
Map map = CaiYunUtil.getUserInfoByMobile(CaiYunUtil.getAccessToken().get("accessToken").toString(), yspQueryService.getOrgSecret(), stringList.get(i));
s1[i] = map.get("uid").toString();
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("title", title);
jsonObject.put("content", content);
jsonObject.put("action", action);
jsonObject.put("receivers", s1);
CaiYunUtil.pushMessage(yspQueryService.getAccessToken(), yspQueryService.getOrgSecret(), null, jsonObject.toString());
}*/
private
static
String
getUtf8Url
(
String
url
)
{
char
[]
chars
=
url
.
toCharArray
();
StringBuilder
utf8Url
=
new
StringBuilder
();
final
int
charCount
=
chars
.
length
;
for
(
int
i
=
0
;
i
<
charCount
;
i
++)
{
byte
[]
bytes
=
(
""
+
chars
[
i
]).
getBytes
();
if
(
bytes
.
length
==
1
)
{
utf8Url
.
append
(
chars
[
i
]);
}
else
{
try
{
utf8Url
.
append
(
URLEncoder
.
encode
(
String
.
valueOf
(
chars
[
i
]),
"UTF-8"
));
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
}
}
return
utf8Url
.
toString
();
}
private
static
String
toUTF
(
String
inStr
)
throws
UnsupportedEncodingException
{
String
outStr
=
""
;
if
(
inStr
!=
null
)
{
outStr
=
new
String
(
inStr
.
getBytes
(
"iso-8859-1"
),
"UTF-8"
);
}
return
outStr
;
}
/**
* 汉字 转换为对应的 UTF-8编码
* @param s 木
* @return E69CA8
*/
public
static
String
convertStringToUTF8
(
String
s
)
{
if
(
s
==
null
||
s
.
equals
(
""
))
{
return
null
;
}
StringBuffer
sb
=
new
StringBuffer
();
try
{
char
c
;
for
(
int
i
=
0
;
i
<
s
.
length
();
i
++)
{
c
=
s
.
charAt
(
i
);
if
(
c
>=
0
&&
c
<=
255
)
{
sb
.
append
(
c
);
}
else
{
byte
[]
b
;
b
=
Character
.
toString
(
c
).
getBytes
(
"utf-8"
);
for
(
int
j
=
0
;
j
<
b
.
length
;
j
++)
{
int
k
=
b
[
j
];
//转换为unsigned integer 无符号integer
/*if (k < 0)
k += 256;*/
k
=
k
<
0
?
k
+
256
:
k
;
//返回整数参数的字符串表示形式 作为十六进制(base16)中的无符号整数
//该值以十六进制(base16)转换为ASCII数字的字符串
sb
.
append
(
Integer
.
toHexString
(
k
).
toUpperCase
());
// url转置形式
// sb.append("%" +Integer.toHexString(k).toUpperCase());
}
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
sb
.
toString
();
}
/**
* 可将中文转换成 "&#" 开头的html实体编码
*
*
* @param str
* @return*/
public
static
String
encodeS
(
String
str
)
{
char
[]
arrs
=
str
.
toCharArray
();
//Hex.encodeHex();
StringBuilder
sb
=
new
StringBuilder
();
for
(
char
c
:
arrs
)
{
// \\u 表示Unicode编码。
if
(
c
>=
'\
u2E80
'
&&
c
<=
'\
uFE4F
'
)
{
// [ 只是中文一般 [ \u4e00-\u9fa5];中日韩统一表意文字(CJK Unified Ideographs) [\u2E80-\uFE4F]
sb
.
append
(
"&#x"
).
append
((
int
)
c
).
append
(
";"
);
}
else
{
sb
.
append
(
c
);
}
}
return
sb
.
toString
();
}
public
static
String
ZH
(
String
str
)
{
String
[]
string
=
str
.
split
(
"u"
);
System
.
out
.
println
(
new
Gson
().
toJson
(
string
));
return
"111"
;
}
public
static
void
main
(
String
[]
args
)
throws
UnsupportedEncodingException
,
NoSuchAlgorithmException
{
//System.out.println(URLEncoder.encode("给付", "UTF-8"));
//System.out.println(StringEscapeUtils.unescapeHtml("给付"));
//System.out.println(StringEscapeUtils.unescapeHtml("\\u7ED9\\u4ED8"));
//7.StringEscapeUtils
//输出结果为<html>
System
.
out
.
println
(
StringEscapeUtils
.
escapeJava
(
"String"
));
}
}
hmit-api/src/main/java/io/hmit/controller/ApiLoginController.java
View file @
6d37d496
...
...
@@ -4,7 +4,9 @@ package io.hmit.controller;
import
io.hmit.annotation.Login
;
import
io.hmit.common.utils.Result
;
import
io.hmit.common.validator.ValidatorUtils
;
import
io.hmit.config.ZhelibanUtils
;
import
io.hmit.dto.LoginDTO
;
import
io.hmit.entity.UserEntity
;
import
io.hmit.service.TokenService
;
import
io.hmit.service.UserService
;
import
io.swagger.annotations.Api
;
...
...
@@ -13,7 +15,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.web.bind.annotation.*
;
import
springfox.documentation.annotations.ApiIgnore
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.util.Map
;
import
java.util.UUID
;
/**
* 登录接口
...
...
@@ -53,4 +60,69 @@ public class ApiLoginController {
return
new
Result
();
}
}
\ No newline at end of file
//个人登录 - 单点登陆
@RequestMapping
(
value
=
"/check_user"
)
@ResponseBody
public
void
checkUser
(
@RequestParam
Map
<
String
,
Object
>
map
,
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
UnsupportedEncodingException
{
// 获取到票据信息ticket
System
.
out
.
println
(
"开始进入这个checkuser了————————————————————"
);
System
.
out
.
println
(
map
);
String
redirectUrl
=
""
;
String
Token
=
""
;
if
(
map
.
get
(
"ticket"
)
!=
null
){
System
.
out
.
println
(
"Ticket 是"
+
map
.
get
(
"ticket"
)+
"——————————————————————"
);
Map
<
String
,
Object
>
user_map
=
ZhelibanUtils
.
getUserInfo
(
map
);
System
.
out
.
println
(
"UserMap是——————————————————————————————"
);
System
.
out
.
println
(
user_map
);
if
(
user_map
.
get
(
"idnum"
)
!=
null
){
System
.
out
.
println
(
user_map
.
get
(
"idnum"
));
String
params
=
"idnum="
+
URLEncoder
.
encode
(
user_map
.
get
(
"idnum"
).
toString
(),
"UTF8"
)+
"&mobile="
+
URLEncoder
.
encode
(
user_map
.
get
(
"mobile"
).
toString
(),
"UTF8"
)+
"&username="
+
URLEncoder
.
encode
(
user_map
.
get
(
"username"
).
toString
(),
"UTF8"
);
if
(
map
.
get
(
"sp"
)
!=
null
)
{
redirectUrl
=
map
.
get
(
"sp"
)
+
"?"
+
params
;
}
//判断是否已经存在了这条信息
// UserEntity oldUser=userService.queryByIdnum(URLEncoder.encode(user_map.get("idnum").toString(), "UTF8"));
UserEntity
oldUser
=
userService
.
getUserByUserId
(
222L
);
if
(
oldUser
==
null
){
//将获得的信息保存到个人登陆表
UserEntity
user
=
new
UserEntity
();
user
.
setUsername
(
user_map
.
get
(
"username"
).
toString
());
user
.
setMobile
(
URLEncoder
.
encode
(
user_map
.
get
(
"mobile"
).
toString
(),
"UTF8"
));
user
.
setPassword
(
URLEncoder
.
encode
(
user_map
.
get
(
"idnum"
).
toString
(),
"UTF8"
));
// userService.save(user);
// //将获得的信息保存到个人信息表
// CjroneDisabledPersonEntity disabledPersonEntity=new CjroneDisabledPersonEntity();
// disabledPersonEntity.setName(user_map.get("username").toString());
// // disabledPersonEntity.setMobilePhone(URLEncoder.encode(user_map.get("mobile").toString(), "UTF8"));
// disabledPersonEntity.setIdCard(URLEncoder.encode(user_map.get("idnum").toString(), "UTF8"));
// // disabledPersonEntity.setSex(URLEncoder.encode(user_map.get("sex").toString(), "UTF8"));
// disabledPersonEntity.setPostcode(URLEncoder.encode(user_map.get("postcode").toString(), "UTF8"));
// disabledPersonEntity.setBirthday(URLEncoder.encode(user_map.get("birthday").toString(), "UTF8"));
// disabledPersonEntity.setPresentAddress(user_map.get("homeaddress").toString());
// cjroneDisabledPersonService.save(disabledPersonEntity);
}
//生成token返回
// UserEntity tbuser=userService.queryByIdnum(URLEncoder.encode(user_map.get("idnum").toString(), "UTF8"));
// Token = jwtUtils.generateToken(tbuser.getUserId());
}
}
else
{
//return R.error().put("msg","票据信息不能为空!");
if
(
map
.
get
(
"sp"
)
!=
null
)
{
redirectUrl
=
map
.
get
(
"sp"
).
toString
()+
"?1=1"
;
}
}
String
record_id
=
UUID
.
randomUUID
().
toString
();
System
.
out
.
println
(
"Url: "
+
redirectUrl
+
"&recordId="
+
record_id
+
"&token="
+
Token
);
response
.
setHeader
(
"refresh"
,
"1;URL="
+
redirectUrl
+
"&recordId="
+
record_id
+
"&token="
+
Token
);
}
}
hmit-api/src/main/java/io/hmit/modules/appointment/controller/AppointmentOrderController.java
View file @
6d37d496
package
io
.
hmit
.
modules
.
appointment
.
controller
;
import
com.alibaba.fastjson.JSONObject
;
import
com.google.gson.JsonObject
;
import
io.hmit.common.constant.Constant
;
import
io.hmit.common.page.PageData
;
import
io.hmit.common.utils.DateUtils
;
import
io.hmit.common.utils.HttpRequestUtil
;
import
io.hmit.common.utils.MD5
;
import
io.hmit.common.utils.Result
;
import
io.hmit.common.validator.AssertUtils
;
import
io.hmit.common.validator.ValidatorUtils
;
...
...
@@ -19,7 +23,9 @@ import io.swagger.annotations.ApiImplicitParam;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.http.ResponseEntity
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.client.RestTemplate
;
import
springfox.documentation.annotations.ApiIgnore
;
import
java.util.Date
;
...
...
@@ -115,8 +121,29 @@ public class AppointmentOrderController {
//根据appointmentOrderId获取到订单实体
AppointmentOrderDTO
appointmentOrderDTO
=
appointmentOrderService
.
get
(
appointmentOrderId
);
//判断签到时间是否在预约时间前
if
(
appointmentOrderDTO
.
getAppointmentTime
().
getTime
()
>
new
Date
().
getTime
())
{
String
appointmentIdCard
=
appointmentOrderDTO
.
getAppointmentIdCard
();
String
appointmentPhone
=
appointmentOrderDTO
.
getAppointmentPhone
();
String
serviceId
=
appointmentOrderDTO
.
getServiceId
().
toString
();
String
appointmentPerson
=
appointmentOrderDTO
.
getAppointmentPerson
();
String
sign
=
"hjfhsdjfueytRwYSdsa%hdf^jdshfh*KGh$e"
+
serviceId
+
new
Date
().
getTime
();
//判断签到时间是否在预约时间前
//调用取号机取号接口,获取取号信息,并更新预约号。
// http://IP:8223/smartqueue/yynumber?sQueueInfoID=24&time=1613389800&sign=ee2c3fc1bdabf439f00aa90af6a0a68f&sTel=13988888888&sName=王小二&sCardID=333111123456
String
url
=
"http://IP:8223/smartqueue/yynumber?"
+
"sQueueInfoID="
+
serviceId
+
"&time="
+
new
Date
().
getTime
()+
"&sign="
+
MD5
.
md5
(
sign
)+
"&sTel="
+
appointmentPhone
+
"&sName="
+
appointmentPerson
+
"&sCardID="
+
appointmentIdCard
;
String
Url
=
"http://www.nb-fh.cn/getAllarticleCast"
;
String
s
=
HttpRequestUtil
.
sendGetAndRetrieveContent
(
Url
);
JSONObject
json
=
JSONObject
.
parseObject
(
s
);
//根据接口返回的结果更新预约单号
appointmentOrderDTO
.
setStatus
(
2
);
appointmentOrderDTO
.
setStatusName
(
"签到"
);
appointmentOrderDTO
.
setUpdateDate
(
new
Date
());
...
...
@@ -178,4 +205,6 @@ public class AppointmentOrderController {
return
new
Result
();
}
}
hmit-api/src/main/java/io/hmit/modules/appointment/dto/YynumberDTO.java
0 → 100644
View file @
6d37d496
package
io
.
hmit
.
modules
.
appointment
.
dto
;
import
lombok.Data
;
import
java.util.List
;
@Data
public
class
YynumberDTO
{
/**
* nStatus : 0
* sMsg :
* sPaperNumber : Z1001
* nWait : 1
* nid : 4322
* sRegTime : 2018-12-21 13:49:21
* sQueueName : 预约-交通违法处理
* listWin : ["B03","B04","B05","B06"]
*/
private
int
nStatus
;
private
String
sMsg
;
private
String
sPaperNumber
;
private
int
nWait
;
private
int
nid
;
private
String
sRegTime
;
private
String
sCallTime
;
private
String
sQueueName
;
private
List
<
String
>
listWin
;
}
hmit-api/src/main/java/io/hmit/modules/appointment/service/AppointmentOrderService.java
View file @
6d37d496
...
...
@@ -21,4 +21,6 @@ public interface AppointmentOrderService extends CrudService<AppointmentOrderEnt
Integer
serviceWaitingNum
(
Long
serviceId
);
}
hmit-api/src/main/java/io/hmit/modules/appointment/service/impl/AppointmentOrderServiceImpl.java
View file @
6d37d496
...
...
@@ -74,4 +74,6 @@ public class AppointmentOrderServiceImpl extends CrudServiceImpl<AppointmentOrde
return
appointmentOrderDao
.
serviceWaitingNum
(
serviceId
)
;
}
}
hmit-common/pom.xml
View file @
6d37d496
...
...
@@ -14,5 +14,12 @@
<build>
<finalName>
${project.artifactId}
</finalName>
</build>
<dependencies>
<dependency>
<groupId>
log4j
</groupId>
<artifactId>
log4j
</artifactId>
<version>
1.2.17
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
</project>
hmit-common/src/main/java/io/hmit/common/utils/HttpRequestUtil.java
0 → 100644
View file @
6d37d496
package
io
.
hmit
.
common
.
utils
;
import
org.apache.commons.codec.binary.Base64
;
import
org.apache.log4j.Logger
;
import
javax.net.ssl.*
;
import
java.io.BufferedReader
;
import
java.io.InputStream
;
import
java.io.InputStreamReader
;
import
java.io.PrintWriter
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
public
class
HttpRequestUtil
{
private
static
Logger
mailAndLyncFailLogger
=
Logger
.
getLogger
(
"MailAndLyncFailLogger"
);
/***
* 向指定URL发送POST方法的请求
* @param url 发送请求的URL
* @return URL所代表远程资源的响应
*/
public
static
int
sendGet
(
String
url
)
{
int
resultCode
=
0
;
try
{
URL
realUrl
=
new
URL
(
url
);
// 打开和URL之间的连接
HttpURLConnection
conn
=
(
HttpURLConnection
)
realUrl
.
openConnection
();
conn
.
setRequestMethod
(
"GET"
);
//设置post方式连接
// 设置通用的请求属性
conn
.
setRequestProperty
(
"Connection"
,
"Keep-Alive"
);
conn
.
setRequestProperty
(
"Charset"
,
"UTF-8"
);
conn
.
setUseCaches
(
false
);
// 建立实际的连接
conn
.
connect
();
// 获取响应状态
resultCode
=
conn
.
getResponseCode
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
(
e
);
}
return
resultCode
;
}
/***
* 向指定URL发送GET方法的请求
* @param url 发送请求的URL
* @return URL所代表远程资源的响应
*/
public
static
String
sendGetAndRetrieveContent
(
String
url
)
{
String
result
=
null
;
StringBuffer
resultBuffer
=
new
StringBuffer
();
try
{
URL
realUrl
=
new
URL
(
url
);
// 打开和URL之间的连接
HttpURLConnection
conn
=
(
HttpURLConnection
)
realUrl
.
openConnection
();
conn
.
setRequestMethod
(
"GET"
);
//设置post方式连接
// 设置通用的请求属性
conn
.
setRequestProperty
(
"Connection"
,
"Keep-Alive"
);
conn
.
setRequestProperty
(
"Charset"
,
"UTF-8"
);
conn
.
setUseCaches
(
false
);
// 建立实际的连接
conn
.
connect
();
// 获取响应状态
InputStream
in
=
conn
.
getInputStream
();
InputStreamReader
reader
=
new
InputStreamReader
(
in
,
"UTF-8"
);
BufferedReader
breader
=
new
BufferedReader
(
reader
);
String
str
=
null
;
while
((
str
=
breader
.
readLine
())!=
null
){
resultBuffer
.
append
(
str
);
}
breader
.
close
();
reader
.
close
();
in
.
close
();
conn
.
disconnect
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
throw
new
RuntimeException
(
e
);
}
return
result
=
resultBuffer
.
toString
();
}
/***
* 向指定URL发送POST方法的请求
* @param url 发送请求的URL
* @param param 请求参数,请求参数应该是name1=value1&name2=value2的形式
* @return URL所代表远程资源的响应
*/
public
static
int
sendPost
(
String
url
,
String
param
)
{
PrintWriter
out
=
null
;
int
resultCode
=
0
;
try
{
URL
realUrl
=
new
URL
(
url
);
mailAndLyncFailLogger
.
info
(
"realUrl:"
+
realUrl
);
mailAndLyncFailLogger
.
info
(
"param:"
+
param
);
// 打开和URL之间的连接
HttpURLConnection
conn
=
(
HttpURLConnection
)
realUrl
.
openConnection
();
conn
.
setRequestMethod
(
"POST"
);
//设置post方式连接
// 设置通用的请求属性
conn
.
setRequestProperty
(
"Content-Type"
,
"application/x-www-form-urlencoded"
);
conn
.
setRequestProperty
(
"Connection"
,
"Keep-Alive"
);
conn
.
setRequestProperty
(
"Charset"
,
"UTF-8"
);
// 发送POST请求必须设置如下两行
conn
.
setDoOutput
(
true
);
conn
.
setDoInput
(
true
);
conn
.
setUseCaches
(
false
);
// 获取URLConnection对象对应的输出流
out
=
new
PrintWriter
(
conn
.
getOutputStream
());
// 发送请求参数
out
.
print
(
param
);
// flush输出流的缓冲
out
.
flush
();
// 定义BufferedReader输入流来读取URL的响应
resultCode
=
conn
.
getResponseCode
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
mailAndLyncFailLogger
.
error
(
e
.
getMessage
());
}
finally
{
try
{
if
(
out
!=
null
)
{
out
.
close
();
}
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
mailAndLyncFailLogger
.
error
(
ex
.
getMessage
());
}
}
return
resultCode
;
}
/***
* 向指定URL发送POST方法的请求
* @param url 发送请求的URL
* @param param 请求参数,请求参数应该是name1=value1&name2=value2的形式
* @param userName 新品系统发送数据账号名
* @param passWord 新品系统发送数据账号密码
* @return URL所代表远程资源的响应
*/
public
static
int
sendPostExtend
(
String
url
,
String
param
,
String
userName
,
String
passWord
)
{
PrintWriter
out
=
null
;
int
resultCode
=
-
1
;
String
base64Str
=
null
;
String
userInfo
=
null
;
try
{
URL
realUrl
=
new
URL
(
url
);
mailAndLyncFailLogger
.
info
(
"realUrl:"
+
realUrl
);
mailAndLyncFailLogger
.
info
(
"param:"
+
param
+
"; from userName="
+
userName
);
// 打开和URL之间的连接
HttpsURLConnection
conn
=
(
HttpsURLConnection
)
realUrl
.
openConnection
();
//SSLContext sslcontext = SSLContext.getInstance("SSL","SunJSSE");
SSLContext
sslcontext
=
SSLContext
.
getInstance
(
"SSL"
);
sslcontext
.
init
(
null
,
new
TrustManager
[]{
new
MyX509TrustManager
()},
new
java
.
security
.
SecureRandom
());
HostnameVerifier
ignoreHostnameVerifier
=
new
HostnameVerifier
()
{
public
boolean
verify
(
String
s
,
SSLSession
sslsession
)
{
mailAndLyncFailLogger
.
info
(
"WARNING: Hostname is not matched for cert."
);
return
true
;
}
};
conn
.
setHostnameVerifier
(
ignoreHostnameVerifier
);
conn
.
setSSLSocketFactory
(
sslcontext
.
getSocketFactory
());
conn
.
setRequestMethod
(
"POST"
);
//设置post方式连接
// 设置通用的请求属性
conn
.
setRequestProperty
(
"Accept"
,
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
);
conn
.
setRequestProperty
(
"Accept-Language"
,
"zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2"
);
conn
.
setRequestProperty
(
"Accept-Encoding"
,
"gzip, deflate, br"
);
conn
.
setRequestProperty
(
"Connection"
,
"keep-alive"
);
conn
.
setRequestProperty
(
"Upgrade-Insecure-Requests"
,
"1"
);
//柳汽通 需要包含指定头部,用于临时授权
Base64
base64
=
new
Base64
();
userInfo
=
userName
+
":"
+
passWord
;
base64Str
=
base64
.
encodeToString
(
userInfo
.
getBytes
(
"UTF-8"
));
conn
.
setRequestProperty
(
"Authorization"
,
"Basic "
+
base64Str
);
// 发送POST请求必须设置如下两行
conn
.
setDoOutput
(
true
);
conn
.
setDoInput
(
true
);
conn
.
setUseCaches
(
false
);
//不校验
// conn.setHostnameVerifier(DO_NOT_VERIFY);
// 获取URLConnection对象对应的输出流
out
=
new
PrintWriter
(
conn
.
getOutputStream
());
// 发送请求参数
out
.
print
(
param
);
// flush输出流的缓冲
out
.
flush
();
// 定义BufferedReader输入流来读取URL的响应
conn
.
getResponseCode
();
resultCode
=
conn
.
getResponseCode
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
mailAndLyncFailLogger
.
error
(
e
.
getMessage
());
}
finally
{
try
{
if
(
out
!=
null
)
{
out
.
close
();
}
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
mailAndLyncFailLogger
.
error
(
ex
.
getMessage
());
}
}
return
resultCode
;
}
}
hmit-common/src/main/java/io/hmit/common/utils/MD5.java
0 → 100644
View file @
6d37d496
package
io
.
hmit
.
common
.
utils
;
import
sun.misc.BASE64Encoder
;
import
java.io.UnsupportedEncodingException
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
/**
* 说明:MD5处理
* 创建人:hmit
* 修改时间:
* @version
*/
public
class
MD5
{
public
static
String
md5
(
String
str
)
{
try
{
MessageDigest
md
=
MessageDigest
.
getInstance
(
"MD5"
);
md
.
update
(
str
.
getBytes
());
byte
b
[]
=
md
.
digest
();
int
i
;
StringBuffer
buf
=
new
StringBuffer
(
""
);
for
(
int
offset
=
0
;
offset
<
b
.
length
;
offset
++)
{
i
=
b
[
offset
];
if
(
i
<
0
)
i
+=
256
;
if
(
i
<
16
)
buf
.
append
(
"0"
);
buf
.
append
(
Integer
.
toHexString
(
i
));
}
str
=
buf
.
toString
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
str
;
}
/**利用MD5进行加密
* @param str 待加密的字符串
* @return 加密后的字符串
* @throws NoSuchAlgorithmException 没有这种产生消息摘要的算法
* @throws UnsupportedEncodingException
*/
public
static
String
EncoderByMd5
(
String
str
)
throws
NoSuchAlgorithmException
,
UnsupportedEncodingException
{
//确定计算方法
MessageDigest
md5
=
MessageDigest
.
getInstance
(
"MD5"
);
BASE64Encoder
base64en
=
new
BASE64Encoder
();
//加密后的字符串
String
newstr
=
base64en
.
encode
(
md5
.
digest
(
str
.
getBytes
(
"utf-8"
)));
return
newstr
;
}
public
static
void
main
(
String
[]
args
)
throws
UnsupportedEncodingException
,
NoSuchAlgorithmException
{
System
.
out
.
println
(
md5
(
"hjfhsdjfueytRwYSdsa%hdf^jdshfh*KGh$e241613389800"
));
System
.
out
.
println
(
md5
(
"kkk"
));
System
.
out
.
println
(
EncoderByMd5
(
"180@qq.com"
+
"123456"
));
}
}
hmit-common/src/main/java/io/hmit/common/utils/MyX509TrustManager.java
0 → 100644
View file @
6d37d496
package
io
.
hmit
.
common
.
utils
;
import
java.security.cert.CertificateException
;
import
java.security.cert.X509Certificate
;
import
javax.net.ssl.X509TrustManager
;
public
class
MyX509TrustManager
implements
X509TrustManager
{
@Override
public
void
checkClientTrusted
(
X509Certificate
certificates
[],
String
authType
)
throws
CertificateException
{
}
@Override
public
void
checkServerTrusted
(
X509Certificate
[]
ax509certificate
,
String
s
)
throws
CertificateException
{
}
@Override
public
X509Certificate
[]
getAcceptedIssuers
()
{
return
null
;
}
}
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