Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gdtel-gztel-school-center
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
吴学德
gdtel-gztel-school-center
Commits
f70b2b3e
Commit
f70b2b3e
authored
Apr 20, 2020
by
黄森林
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
微信登录修改
parent
687f2bee
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
139 additions
and
16 deletions
+139
-16
common/src/main/java/com/winsun/utils/HttpHelper.java
+114
-0
core-service/src/main/java/com/winsun/item/modular/system/controller/LoginPwdController.java
+23
-12
core-service/src/main/java/com/winsun/item/modular/system/controller/WeixinAuthController.java
+2
-4
No files found.
common/src/main/java/com/winsun/utils/HttpHelper.java
View file @
f70b2b3e
...
@@ -3,10 +3,16 @@ package com.winsun.utils;
...
@@ -3,10 +3,16 @@ package com.winsun.utils;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpEntity
;
import
org.apache.http.HttpHost
;
import
org.apache.http.HttpResponse
;
import
org.apache.http.client.ClientProtocolException
;
import
org.apache.http.client.config.RequestConfig
;
import
org.apache.http.client.config.RequestConfig
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.CloseableHttpResponse
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.client.methods.HttpGet
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.client.methods.HttpPost
;
import
org.apache.http.conn.ssl.SSLConnectionSocketFactory
;
import
org.apache.http.conn.ssl.SSLContextBuilder
;
import
org.apache.http.conn.ssl.TrustStrategy
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.entity.StringEntity
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClients
;
import
org.apache.http.impl.client.HttpClients
;
...
@@ -15,7 +21,13 @@ import org.apache.http.util.EntityUtils;
...
@@ -15,7 +21,13 @@ import org.apache.http.util.EntityUtils;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
javax.net.ssl.SSLContext
;
import
javax.security.cert.CertificateException
;
import
javax.security.cert.X509Certificate
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.security.KeyManagementException
;
import
java.security.KeyStoreException
;
import
java.security.NoSuchAlgorithmException
;
/**
/**
* HTTP请求封装
* HTTP请求封装
...
@@ -171,6 +183,108 @@ public class HttpHelper {
...
@@ -171,6 +183,108 @@ public class HttpHelper {
return
null
;
return
null
;
}
}
// 新方法 走代理
public
static
String
sendGet
(
String
url
)
{
String
string
=
""
;
CloseableHttpClient
httpClient
=
HttpClients
.
createDefault
();
HttpPost
httpPost
=
new
HttpPost
(
url
);
try
{
HttpHost
proxy
=
new
HttpHost
(
"172.18.101.170"
,
3128
);
RequestConfig
requestConfig
=
RequestConfig
.
custom
().
setSocketTimeout
(
200000
).
setConnectTimeout
(
200000
).
setProxy
(
proxy
).
build
();
httpPost
.
setConfig
(
requestConfig
);
CloseableHttpResponse
result
=
httpClient
.
execute
(
httpPost
);
string
=
EntityUtils
.
toString
(
result
.
getEntity
(),
"utf-8"
);
;
}
catch
(
ClientProtocolException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalStateException
e
)
{
e
.
printStackTrace
();
}
return
string
;
}
/**
* 向指定 URL 发送POST方法的请求
*
* @param url
* 发送请求的 URL
* @param param
* 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
* @return 所代表远程资源的响应结果
*/
// 走代理
public
static
String
sendPost
(
String
url
,
String
param
)
{
String
string
=
""
;
CloseableHttpClient
httpClient
=
createSSLClientDefault
();
HttpPost
httpPost
=
new
HttpPost
(
url
);
StringEntity
s
=
new
StringEntity
(
param
,
"UTF-8"
);
// 中文乱码在此解决
s
.
setContentType
(
"application/json"
);
httpPost
.
setEntity
(
s
);
HttpResponse
res
;
try
{
HttpHost
proxy
=
new
HttpHost
(
"172.18.101.170"
,
3128
);
RequestConfig
requestConfig
=
RequestConfig
.
custom
().
setSocketTimeout
(
200000
).
setConnectTimeout
(
200000
).
setProxy
(
proxy
).
build
();
httpPost
.
setConfig
(
requestConfig
);
CloseableHttpResponse
result
=
httpClient
.
execute
(
httpPost
);
string
=
EntityUtils
.
toString
(
result
.
getEntity
(),
"utf-8"
);
}
catch
(
ClientProtocolException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalStateException
e
)
{
e
.
printStackTrace
();
}
finally
{
try
{
httpClient
.
close
();
}
catch
(
IOException
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
}
return
string
;
}
public
static
CloseableHttpClient
createSSLClientDefault
()
{
try
{
SSLContext
sslContext
=
new
SSLContextBuilder
().
loadTrustMaterial
(
null
,
new
TrustStrategy
()
{
// 信任所有
public
boolean
isTrusted
(
X509Certificate
[]
chain
,
String
authType
)
throws
CertificateException
{
return
true
;
}
@Override
public
boolean
isTrusted
(
java
.
security
.
cert
.
X509Certificate
[]
arg0
,
String
arg1
)
throws
java
.
security
.
cert
.
CertificateException
{
// TODO Auto-generated method stub
return
false
;
}
}).
build
();
SSLConnectionSocketFactory
sslsf
=
new
SSLConnectionSocketFactory
(
sslContext
);
return
HttpClients
.
custom
().
setSSLSocketFactory
(
sslsf
).
build
();
}
catch
(
KeyManagementException
e
)
{
e
.
printStackTrace
();
}
catch
(
NoSuchAlgorithmException
e
)
{
e
.
printStackTrace
();
}
catch
(
KeyStoreException
e
)
{
e
.
printStackTrace
();
}
return
HttpClients
.
createDefault
();
}
}
}
core-service/src/main/java/com/winsun/item/modular/system/controller/LoginPwdController.java
View file @
f70b2b3e
...
@@ -43,6 +43,8 @@ import org.springframework.util.Assert;
...
@@ -43,6 +43,8 @@ import org.springframework.util.Assert;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.util.CollectionUtils
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.RequestDispatcher
;
import
javax.servlet.ServletException
;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.ServletOutputStream
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.Cookie
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
...
@@ -94,6 +96,11 @@ public class LoginPwdController extends BaseController {
...
@@ -94,6 +96,11 @@ public class LoginPwdController extends BaseController {
LoginPwdController
.
stringRedisTemplate
=
stringRedisTemplate
;
LoginPwdController
.
stringRedisTemplate
=
stringRedisTemplate
;
}
}
@RequestMapping
(
"/MP_verify_oYaGTxvtIJXLOkXB.txt"
)
public
void
auth
(
HttpServletResponse
response
)
throws
IOException
{
response
.
getWriter
().
print
(
"oYaGTxvtIJXLOkXB"
);
}
/**
/**
* 微信授权
* 微信授权
*
*
...
@@ -106,13 +113,15 @@ public class LoginPwdController extends BaseController {
...
@@ -106,13 +113,15 @@ public class LoginPwdController extends BaseController {
String
url
=
"https://open.weixin.qq.com/connect/oauth2/authorize?"
;
String
url
=
"https://open.weixin.qq.com/connect/oauth2/authorize?"
;
url
+=
"appid="
;
url
+=
"appid="
;
url
+=
APPID
;
url
+=
APPID
;
url
+=
"&redirect_uri="
+
URLEncoder
.
encode
(
"http://hhrcode.winsun-aly.com/#/login
?state="
+
state
,
"UTF-8"
);
//此处和微信会调用的域名相同
url
+=
"&redirect_uri="
+
URLEncoder
.
encode
(
"http://hhrcode.winsun-aly.com/#/login
"
,
"UTF-8"
);
//此处和微信会调用的域名相同
url
+=
"&response_type=code&scope=snsapi_userinfo&state=
STATE"
;
url
+=
"&response_type=code&scope=snsapi_userinfo&state=
"
+
state
;
url
+=
"#wechat_redirect"
;
url
+=
"#wechat_redirect"
;
log
.
info
(
url
);
log
.
info
(
url
);
try
{
try
{
response
.
sendRedirect
(
url
);
RequestDispatcher
rd
=
request
.
getRequestDispatcher
(
url
);
}
catch
(
IOException
e
)
{
rd
.
forward
(
request
,
response
);
/* response.sendRedirect(url);*/
}
catch
(
Exception
e
)
{
log
.
error
(
"微信授权异常"
,
e
.
getMessage
());
log
.
error
(
"微信授权异常"
,
e
.
getMessage
());
}
}
}
}
...
@@ -131,10 +140,10 @@ public class LoginPwdController extends BaseController {
...
@@ -131,10 +140,10 @@ public class LoginPwdController extends BaseController {
url
+=
APPID
;
url
+=
APPID
;
url
+=
"&redirect_uri="
+
URLEncoder
.
encode
(
"http://167460x6b0.51mypc.cn/ciop/forgerpw/callBackLogin"
,
"UTF-8"
);
//此处和微信会调用的域名相同
url
+=
"&redirect_uri="
+
URLEncoder
.
encode
(
"http://167460x6b0.51mypc.cn/ciop/forgerpw/callBackLogin"
,
"UTF-8"
);
//此处和微信会调用的域名相同
url
+=
"&response_type=code&scope=snsapi_userinfo"
;
url
+=
"&response_type=code&scope=snsapi_userinfo"
;
url
+=
"&state=#wechat_redirect"
;
url
+=
"&state=
"
+
"http%3A%2F%2Flocalhost%3A3048%2F%23%2Fsupervisor%3Fid%3D7678%26sign%3Df543efe0512735b8b559b7058a6799ea"
+
"
#wechat_redirect"
;
try
{
try
{
response
.
sendRedirect
(
url
);
response
.
sendRedirect
(
url
);
}
catch
(
IO
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"微信授权异常"
,
e
.
getMessage
());
log
.
error
(
"微信授权异常"
,
e
.
getMessage
());
}
}
}
}
...
@@ -164,16 +173,17 @@ public class LoginPwdController extends BaseController {
...
@@ -164,16 +173,17 @@ public class LoginPwdController extends BaseController {
url
+=
"&secret="
;
url
+=
"&secret="
;
url
+=
APPSECRET
;
url
+=
APPSECRET
;
url
+=
"&code="
+
code
+
"&grant_type=authorization_code"
;
url
+=
"&code="
+
code
+
"&grant_type=authorization_code"
;
JSONObject
jsonObject
=
null
;
String
jsonObject
=
null
;
try
{
try
{
jsonObject
=
HttpHelper
.
do
Get
(
url
);
jsonObject
=
HttpHelper
.
send
Get
(
url
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"微信登录获取用户信息失败"
,
e
.
getMessage
());
log
.
error
(
"微信登录获取用户信息失败"
,
e
.
getMessage
());
}
}
if
(
jsonObject
==
null
)
{
if
(
jsonObject
==
null
)
{
return
ResponseData
.
error
(
"微信授权失效,请重新授权!"
);
return
ResponseData
.
error
(
"微信授权失效,请重新授权!"
);
}
}
String
openId
=
jsonObject
.
getString
(
"openid"
);
Map
<
String
,
Object
>
map
=
JSON
.
parseObject
(
jsonObject
,
Map
.
class
);
String
openId
=
map
.
get
(
"openid"
).
toString
();
Wrapper
<
HhrUser
>
wrapper
=
new
EntityWrapper
<>();
Wrapper
<
HhrUser
>
wrapper
=
new
EntityWrapper
<>();
wrapper
.
eq
(
"open_id"
,
openId
);
wrapper
.
eq
(
"open_id"
,
openId
);
List
<
HhrUser
>
hhrUsers
=
hhrUserMapper
.
selectList
(
wrapper
);
List
<
HhrUser
>
hhrUsers
=
hhrUserMapper
.
selectList
(
wrapper
);
...
@@ -223,16 +233,17 @@ public class LoginPwdController extends BaseController {
...
@@ -223,16 +233,17 @@ public class LoginPwdController extends BaseController {
url
+=
"&secret="
;
url
+=
"&secret="
;
url
+=
APPSECRET
;
url
+=
APPSECRET
;
url
+=
"&code="
+
code
+
"&grant_type=authorization_code"
;
url
+=
"&code="
+
code
+
"&grant_type=authorization_code"
;
JSONObject
jsonObject
=
null
;
String
jsonObject
=
null
;
try
{
try
{
jsonObject
=
HttpHelper
.
do
Get
(
url
);
jsonObject
=
HttpHelper
.
send
Get
(
url
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"微信登录获取用户信息失败"
,
e
.
getMessage
());
log
.
error
(
"微信登录获取用户信息失败"
,
e
.
getMessage
());
}
}
if
(
jsonObject
==
null
)
{
if
(
jsonObject
==
null
)
{
return
ResponseData
.
error
(
"微信授权失效,请重新授权!"
);
return
ResponseData
.
error
(
"微信授权失效,请重新授权!"
);
}
}
String
openId
=
jsonObject
.
getString
(
"openid"
);
Map
<
String
,
Object
>
map
=
JSON
.
parseObject
(
jsonObject
,
Map
.
class
);
String
openId
=
map
.
get
(
"openid"
).
toString
();
SysUser
sysUser
=
users
.
get
(
0
);
SysUser
sysUser
=
users
.
get
(
0
);
Wrapper
<
HhrUser
>
wrapper
=
new
EntityWrapper
<>();
Wrapper
<
HhrUser
>
wrapper
=
new
EntityWrapper
<>();
wrapper
.
eq
(
"id"
,
sysUser
.
getId
());
wrapper
.
eq
(
"id"
,
sysUser
.
getId
());
...
...
core-service/src/main/java/com/winsun/item/modular/system/controller/WeixinAuthController.java
View file @
f70b2b3e
...
@@ -8,11 +8,9 @@ import org.springframework.stereotype.Controller;
...
@@ -8,11 +8,9 @@ import org.springframework.stereotype.Controller;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
@Controller
@Controller
public
class
WeixinAuthController
{
public
class
WeixinAuthController
{
@RequestMapping
(
"/MP_verify_oYaGTxvtIJXLOkXB.txt"
)
public
void
auth
(
HttpServletResponse
response
)
throws
IOException
{
response
.
getWriter
().
print
(
"oYaGTxvtIJXLOkXB"
);
}
}
}
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