Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cloud-platform
Project
Project
Details
Activity
Releases
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
youjj
cloud-platform
Commits
9866b5a7
Commit
9866b5a7
authored
Sep 20, 2019
by
hezhen
Committed by
libin
Sep 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
123
parent
2ced5dbd
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
257 additions
and
24 deletions
+257
-24
RedisKey.java
...main/java/com/xxfc/platform/summit/constant/RedisKey.java
+10
-0
ActivityBm.java
...main/java/com/xxfc/platform/summit/entity/ActivityBm.java
+55
-0
User.java
...i/src/main/java/com/xxfc/platform/summit/entity/User.java
+111
-0
WeixinController.java
...com/xxfc/platform/summit/controller/WeixinController.java
+33
-12
WeChatH5LoginInterceoptor.java
...latform/summit/interceptor/WeChatH5LoginInterceoptor.java
+48
-12
No files found.
xx-summit/xx-summit-api/src/main/java/com/xxfc/platform/summit/constant/RedisKey.java
0 → 100644
View file @
9866b5a7
package
com
.
xxfc
.
platform
.
summit
.
constant
;
public
class
RedisKey
{
/**
*验证码key前缀
*/
public
static
final
String
CONSTANT_CODE_PREFIX
=
"bm:info:"
;
}
xx-summit/xx-summit-api/src/main/java/com/xxfc/platform/summit/entity/ActivityBm.java
0 → 100644
View file @
9866b5a7
package
com
.
xxfc
.
platform
.
summit
.
entity
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
javax.persistence.Column
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
/**
* @author Administrator
*/
@Data
@Table
(
name
=
"fc_activity_bm"
)
public
class
ActivityBm
{
@Id
@GeneratedValue
(
generator
=
"JDBC"
)
private
Integer
id
;
@Column
(
name
=
"activity_id"
)
@ApiModelProperty
(
"活动id"
)
private
Integer
activityId
;
@Column
(
name
=
"name"
)
@ApiModelProperty
(
"报名人姓名"
)
private
String
name
;
@Column
(
name
=
"phone"
)
@ApiModelProperty
(
"报名人电话"
)
private
String
phone
;
@Column
(
name
=
"id_number"
)
@ApiModelProperty
(
"身份证号"
)
private
String
idNumber
;
@Column
(
name
=
"inviter"
)
@ApiModelProperty
(
"邀请人"
)
private
String
inviter
;
@Column
(
name
=
"crt_time"
)
@ApiModelProperty
(
"创建时间"
)
private
Long
crtTime
;
@Column
(
name
=
"upd_time"
)
@ApiModelProperty
(
"创建时间"
)
private
Long
updTime
;
@Column
(
name
=
"is_del"
)
@ApiModelProperty
(
"是否删除:0-正常;1-删除"
)
private
Integer
isDel
;
}
xx-summit/xx-summit-api/src/main/java/com/xxfc/platform/summit/entity/User.java
0 → 100644
View file @
9866b5a7
package
com
.
xxfc
.
platform
.
summit
.
entity
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
javax.persistence.Column
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
import
javax.persistence.Table
;
import
java.math.BigDecimal
;
/**
* @author Administrator
*/
@Data
@Table
(
name
=
"ims_meepo_xianchang_user"
)
public
class
User
{
@Id
@GeneratedValue
(
generator
=
"JDBC"
)
private
Integer
id
;
@Column
(
name
=
"weid"
)
@ApiModelProperty
(
"主公众号id"
)
private
Integer
weId
;
@Column
(
name
=
"rid"
)
@ApiModelProperty
(
"规则ID"
)
private
Integer
rId
;
@Column
(
name
=
"openid"
)
@ApiModelProperty
(
"微信openid"
)
private
String
openId
;
@Column
(
name
=
"oauth_openid"
)
@ApiModelProperty
(
"待定"
)
private
String
oauthOpenid
;
@Column
(
name
=
"mobile"
)
@ApiModelProperty
(
"电话"
)
private
String
mobile
;
@Column
(
name
=
"nick_name"
)
@ApiModelProperty
(
"昵称"
)
private
String
nickName
;
@Column
(
name
=
"avatar"
)
@ApiModelProperty
(
"头像"
)
private
String
avatar
;
@Column
(
name
=
"sex"
)
@ApiModelProperty
(
"性别"
)
private
String
sex
;
@Column
(
name
=
"group"
)
@ApiModelProperty
(
"分组"
)
private
Integer
group
;
@Column
(
name
=
"status"
)
@ApiModelProperty
(
"状态"
)
private
Integer
status
;
@Column
(
name
=
"isblacklist"
)
@ApiModelProperty
(
"待定"
)
private
Integer
isBlacklist
;
@Column
(
name
=
"can_lottory"
)
@ApiModelProperty
(
"待定"
)
private
Integer
canLottory
;
@Column
(
name
=
"can_dt"
)
@ApiModelProperty
(
"待定"
)
private
Integer
canDt
;
@Column
(
name
=
"nd_id"
)
@ApiModelProperty
(
"待定"
)
private
Integer
ndId
;
@Column
(
name
=
"qd_status"
)
@ApiModelProperty
(
"签到状态"
)
private
Integer
qdStatus
;
@Column
(
name
=
"is_manager"
)
@ApiModelProperty
(
"待定"
)
private
Integer
isManager
;
@Column
(
name
=
"money"
)
@ApiModelProperty
(
"分组"
)
private
BigDecimal
money
;
@Column
(
name
=
"createtime"
)
@ApiModelProperty
(
"创建时间"
)
private
Integer
createtime
;
@Column
(
name
=
"lastjointime"
)
@ApiModelProperty
(
"待定"
)
private
Integer
lastjointime
;
@Column
(
name
=
"had_luru"
)
@ApiModelProperty
(
"待定"
)
private
Integer
hadLuru
;
}
xx-summit/xx-summit-server/src/main/java/com/xxfc/platform/summit/controller/WeixinController.java
View file @
9866b5a7
...
@@ -26,6 +26,7 @@ import javax.servlet.http.HttpSession;
...
@@ -26,6 +26,7 @@ import javax.servlet.http.HttpSession;
public
class
WeixinController
{
public
class
WeixinController
{
public
static
final
String
WECHAT_AUTOLOGIN_CALLBACKURL_KEY
=
"callback"
;
public
static
final
String
WECHAT_AUTOLOGIN_CALLBACKURL_KEY
=
"callback"
;
public
static
final
String
WECHAT_REDIS_KEY
=
"key"
;
@Autowired
@Autowired
WeixinService
weixinService
;
WeixinService
weixinService
;
...
@@ -39,14 +40,15 @@ public class WeixinController {
...
@@ -39,14 +40,15 @@ public class WeixinController {
@RequestMapping
(
value
=
"/app/unauth/wxLogin"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"/app/unauth/wxLogin"
,
method
=
RequestMethod
.
GET
)
@IgnoreUserToken
@IgnoreUserToken
public
String
index
(
@RequestParam
(
value
=
"redirec_url"
)
String
redirec_url
){
public
String
index
(
@RequestParam
(
value
=
"redirec_url"
)
String
redirec_url
,
@RequestParam
(
value
=
"key"
)
String
key
){
log
.
info
(
"-----微信wxLogin---redirec_url=="
+
redirec_url
);
log
.
info
(
"-----微信wxLogin---redirec_url=="
+
redirec_url
);
if
(
StringUtils
.
isBlank
(
redirec_url
)){
if
(
StringUtils
.
isBlank
(
redirec_url
)){
redirec_url
=
""
;
redirec_url
=
""
;
}
}
try
{
try
{
String
encrypt_curr_url
=
Base64
.
encode
(
redirec_url
.
getBytes
(
"utf-8"
));
String
encrypt_curr_url
=
Base64
.
encode
(
redirec_url
.
getBytes
(
"utf-8"
));
redirec_url
=
url
+
"?"
+
WECHAT_AUTOLOGIN_CALLBACKURL_KEY
+
"="
+
encrypt_curr_url
;
redirec_url
=
url
+
"?"
+
WECHAT_AUTOLOGIN_CALLBACKURL_KEY
+
"="
+
encrypt_curr_url
+
"&"
+
WECHAT_REDIS_KEY
+
"="
+
key
;
String
oauth_api
=
weixinService
.
getAuthorize
(
redirec_url
);
String
oauth_api
=
weixinService
.
getAuthorize
(
redirec_url
);
return
String
.
format
(
"redirect:"
+
oauth_api
);
return
String
.
format
(
"redirect:"
+
oauth_api
);
}
catch
(
Exception
e
){
}
catch
(
Exception
e
){
...
@@ -63,19 +65,20 @@ public class WeixinController {
...
@@ -63,19 +65,20 @@ public class WeixinController {
* @return
* @return
*/
*/
@GetMapping
(
value
=
"/app/unauth/userInfo"
)
@GetMapping
(
value
=
"/app/unauth/userInfo"
)
public
String
getUserInformation
(
String
code
,
String
callback
,
HttpServletRequest
request
)
{
public
String
getUserInformation
(
String
code
,
String
callback
,
String
key
,
HttpServletRequest
request
)
{
log
.
info
(
"-----微信回调userInfo---code=="
+
code
+
"----redirec_url==="
+
callback
);
log
.
info
(
"-----微信回调userInfo---code=="
+
code
+
"----redirec_url==="
+
callback
);
if
(
StringUtils
.
isBlank
(
code
)){
if
(
StringUtils
.
isBlank
(
code
)){
log
.
info
(
"----code为空---"
);
log
.
info
(
"----code为空---"
);
return
String
.
format
(
"code为空"
);
return
String
.
format
(
"code为空"
);
}
}
String
openid
=
null
;
String
access_token
=
null
;
try
{
try
{
JSONObject
jsonData
=
weixinService
.
getAccessToken
(
code
);
JSONObject
jsonData
=
weixinService
.
getAccessToken
(
code
);
String
openid
=
jsonData
.
getString
(
"openid"
);
openid
=
jsonData
.
getString
(
"openid"
);
String
access_token
=
jsonData
.
getString
(
"access_token"
);
access_token
=
jsonData
.
getString
(
"access_token"
);
String
refresh_token
=
jsonData
.
getString
(
"refresh_token"
);
String
refresh_token
=
jsonData
.
getString
(
"refresh_token"
);
log
.
info
(
"-----微信回调userInfo---openid=="
+
openid
+
"----access_token==="
+
access_token
);
log
.
info
(
"-----微信回调userInfo---openid=="
+
openid
+
"----access_token==="
+
access_token
);
HttpSession
session
=
request
.
getSession
();
//验证access_token是否失效
//验证access_token是否失效
JSONObject
validateData
=
weixinService
.
getValidateData
(
access_token
,
openid
);
JSONObject
validateData
=
weixinService
.
getValidateData
(
access_token
,
openid
);
if
(!
"0"
.
equals
(
validateData
.
getString
(
"errcode"
))){
if
(!
"0"
.
equals
(
validateData
.
getString
(
"errcode"
))){
...
@@ -83,21 +86,39 @@ public class WeixinController {
...
@@ -83,21 +86,39 @@ public class WeixinController {
JSONObject
refreshData
=
weixinService
.
getRefreshToken
(
refresh_token
);
JSONObject
refreshData
=
weixinService
.
getRefreshToken
(
refresh_token
);
access_token
=
refreshData
.
getString
(
"access_token"
);
access_token
=
refreshData
.
getString
(
"access_token"
);
}
}
}
catch
(
Exception
e
){
e
.
printStackTrace
();
log
.
info
(
"网络异常==="
+
e
.
getMessage
());
return
String
.
format
(
"网络异常"
);
}
try
{
// 获取微信用户基本信息
JSONObject
userinfo_json
=
weixinService
.
getUserInfo
(
access_token
,
openid
);
if
(
userinfo_json
==
null
||
StringUtils
.
isNotBlank
(
userinfo_json
.
getString
(
"errcode"
)))
{
log
.
info
(
"调用微信用户基本信息接口失败"
);
return
String
.
format
(
"调用微信用户基本信息接口失败"
);
}
String
headimgurl
=
userinfo_json
.
getString
(
"headimgurl"
);
String
unionid
=
userinfo_json
.
getString
(
"unionid"
);
String
nickName
=
userinfo_json
.
getString
(
"nickname"
);
String
sex
=
userinfo_json
.
getString
(
"sex"
);
UserInfo
userInfo
=
new
UserInfo
();
UserInfo
userInfo
=
new
UserInfo
();
userInfo
.
setOpenId
(
openid
);
userInfo
.
setOpenId
(
openid
);
log
.
info
(
"UserInfo==="
+
JSONObject
.
toJSONString
(
userInfo
));
log
.
info
(
"UserInfo==="
+
JSONObject
.
toJSONString
(
userInfo
));
String
encode
=
Base64
.
encode
(
JSONObject
.
toJSONString
(
userInfo
));
String
encode
=
Base64
.
encode
(
JSONObject
.
toJSONString
(
userInfo
));
HttpSession
session
=
request
.
getSession
();
session
.
removeAttribute
(
frontSessionKey
);
session
.
removeAttribute
(
frontSessionKey
);
session
.
setAttribute
(
frontSessionKey
,
encode
);
session
.
setAttribute
(
frontSessionKey
,
encode
);
callback
=
new
String
(
Base64
.
decode
(
callback
),
"utf-8"
);
callback
=
new
String
(
Base64
.
decode
(
callback
),
"utf-8"
);
log
.
info
(
"callback==="
+
callback
);
log
.
info
(
"callback==="
+
callback
);
}
catch
(
Exception
e
)
{
log
.
info
(
"调用微信用户基本信息接口失败"
,
e
);
return
String
.
format
(
"调用微信用户基本信息接口失败:"
);
}
return
String
.
format
(
"redirect:"
+
callback
);
return
String
.
format
(
"redirect:"
+
callback
);
}
catch
(
Exception
e
){
e
.
printStackTrace
();
log
.
info
(
"网络异常==="
+
e
.
getMessage
());
return
String
.
format
(
"网络异常"
);
}
}
}
}
}
xx-summit/xx-summit-server/src/main/java/com/xxfc/platform/summit/interceptor/WeChatH5LoginInterceoptor.java
View file @
9866b5a7
package
com
.
xxfc
.
platform
.
summit
.
interceptor
;
package
com
.
xxfc
.
platform
.
summit
.
interceptor
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpSession
;
import
javax.servlet.http.HttpSession
;
import
cn.hutool.core.codec.Base64
;
import
com.alibaba.fastjson.JSON
;
import
com.github.wxiaoqi.security.common.msg.ObjectRestResponse
;
import
com.github.wxiaoqi.security.common.util.UserAgentUtil
;
import
com.github.wxiaoqi.security.common.util.UserAgentUtil
;
import
com.xxfc.platform.summit.constant.RedisKey
;
import
com.xxfc.platform.summit.service.WeixinService
;
import
com.xxfc.platform.summit.service.WeixinService
;
import
com.xxfc.platform.summit.vo.UserInfo
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.
beans.factory.annotation.Valu
e
;
import
org.springframework.
data.redis.core.RedisTemplat
e
;
import
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
;
import
org.springframework.web.servlet.handler.HandlerInterceptorAdapter
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
java.io.BufferedReader
;
import
java.io.PrintWriter
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.UUID
;
import
java.util.concurrent.TimeUnit
;
/**
/**
* 微信登陆拦截器
* 微信登陆拦截器
...
@@ -37,6 +37,9 @@ public class WeChatH5LoginInterceoptor extends HandlerInterceptorAdapter {
...
@@ -37,6 +37,9 @@ public class WeChatH5LoginInterceoptor extends HandlerInterceptorAdapter {
@Autowired
@Autowired
WeixinService
weixinService
;
WeixinService
weixinService
;
@Autowired
private
RedisTemplate
userRedisTemplate
;
@Override
@Override
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
throws
Exception
{
public
boolean
preHandle
(
HttpServletRequest
request
,
HttpServletResponse
response
,
Object
handler
)
throws
Exception
{
...
@@ -47,20 +50,53 @@ public class WeChatH5LoginInterceoptor extends HandlerInterceptorAdapter {
...
@@ -47,20 +50,53 @@ public class WeChatH5LoginInterceoptor extends HandlerInterceptorAdapter {
log
.
info
(
"address:"
+
request
.
getRequestURL
().
toString
());
log
.
info
(
"address:"
+
request
.
getRequestURL
().
toString
());
log
.
info
(
"params:"
+
request
.
getQueryString
());
log
.
info
(
"params:"
+
request
.
getQueryString
());
boolean
isWx
=
UserAgentUtil
.
isWexinBrowser
(
request
);
boolean
isWx
=
UserAgentUtil
.
isWexinBrowser
(
request
);
if
(
isWx
)
{
if
(
isWx
)
{
String
frontSessionValue1
=
(
String
)
session
.
getAttribute
(
frontSessionKey
);
String
frontSessionValue1
=
(
String
)
session
.
getAttribute
(
frontSessionKey
);
if
(
StringUtils
.
isNotBlank
(
frontSessionValue1
))
{
if
(
StringUtils
.
isNotBlank
(
frontSessionValue1
))
{
return
true
;
return
true
;
}
}
String
redisKey
=
redisBmInfo
(
request
);
Map
<
String
,
Object
>
result
=
new
HashMap
<>();
JSONObject
json
=
new
JSONObject
();
JSONObject
json
=
new
JSONObject
();
json
.
put
(
"status"
,
1001
);
if
(
StringUtils
.
isNotBlank
(
redisKey
)){
json
.
put
(
"data"
,
"https://dev.dfangche.com/api/summit/auth/app/unauth/wxLogin?redirec_url=https://dev.dfangche.com/h5/appHtml/view/wxh5/index.html"
);
json
.
put
(
"key"
,
redisKey
);
response
.
getWriter
().
write
(
json
.
toJSONString
());
}
json
.
put
(
"url"
,
"https://dev.dfangche.com/api/summit/auth/app/unauth/wxLogin?redirec_url=https://dev.dfangche.com/h5/appHtml/view/wxh5/index.html"
);
result
.
put
(
"data"
,
json
);
result
.
put
(
"status"
,
1001
);
response
.
getWriter
().
write
(
result
.
toString
());
return
false
;
return
false
;
}
}
return
true
;
return
true
;
}
}
public
String
redisBmInfo
(
HttpServletRequest
request
)
throws
Exception
{
request
.
setCharacterEncoding
(
"UTF-8"
);
StringBuffer
jb
=
new
StringBuffer
();
String
line
=
null
;
try
{
BufferedReader
reader
=
request
.
getReader
();
while
((
line
=
reader
.
readLine
())
!=
null
)
jb
.
append
(
line
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
String
redisLockKey
=
null
;
if
(
StringUtils
.
isNotBlank
(
jb
)){
redisLockKey
=
RedisKey
.
CONSTANT_CODE_PREFIX
+
UUID
.
randomUUID
();
Boolean
suc
=
userRedisTemplate
.
opsForValue
().
setIfAbsent
(
redisLockKey
,
jb
);
if
(
suc
)
{
userRedisTemplate
.
expire
(
redisLockKey
,
5
,
TimeUnit
.
MINUTES
);
//5分钟内过期
}
}
return
redisLockKey
;
}
}
}
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