Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xyqb-user2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
head_group
xyqb-user2
Commits
1fd43fad
Commit
1fd43fad
authored
Jan 18, 2017
by
zhouqian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
log
parent
7182279a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
17 deletions
+13
-17
WeChatController.java
...group/xyqb/controller/external/user/WeChatController.java
+13
-17
No files found.
src/main/java/cn/quantgroup/xyqb/controller/external/user/We
b
ChatController.java
→
src/main/java/cn/quantgroup/xyqb/controller/external/user/WeChatController.java
View file @
1fd43fad
...
...
@@ -6,8 +6,8 @@ import cn.quantgroup.xyqb.model.webchat.AccessTokenResponse;
import
cn.quantgroup.xyqb.service.http.IHttpService
;
import
cn.quantgroup.xyqb.service.user.IUserService
;
import
com.alibaba.fastjson.JSON
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
...
...
@@ -20,20 +20,21 @@ import java.util.Arrays;
/**
* Created by 11 on 2017/1/17.
*/
@Slf4j
@RestController
@RequestMapping
(
"/we
b
chat"
)
public
class
We
b
ChatController
{
@RequestMapping
(
"/wechat"
)
public
class
WeChatController
{
// todo: 配置文件
public
static
final
String
TOKEN
=
"5YihkluEo5QuWAWpFwzvA"
;
private
static
final
org
.
slf4j
.
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
WebChatController
.
class
);
@Autowired
private
IHttpService
httpService
;
@Autowired
private
IUserService
userService
;
public
String
access_token_url
=
"https://api.weixin.qq.com/sns/oauth2/access_token?appid=wxcdf6077af8127559&secret=16eaec16084d0d9c52d4114f359cc72c&code=%s&grant_type=authorization_code"
;
public
String
access_userinfo_url
=
"https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s&lang=zh_CN"
;
//todo: 配置文件相关
private
String
access_token_url
=
"https://api.weixin.qq.com/sns/oauth2/access_token?appid=wxcdf6077af8127559&secret=16eaec16084d0d9c52d4114f359cc72c&code=%s&grant_type=authorization_code"
;
private
String
access_userinfo_url
=
"https://api.weixin.qq.com/sns/userinfo?access_token=%s&openid=%s&lang=zh_CN"
;
/**
...
...
@@ -72,11 +73,6 @@ public class WebChatController {
return
null
;
}
public
static
void
main
(
String
[]
args
)
{
String
test
=
" "
;
System
.
out
.
println
(
StringUtils
.
isEmpty
(
test
));
System
.
out
.
println
(
StringUtils
.
isBlank
(
test
));
}
/**
* 验签:步骤
...
...
@@ -87,14 +83,14 @@ public class WebChatController {
* @param request
* @return
*/
p
ublic
boolean
checkSignature
(
HttpServletRequest
request
)
{
p
rivate
boolean
checkSignature
(
HttpServletRequest
request
)
{
String
signature
=
request
.
getParameter
(
"signature"
);
String
timestamp
=
request
.
getParameter
(
"timestamp"
);
String
nonce
=
request
.
getParameter
(
"nonce"
);
String
token
=
TOKEN
;
String
[]
arrs
=
new
String
[]{
token
,
timestamp
,
nonce
};
Arrays
.
sort
(
arrs
);
String
joinStr
=
split
Array
(
arrs
);
String
joinStr
=
join
Array
(
arrs
);
joinStr
=
sha1
(
joinStr
);
return
joinStr
.
equals
(
signature
);
}
...
...
@@ -122,7 +118,7 @@ public class WebChatController {
return
hexString
.
toString
();
}
catch
(
NoSuchAlgorithmException
e
)
{
LOGGER
.
error
(
"未找到sha1算法."
+
e
.
getMessage
());
log
.
error
(
"未找到sha1算法."
+
e
.
getMessage
());
}
return
""
;
}
...
...
@@ -132,7 +128,7 @@ public class WebChatController {
* @param arr
* @return
*/
private
String
split
Array
(
String
[]
arr
)
{
private
String
join
Array
(
String
[]
arr
)
{
StringBuilder
builder
=
new
StringBuilder
();
for
(
String
str
:
arr
){
builder
.
append
(
str
);
...
...
@@ -164,7 +160,7 @@ public class WebChatController {
try
{
accessTokenResponse
=
JSON
.
parseObject
(
response
,
AccessTokenResponse
.
class
);
}
catch
(
Exception
e
){
LOGGER
.
error
(
"获取access_token出错{}:"
,
e
);
log
.
error
(
"获取access_token出错{}:"
,
e
);
return
JsonResult
.
buildErrorStateResult
(
"获取access_token出错"
,
null
);
}
//从AccessTokenResponse中获取access_token, openid
...
...
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