Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
appApi
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
antaile
appApi
Commits
ae04051b
Commit
ae04051b
authored
May 19, 2021
by
XiaHou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
微信扫码登录相关代码提交
parent
f7fcb70f
Show whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
683 additions
and
17 deletions
+683
-17
AntaileApplication.java
src/main/java/com/hwstudio/antaile/AntaileApplication.java
+2
-0
BeanUtils.java
src/main/java/com/hwstudio/antaile/common/BeanUtils.java
+104
-0
AtlTimeController.java
...va/com/hwstudio/antaile/controller/AtlTimeController.java
+13
-4
AtlUserController.java
...va/com/hwstudio/antaile/controller/AtlUserController.java
+2
-4
AtlWxController.java
...java/com/hwstudio/antaile/controller/AtlWxController.java
+44
-0
SysBaseParamController.java
...studio/antaile/controller/sys/SysBaseParamController.java
+1
-1
AccessTokenParam.java
src/main/java/com/hwstudio/antaile/dto/AccessTokenParam.java
+27
-0
OfficialWebsiteAtlTimeParam.java
...com/hwstudio/antaile/dto/OfficialWebsiteAtlTimeParam.java
+18
-0
OfficialWebsiteAtlTimeVO.java
...va/com/hwstudio/antaile/dto/OfficialWebsiteAtlTimeVO.java
+26
-0
WxInsertUserParam.java
...main/java/com/hwstudio/antaile/dto/WxInsertUserParam.java
+26
-0
AtlTimeMapper.java
src/main/java/com/hwstudio/antaile/mapper/AtlTimeMapper.java
+14
-0
AtlPrivateService.java
.../java/com/hwstudio/antaile/service/AtlPrivateService.java
+2
-2
AtlTimeService.java
...ain/java/com/hwstudio/antaile/service/AtlTimeService.java
+21
-6
AtlWxService.java
src/main/java/com/hwstudio/antaile/service/AtlWxService.java
+173
-0
HttpUtil.java
src/main/java/com/hwstudio/antaile/utils/HttpUtil.java
+174
-0
JsonResult.java
src/main/java/com/hwstudio/antaile/utils/JsonResult.java
+8
-0
application.yml
src/main/resources/application.yml
+5
-0
AtlTimeMapper.xml
src/main/resources/mapping/AtlTimeMapper.xml
+23
-0
No files found.
src/main/java/com/hwstudio/antaile/AntaileApplication.java
View file @
ae04051b
...
...
@@ -8,6 +8,7 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
import
org.springframework.boot.web.servlet.support.SpringBootServletInitializer
;
import
org.springframework.cache.annotation.EnableCaching
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
@SpringBootApplication
...
...
@@ -16,6 +17,7 @@ import org.springframework.scheduling.annotation.EnableScheduling;
//springBoot自带的定时任务注解
@EnableScheduling
@MapperScan
(
value
=
{
"com.hwstudio.antaile.mapper"
,
"com.hwstudio.antaile.mbg.mapper"
,
"com.hwstudio.antaile.operation.*.dao"
})
@ComponentScan
(
basePackages
=
{
"com.hwstudio.antaile.*"
})
@EnableAutoConfiguration
(
exclude
={
DataSourceAutoConfiguration
.
class
})
public
class
AntaileApplication
extends
SpringBootServletInitializer
{
...
...
src/main/java/com/hwstudio/antaile/common/BeanUtils.java
0 → 100644
View file @
ae04051b
package
com
.
hwstudio
.
antaile
.
common
;
import
java.lang.reflect.Method
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
/**
* Bean 工具类
*
* @author kachexing
*/
public
class
BeanUtils
extends
org
.
springframework
.
beans
.
BeanUtils
{
/**
* Bean方法名中属性名开始的下标
*/
private
static
final
int
BEAN_METHOD_PROP_INDEX
=
3
;
/**
* 匹配getter方法的正则表达式
*/
private
static
final
Pattern
GET_PATTERN
=
Pattern
.
compile
(
"get(\\p{javaUpperCase}\\w*)"
);
/**
* 匹配setter方法的正则表达式
*/
private
static
final
Pattern
SET_PATTERN
=
Pattern
.
compile
(
"set(\\p{javaUpperCase}\\w*)"
);
/**
* Bean属性复制工具方法。
*
* @param dest 目标对象
* @param src 源对象
*/
public
static
void
copyBeanProp
(
Object
dest
,
Object
src
)
{
try
{
copyProperties
(
src
,
dest
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
/**
* 获取对象的setter方法。
*
* @param obj 对象
* @return 对象的setter方法列表
*/
public
static
List
<
Method
>
getSetterMethods
(
Object
obj
)
{
// setter方法列表
List
<
Method
>
setterMethods
=
new
ArrayList
<
Method
>();
// 获取所有方法
Method
[]
methods
=
obj
.
getClass
().
getMethods
();
// 查找setter方法
for
(
Method
method
:
methods
)
{
Matcher
m
=
SET_PATTERN
.
matcher
(
method
.
getName
());
if
(
m
.
matches
()
&&
(
method
.
getParameterTypes
().
length
==
1
))
{
setterMethods
.
add
(
method
);
}
}
// 返回setter方法列表
return
setterMethods
;
}
/**
* 获取对象的getter方法。
*
* @param obj 对象
* @return 对象的getter方法列表
*/
public
static
List
<
Method
>
getGetterMethods
(
Object
obj
)
{
// getter方法列表
List
<
Method
>
getterMethods
=
new
ArrayList
<
Method
>();
// 获取所有方法
Method
[]
methods
=
obj
.
getClass
().
getMethods
();
// 查找getter方法
for
(
Method
method
:
methods
)
{
Matcher
m
=
GET_PATTERN
.
matcher
(
method
.
getName
());
if
(
m
.
matches
()
&&
(
method
.
getParameterTypes
().
length
==
0
))
{
getterMethods
.
add
(
method
);
}
}
// 返回getter方法列表
return
getterMethods
;
}
/**
* 检查Bean方法名中的属性名是否相等。<br>
* 如getName()和setName()属性名一样,getName()和setAge()属性名不一样。
*
* @param m1 方法名1
* @param m2 方法名2
* @return 属性名一样返回true,否则返回false
*/
public
static
boolean
isMethodPropEquals
(
String
m1
,
String
m2
)
{
return
m1
.
substring
(
BEAN_METHOD_PROP_INDEX
).
equals
(
m2
.
substring
(
BEAN_METHOD_PROP_INDEX
));
}
}
src/main/java/com/hwstudio/antaile/controller/AtlTimeController.java
View file @
ae04051b
...
...
@@ -9,10 +9,7 @@ import com.hwstudio.antaile.vo.*;
import
io.swagger.annotations.*
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.CrossOrigin
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -564,4 +561,16 @@ public class AtlTimeController extends BaseController {
return
atlTimeService
.
findPageList
(
type
);
}
@PostMapping
(
value
=
"/selectOfficialWebsiteAtlTime"
)
@ApiOperation
(
value
=
"获取官网时光纪"
,
httpMethod
=
"POST"
,
notes
=
"获取官网时光纪"
)
public
JsonResult
selectOfficialWebsiteAtlTime
(
@ApiParam
(
value
=
"传入对象"
)
@RequestBody
OfficialWebsiteAtlTimeParam
officialWebsiteAtlTimeParam
)
{
return
JsonResult
.
success
(
"获取时光纪详情成功"
,
this
.
atlTimeService
.
selectOfficialWebsiteAtlTime
(
officialWebsiteAtlTimeParam
));
}
@PostMapping
(
value
=
"/selectRandomAtlTime"
)
@ApiOperation
(
value
=
"随机获取推荐3个时光纪"
,
httpMethod
=
"POST"
,
notes
=
"随机获取推荐3个时光纪"
)
public
JsonResult
selectRandomAtlTime
(
)
{
return
JsonResult
.
success
(
"获取时光纪详情成功"
,
this
.
atlTimeService
.
selectRandomAtlTime
());
}
}
src/main/java/com/hwstudio/antaile/controller/AtlUserController.java
View file @
ae04051b
...
...
@@ -3,7 +3,6 @@ package com.hwstudio.antaile.controller;
import
com.hwstudio.antaile.dto.AtlUserInfoDto
;
import
com.hwstudio.antaile.dto.BindingMobileDto
;
import
com.hwstudio.antaile.dto.LoginUserDto
;
import
com.hwstudio.antaile.entity.AtlUserAddress
;
import
com.hwstudio.antaile.service.AtlUserService
;
import
com.hwstudio.antaile.utils.JsonResult
;
import
com.hwstudio.antaile.utils.RedisUtil
;
...
...
@@ -13,9 +12,7 @@ import com.hwstudio.antaile.vo.AtlUserUpdateVo;
import
com.hwstudio.antaile.vo.LoginUserVo
;
import
io.swagger.annotations.*
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.CrossOrigin
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.Objects
;
...
...
@@ -254,4 +251,5 @@ public class AtlUserController extends BaseController {
return
atlUserService
.
deleteAddress
(
vo
);
}
}
src/main/java/com/hwstudio/antaile/controller/AtlWxController.java
0 → 100644
View file @
ae04051b
package
com
.
hwstudio
.
antaile
.
controller
;
import
com.hwstudio.antaile.dto.WxInsertUserParam
;
import
com.hwstudio.antaile.service.AtlWxService
;
import
com.hwstudio.antaile.utils.JsonResult
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiParam
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
/**
* @Author xh
* @Date 2021/5/17
* description:
*/
@RestController
@RequestMapping
(
value
=
"/wx"
)
@Api
(
tags
=
"用户相关接口"
)
@CrossOrigin
(
origins
=
"*"
,
maxAge
=
3600
)
public
class
AtlWxController
extends
BaseController
{
@Autowired
private
AtlWxService
atlWxService
;
@RequestMapping
(
value
=
"getQrcodeUrl"
,
method
=
RequestMethod
.
GET
)
@ApiOperation
(
"获取二维码链接地址"
)
public
JsonResult
getQrcodeUrl
()
{
return
this
.
atlWxService
.
getQrcodeUrl
();
}
@RequestMapping
(
value
=
"getQrcodeAndState"
,
method
=
RequestMethod
.
GET
)
@ApiOperation
(
"微信二维码回调地址"
)
public
JsonResult
getQrcodeAndState
(
@RequestParam
(
value
=
"code"
,
required
=
true
)
String
code
,
@RequestParam
(
value
=
"state"
,
required
=
true
)
String
state
)
{
return
this
.
atlWxService
.
getAccessToken
(
code
,
state
);
}
@RequestMapping
(
value
=
"getQrcodeAndState"
,
method
=
RequestMethod
.
POST
)
@ApiOperation
(
"新用户微信扫码登录,绑定手机号密码"
)
public
JsonResult
insertAtlUserByWxLogin
(
@ApiParam
(
value
=
"传入对象"
)
@RequestBody
WxInsertUserParam
wxInsertUserParam
)
{
return
this
.
atlWxService
.
insertAtlUserByWxLogin
(
wxInsertUserParam
);
}
}
src/main/java/com/hwstudio/antaile/controller/sys/SysBaseParamController.java
View file @
ae04051b
...
...
@@ -26,7 +26,7 @@ public class SysBaseParamController {
private
ISysBaseParamService
sysBaseParamService
;
@ApiOperation
(
"根据参数编码查询一条系统参数信息"
)
@RequestMapping
(
value
=
"/getOneParamByParamCode"
,
method
=
RequestMethod
.
GE
T
)
@RequestMapping
(
value
=
"/getOneParamByParamCode"
,
method
=
RequestMethod
.
POS
T
)
@ResponseBody
public
JsonResult
getOneParamByParamCode
(
@ApiParam
(
value
=
"系统参数编码"
,
required
=
true
)
@RequestParam
(
value
=
"paramCode"
,
required
=
true
)
String
paramCode
)
{
return
JsonResult
.
success
(
"查询成功"
,
this
.
sysBaseParamService
.
getOneParamByParamCode
(
paramCode
));
...
...
src/main/java/com/hwstudio/antaile/dto/AccessTokenParam.java
0 → 100644
View file @
ae04051b
package
com
.
hwstudio
.
antaile
.
dto
;
import
io.swagger.annotations.ApiModelProperty
;
import
io.swagger.annotations.ApiOperation
;
import
lombok.Data
;
import
lombok.Value
;
import
java.io.Serializable
;
/**
* @Author xh
* @Date 2021/5/17
* description:
*/
@Data
public
class
AccessTokenParam
implements
Serializable
{
@ApiModelProperty
(
value
=
"appid"
)
private
String
appid
;
@ApiModelProperty
(
value
=
"应用密钥AppSecret,在微信开放平台提交应用审核通过后获得"
)
private
String
secret
;
@ApiModelProperty
(
value
=
"微信二维码登录响应的code"
)
private
String
code
;
@ApiModelProperty
(
value
=
"填authorization_code"
)
private
String
grant_type
;
}
src/main/java/com/hwstudio/antaile/dto/OfficialWebsiteAtlTimeParam.java
0 → 100644
View file @
ae04051b
package
com
.
hwstudio
.
antaile
.
dto
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.io.Serializable
;
/**
* @Author xh
* @Date 2021/5/18
* description:
*/
@Data
public
class
OfficialWebsiteAtlTimeParam
implements
Serializable
{
@ApiModelProperty
(
value
=
"是否首页推荐 0-否 1-是"
)
private
Integer
isCommend
;
}
src/main/java/com/hwstudio/antaile/dto/OfficialWebsiteAtlTimeVO.java
0 → 100644
View file @
ae04051b
package
com
.
hwstudio
.
antaile
.
dto
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.io.Serializable
;
/**
* @Author xh
* @Date 2021/5/14
* description:
*/
@Data
public
class
OfficialWebsiteAtlTimeVO
implements
Serializable
{
@ApiModelProperty
(
value
=
"id"
)
private
Long
id
;
@ApiModelProperty
(
value
=
"模板id"
)
private
Long
templateId
;
@ApiModelProperty
(
value
=
"名称"
)
private
String
name
;
@ApiModelProperty
(
value
=
"封面图"
)
private
String
coverUrl
;
}
src/main/java/com/hwstudio/antaile/dto/WxInsertUserParam.java
0 → 100644
View file @
ae04051b
package
com
.
hwstudio
.
antaile
.
dto
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
java.io.Serializable
;
/**
* @Author xh
* @Date 2021/5/18
* description:
*/
@Data
public
class
WxInsertUserParam
implements
Serializable
{
@ApiModelProperty
(
value
=
"通过微信获取的accessToken"
)
private
String
accessToken
;
@ApiModelProperty
(
value
=
"用户微信Openid"
)
private
String
openid
;
@ApiModelProperty
(
value
=
"用户手机号"
)
private
String
mobilePhone
;
@ApiModelProperty
(
value
=
"登录密码"
)
private
String
loginPassword
;
@ApiModelProperty
(
value
=
"验证码"
)
private
String
verifyCode
;
}
src/main/java/com/hwstudio/antaile/mapper/AtlTimeMapper.java
View file @
ae04051b
...
...
@@ -86,4 +86,17 @@ public interface AtlTimeMapper {
void
restoreTimeDefault
(
Long
userId
);
/**
* 获取官网首页推荐的 时光纪
*
* @return
*/
List
<
OfficialWebsiteAtlTimeVO
>
selectOfficialWebsiteAtlTime
(
OfficialWebsiteAtlTimeParam
officialWebsiteAtlTimeParam
);
/**
* 随机推荐3个时光纪
*
* @return
*/
List
<
OfficialWebsiteAtlTimeVO
>
selectRandomAtlTime
();
}
\ No newline at end of file
src/main/java/com/hwstudio/antaile/service/AtlPrivateService.java
View file @
ae04051b
...
...
@@ -37,7 +37,7 @@ public class AtlPrivateService {
if
(
type
==
1
){
AtlTime
atlTime
=
atlTimeMapper
.
getById
(
id
);
Long
timeUserId
=
atlTime
.
getUserId
();
if
(
userId
==
timeUserId
){
if
(
userId
.
equals
(
timeUserId
)
){
atlPrivateQuestionDto
.
setPrivacySetting
(
1
);
}
else
{
atlPrivateQuestionDto
=
atlTimeMapper
.
getPrivacySetting
(
id
,
type
);
...
...
@@ -45,7 +45,7 @@ public class AtlPrivateService {
}
else
{
AtlAutobiography
atlAutobiography
=
atlAutobiographyMapper
.
getById
(
id
);
Long
autobiographyUserId
=
atlAutobiography
.
getUserId
();
if
(
userId
==
autobiographyUserId
){
if
(
userId
.
equals
(
autobiographyUserId
)
){
atlPrivateQuestionDto
.
setPrivacySetting
(
1
);
}
else
{
type
=
3
;
...
...
src/main/java/com/hwstudio/antaile/service/AtlTimeService.java
View file @
ae04051b
...
...
@@ -9,21 +9,18 @@ import com.hwstudio.antaile.dto.*;
import
com.hwstudio.antaile.entity.*
;
import
com.hwstudio.antaile.exception.BusinessException
;
import
com.hwstudio.antaile.mapper.*
;
import
com.hwstudio.antaile.utils.
*
;
import
com.hwstudio.antaile.utils.
JsonResult
;
import
com.hwstudio.antaile.vo.AtlFineVo
;
import
com.hwstudio.antaile.vo.AtlPrivateVo
;
import
com.hwstudio.antaile.vo.AtlTimeVo
;
import
com.hwstudio.antaile.vo.PageVo
;
import
net.sf.json.JSONArray
;
import
net.sf.json.JSONObject
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
javax.annotation.Resource
;
import
java.io.File
;
import
java.text.SimpleDateFormat
;
import
java.util.*
;
...
...
@@ -714,7 +711,7 @@ public class AtlTimeService {
Long
l
=
Long
.
parseLong
(
str
);
atlTimeArticleImageMapper
.
restoreImage
(
l
);
Map
<
String
,
Object
>
map
=
atlTimeArticleImageMapper
.
getArticleIdById
(
l
);
atlTimeArticleMapper
.
restoreArticle
((
Long
)
map
.
get
(
"articleId"
));
atlTimeArticleMapper
.
restoreArticle
((
Long
)
map
.
get
(
"articleId"
));
}
msg
=
"图片"
;
break
;
...
...
@@ -723,7 +720,7 @@ public class AtlTimeService {
Long
l
=
Long
.
parseLong
(
str
);
atlTimeArticleFileMapper
.
restoreFile
(
l
);
Map
<
String
,
Object
>
map
=
atlTimeArticleFileMapper
.
getArticleIdById
(
l
);
atlTimeArticleMapper
.
restoreArticle
((
Long
)
map
.
get
(
"articleId"
));
atlTimeArticleMapper
.
restoreArticle
((
Long
)
map
.
get
(
"articleId"
));
}
msg
=
"音视频"
;
break
;
...
...
@@ -791,5 +788,23 @@ public class AtlTimeService {
}
/**
* 获取官网首页推荐的 时光纪
*
* @return
*/
public
List
<
OfficialWebsiteAtlTimeVO
>
selectOfficialWebsiteAtlTime
(
OfficialWebsiteAtlTimeParam
officialWebsiteAtlTimeParam
)
{
return
this
.
atlTimeMapper
.
selectOfficialWebsiteAtlTime
(
officialWebsiteAtlTimeParam
);
}
/**
* 随机推荐3个时光纪
*
* @return
*/
public
List
<
OfficialWebsiteAtlTimeVO
>
selectRandomAtlTime
()
{
return
this
.
atlTimeMapper
.
selectRandomAtlTime
();
}
}
src/main/java/com/hwstudio/antaile/service/AtlWxService.java
0 → 100644
View file @
ae04051b
package
com
.
hwstudio
.
antaile
.
service
;
import
com.alibaba.fastjson.JSON
;
import
com.hwstudio.antaile.common.Constants
;
import
com.hwstudio.antaile.dto.AccessTokenParam
;
import
com.hwstudio.antaile.dto.LoginUserDto
;
import
com.hwstudio.antaile.dto.WxInsertUserParam
;
import
com.hwstudio.antaile.entity.AtlUser
;
import
com.hwstudio.antaile.entity.Sms
;
import
com.hwstudio.antaile.exception.BusinessException
;
import
com.hwstudio.antaile.mapper.AtlUserMapper
;
import
com.hwstudio.antaile.mapper.SmsMapper
;
import
com.hwstudio.antaile.utils.HttpUtils
;
import
com.hwstudio.antaile.utils.JsonResult
;
import
com.hwstudio.antaile.utils.RedisUtil
;
import
org.apache.commons.codec.digest.DigestUtils
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.annotation.Resource
;
import
java.util.Map
;
import
java.util.UUID
;
/**
* @Author xh
* @Date 2021/5/17
* description:
*/
@Service
public
class
AtlWxService
{
@Value
(
"${spring.wx.appid}"
)
private
String
appid
;
@Value
(
"${spring.wx.appSecret}"
)
private
String
appSecret
;
@Value
(
"${spring.wx.redirectUri}"
)
private
String
redirectUri
;
//获取accessTokenUrl
private
String
getAccessTokenUrl
=
"https://api.weixin.qq.com/sns/oauth2/access_token"
;
//获取用户信息Url
private
String
getUserInfoUrl
=
"https://api.weixin.qq.com/sns/userinfo"
;
@Resource
private
AtlUserMapper
atlUserMapper
;
@Resource
private
SmsMapper
smsMapper
;
@Resource
private
RedisUtil
redisUtil
;
/**
* 组装拼接登录url
*
* @return
*/
public
JsonResult
getQrcodeUrl
()
{
String
url
=
"https://open.weixin.qq.com/connect/qrconnect?appid="
+
appid
+
"&redirect_uri="
+
redirectUri
+
"&response_type=code&scope=snsapi_login&state=STATE#wechat_redirect"
;
return
JsonResult
.
success
(
"获取微信登录链接成功"
,
url
);
}
/**
* 获取accessToken
*
* @return
*/
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
JsonResult
getAccessToken
(
String
code
,
String
state
)
{
AccessTokenParam
accessTokenParam
=
new
AccessTokenParam
();
accessTokenParam
.
setAppid
(
appid
);
accessTokenParam
.
setSecret
(
appSecret
);
accessTokenParam
.
setCode
(
code
);
accessTokenParam
.
setGrant_type
(
"authorization_code"
);
String
accessTokenRes
=
HttpUtils
.
get
(
getAccessTokenUrl
+
"?appid="
+
appid
+
"&secret="
+
appSecret
+
"&code="
+
code
+
"&grant_type=authorization_code"
);
//将返回数据 转成map 获取accessToken数据
Map
dataMap
=
(
Map
)
JSON
.
parse
(
accessTokenRes
);
String
accessToken
=
(
String
)
dataMap
.
get
(
"access_token"
);
String
openid
=
(
String
)
dataMap
.
get
(
"openid"
);
if
(
accessToken
==
null
||
accessToken
.
isEmpty
())
{
return
JsonResult
.
failed
(
"获取accessToken失败:"
,
dataMap
);
}
//返回了openid等信息 根据openid去查询 如果没有则去新增
AtlUser
atlUser
=
atlUserMapper
.
getByOpenId
(
openid
);
//如果是新用户 需要去绑定手机号 和 密码
if
(
atlUser
==
null
)
{
return
JsonResult
.
failed
(
""
,
dataMap
);
}
else
{
//否则有查询到 就登录成功
LoginUserDto
loginUserDto
=
new
LoginUserDto
();
String
token
=
UUID
.
randomUUID
().
toString
();
redisUtil
.
set
(
token
,
atlUser
,
Long
.
valueOf
(
604800
));
loginUserDto
.
setToken
(
token
);
loginUserDto
.
setAvatarUrl
(
atlUser
.
getAvaterImageUrl
());
loginUserDto
.
setNickName
(
atlUser
.
getNickName
());
loginUserDto
.
setPhone
(
atlUser
.
getMobilePhone
());
loginUserDto
.
setOpenId
(
atlUser
.
getOpenId
());
return
JsonResult
.
success
(
"登录成功"
,
loginUserDto
);
}
//{"success":true,"status":"200","message":"获取微信登录链接成功","data":"{\"openid\":\"onUQk6gm0ALTXFtddQrikfhmivR0\",\"nickname\":\"夏侯\",\"sex\":1,\"language\":\"zh_CN\",\"city\":\"Xiamen\",\"province\":\"Fujian\",\"country\":\"CN\",
// \"headimgurl\":\"https:\\/\\/thirdwx.qlogo.cn\\/mmopen\\/vi_32\\/Q0j4TwGTfTJqDjxLLVtSwibic5QqiboyfKMRE033kX8066jl1VDFBC0shBnu5n7a7QuicJ7EYGQ0GepAlzlianCohEQ\\/132\",\"privilege\":[],\"unionid\":\"oMKkr6Dkxr4gwkAJBAkd4ctJprWg\"}\r\n"}
}
/**
* 新增绑定用户手机号等
*
* @param wxInsertUserParam
* @return
*/
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
JsonResult
insertAtlUserByWxLogin
(
WxInsertUserParam
wxInsertUserParam
)
{
JsonResult
res
=
this
.
checkWxInsertUserParam
(
wxInsertUserParam
);
if
(
res
.
getStatus
().
equals
(
Constants
.
RESPONSE_STATUS_500
))
{
return
res
;
}
//获取用户信息数据
String
userInfoRes
=
HttpUtils
.
get
(
getUserInfoUrl
+
"?access_token="
+
wxInsertUserParam
.
getAccessToken
()
+
"&openid="
+
wxInsertUserParam
.
getOpenid
());
Map
userMap
=
(
Map
)
JSON
.
parse
(
userInfoRes
);
String
openid2
=
(
String
)
userMap
.
get
(
"openid"
);
//判断是否有误返回用户信息 通过openid来判断
if
(
openid2
==
null
||
openid2
.
isEmpty
())
{
return
JsonResult
.
failed
(
"获取用户信息失败:"
+
userMap
);
}
//向数据库写入会员信息
AtlUser
insertAtlUser
=
new
AtlUser
();
insertAtlUser
.
setNickName
(
userMap
.
get
(
"nickname"
)
+
""
);
insertAtlUser
.
setOpenId
(
userMap
.
get
(
"openid"
)
+
""
);
insertAtlUser
.
setAvaterImageUrl
(
userMap
.
get
(
"headimgurl"
)
+
""
);
insertAtlUser
.
setState
(
1
);
insertAtlUser
.
setSex
((
Integer
)
userMap
.
get
(
"sex"
));
insertAtlUser
.
setMobilePhone
(
wxInsertUserParam
.
getMobilePhone
());
insertAtlUser
.
setLoginPassword
(
DigestUtils
.
md5Hex
(
wxInsertUserParam
.
getLoginPassword
()));
this
.
atlUserMapper
.
insert
(
insertAtlUser
);
//返回对象数据
LoginUserDto
loginUserDto
=
new
LoginUserDto
();
String
token
=
UUID
.
randomUUID
().
toString
();
redisUtil
.
set
(
token
,
insertAtlUser
,
Long
.
valueOf
(
604800
));
loginUserDto
.
setToken
(
token
);
loginUserDto
.
setAvatarUrl
(
insertAtlUser
.
getAvaterImageUrl
());
loginUserDto
.
setNickName
(
insertAtlUser
.
getNickName
());
loginUserDto
.
setPhone
(
insertAtlUser
.
getMobilePhone
());
loginUserDto
.
setOpenId
(
insertAtlUser
.
getOpenId
());
return
JsonResult
.
success
(
"绑定手机号登录成功"
,
loginUserDto
);
}
/**
* 校验通过
*
* @param wxInsertUserParam
* @return
*/
private
JsonResult
checkWxInsertUserParam
(
WxInsertUserParam
wxInsertUserParam
)
{
if
(
wxInsertUserParam
.
getAccessToken
()
==
null
||
wxInsertUserParam
.
getAccessToken
().
isEmpty
())
{
return
JsonResult
.
failed
(
"传入accessToken为空"
);
}
if
(
wxInsertUserParam
.
getOpenid
()
==
null
||
wxInsertUserParam
.
getOpenid
().
isEmpty
())
{
return
JsonResult
.
failed
(
"传入openid为空"
);
}
if
(
wxInsertUserParam
.
getMobilePhone
()
==
null
||
wxInsertUserParam
.
getMobilePhone
().
isEmpty
())
{
return
JsonResult
.
failed
(
"传入mobilePhone为空"
);
}
if
(
wxInsertUserParam
.
getLoginPassword
()
==
null
||
wxInsertUserParam
.
getLoginPassword
().
isEmpty
())
{
return
JsonResult
.
failed
(
"传入loginPassword为空"
);
}
if
(
wxInsertUserParam
.
getVerifyCode
()
==
null
||
wxInsertUserParam
.
getVerifyCode
().
isEmpty
())
{
return
JsonResult
.
failed
(
"传入验证码为空"
);
}
else
{
Sms
sms
=
smsMapper
.
getSmsVerifyCode
(
wxInsertUserParam
.
getMobilePhone
(),
wxInsertUserParam
.
getVerifyCode
(),
1
);
if
(
sms
==
null
)
{
throw
new
BusinessException
(
"验证码错误"
);
}
}
return
JsonResult
.
success
(
"校验通过"
);
}
}
src/main/java/com/hwstudio/antaile/utils/HttpUtil.java
0 → 100644
View file @
ae04051b
package
com
.
hwstudio
.
antaile
.
utils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
javax.net.ssl.*
;
import
java.io.*
;
import
java.net.*
;
import
java.security.cert.X509Certificate
;
/**
* 通用http发送方法
*
* @author kachexing
*/
public
class
HttpUtil
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
HttpUtils
.
class
);
/**
* 向指定 URL 发送GET方法的请求
*
* @param url 发送请求的 URL
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
* @return 所代表远程资源的响应结果
*/
public
static
String
sendGet
(
String
url
,
String
param
)
{
return
sendGet
(
url
,
param
,
"UTF-8"
);
}
/**
* 向指定 URL 发送GET方法的请求
*
* @param url 发送请求的 URL
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
* @param contentType 编码类型
* @return 所代表远程资源的响应结果
*/
public
static
String
sendGet
(
String
url
,
String
param
,
String
contentType
)
{
StringBuilder
result
=
new
StringBuilder
();
BufferedReader
in
=
null
;
try
{
String
urlNameString
=
url
+
"?"
+
param
;
log
.
info
(
"sendGet - {}"
,
urlNameString
);
URL
realUrl
=
new
URL
(
urlNameString
);
URLConnection
connection
=
realUrl
.
openConnection
();
connection
.
setRequestProperty
(
"accept"
,
"*/*"
);
connection
.
setRequestProperty
(
"connection"
,
"Keep-Alive"
);
connection
.
setRequestProperty
(
"user-agent"
,
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"
);
connection
.
connect
();
in
=
new
BufferedReader
(
new
InputStreamReader
(
connection
.
getInputStream
(),
contentType
));
String
line
;
while
((
line
=
in
.
readLine
())
!=
null
)
{
result
.
append
(
line
);
}
log
.
info
(
"recv - {}"
,
result
);
}
catch
(
ConnectException
e
)
{
log
.
error
(
"调用HttpUtils.sendGet ConnectException, url="
+
url
+
",param="
+
param
,
e
);
}
catch
(
SocketTimeoutException
e
)
{
log
.
error
(
"调用HttpUtils.sendGet SocketTimeoutException, url="
+
url
+
",param="
+
param
,
e
);
}
catch
(
IOException
e
)
{
log
.
error
(
"调用HttpUtils.sendGet IOException, url="
+
url
+
",param="
+
param
,
e
);
}
catch
(
Exception
e
)
{
log
.
error
(
"调用HttpsUtil.sendGet Exception, url="
+
url
+
",param="
+
param
,
e
);
}
finally
{
try
{
if
(
in
!=
null
)
{
in
.
close
();
}
}
catch
(
Exception
ex
)
{
log
.
error
(
"调用in.close Exception, url="
+
url
+
",param="
+
param
,
ex
);
}
}
return
result
.
toString
();
}
/**
* 向指定 URL 发送POST方法的请求
*
* @param url 发送请求的 URL
* @param param 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
* @return 所代表远程资源的响应结果
*/
public
static
String
sendPost
(
String
url
,
String
param
)
{
PrintWriter
out
=
null
;
BufferedReader
in
=
null
;
StringBuilder
result
=
new
StringBuilder
();
try
{
String
urlNameString
=
url
;
log
.
info
(
"sendPost - {}"
,
urlNameString
);
URL
realUrl
=
new
URL
(
urlNameString
);
URLConnection
conn
=
realUrl
.
openConnection
();
conn
.
setRequestProperty
(
"accept"
,
"*/*"
);
conn
.
setRequestProperty
(
"connection"
,
"Keep-Alive"
);
conn
.
setRequestProperty
(
"user-agent"
,
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)"
);
conn
.
setRequestProperty
(
"Accept-Charset"
,
"utf-8"
);
conn
.
setRequestProperty
(
"contentType"
,
"utf-8"
);
conn
.
setDoOutput
(
true
);
conn
.
setDoInput
(
true
);
out
=
new
PrintWriter
(
conn
.
getOutputStream
());
out
.
print
(
param
);
out
.
flush
();
in
=
new
BufferedReader
(
new
InputStreamReader
(
conn
.
getInputStream
(),
"utf-8"
));
String
line
;
while
((
line
=
in
.
readLine
())
!=
null
)
{
result
.
append
(
line
);
}
log
.
info
(
"recv - {}"
,
result
);
}
catch
(
ConnectException
e
)
{
log
.
error
(
"调用HttpUtils.sendPost ConnectException, url="
+
url
+
",param="
+
param
,
e
);
}
catch
(
SocketTimeoutException
e
)
{
log
.
error
(
"调用HttpUtils.sendPost SocketTimeoutException, url="
+
url
+
",param="
+
param
,
e
);
}
catch
(
IOException
e
)
{
log
.
error
(
"调用HttpUtils.sendPost IOException, url="
+
url
+
",param="
+
param
,
e
);
}
catch
(
Exception
e
)
{
log
.
error
(
"调用HttpsUtil.sendPost Exception, url="
+
url
+
",param="
+
param
,
e
);
}
finally
{
try
{
if
(
out
!=
null
)
{
out
.
close
();
}
if
(
in
!=
null
)
{
in
.
close
();
}
}
catch
(
IOException
ex
)
{
log
.
error
(
"调用in.close Exception, url="
+
url
+
",param="
+
param
,
ex
);
}
}
return
result
.
toString
();
}
//请求方法
public
static
String
httpsRequest
(
String
requestUrl
,
String
requestMethod
,
String
outputStr
)
{
try
{
URL
url
=
new
URL
(
requestUrl
);
HttpURLConnection
conn
=
(
HttpURLConnection
)
url
.
openConnection
();
conn
.
setDoOutput
(
true
);
conn
.
setDoInput
(
true
);
conn
.
setUseCaches
(
false
);
// 设置请求方式(GET/POST)
conn
.
setRequestMethod
(
requestMethod
);
conn
.
setRequestProperty
(
"content-type"
,
"application/x-www-form-urlencoded"
);
// 当outputStr不为null时向输出流写数据
if
(
null
!=
outputStr
)
{
OutputStream
outputStream
=
conn
.
getOutputStream
();
// 注意编码格式
outputStream
.
write
(
outputStr
.
getBytes
(
"UTF-8"
));
outputStream
.
close
();
}
// 从输入流读取返回内容
InputStream
inputStream
=
conn
.
getInputStream
();
InputStreamReader
inputStreamReader
=
new
InputStreamReader
(
inputStream
,
"utf-8"
);
BufferedReader
bufferedReader
=
new
BufferedReader
(
inputStreamReader
);
String
str
=
null
;
StringBuffer
buffer
=
new
StringBuffer
();
while
((
str
=
bufferedReader
.
readLine
())
!=
null
)
{
buffer
.
append
(
str
);
}
// 释放资源
bufferedReader
.
close
();
inputStreamReader
.
close
();
inputStream
.
close
();
conn
.
disconnect
();
return
buffer
.
toString
();
}
catch
(
ConnectException
ce
)
{
System
.
out
.
println
(
"连接超时:{}"
+
ce
);
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"https请求异常:{}"
+
e
);
}
return
null
;
}
}
src/main/java/com/hwstudio/antaile/utils/JsonResult.java
View file @
ae04051b
...
...
@@ -58,6 +58,14 @@ public class JsonResult {
return
res
;
}
public
static
JsonResult
failed
(
String
msg
,
Object
data
)
{
JsonResult
res
=
new
JsonResult
();
res
.
setMessage
(
msg
);
res
.
setStatus
(
Constants
.
RESPONSE_STATUS_500
);
res
.
setData
(
data
);
return
res
;
}
public
static
JsonResult
notLogin
()
{
JsonResult
res
=
new
JsonResult
();
res
.
setMessage
(
"请登录"
);
...
...
src/main/resources/application.yml
View file @
ae04051b
...
...
@@ -69,6 +69,11 @@ spring:
min-idle
:
0
# 连接超时时间(毫秒)
timeout
:
5000
wx
:
#此处为微信开放平台的相关参数
appid
:
wx27928349186b6267
appSecret
:
dee9b11ee545bff614abc91ebb042127
redirectUri
:
http://31673rv944.51vip.biz/atlApp/wx/getQrcodeAndState
server
:
port
:
8088
...
...
src/main/resources/mapping/AtlTimeMapper.xml
View file @
ae04051b
...
...
@@ -264,5 +264,27 @@
where id = #{id}
</update>
<select
id=
"selectOfficialWebsiteAtlTime"
resultType=
"com.hwstudio.antaile.dto.OfficialWebsiteAtlTimeVO"
parameterType=
"com.hwstudio.antaile.dto.OfficialWebsiteAtlTimeParam"
>
select
a.id,a.template_id templateId,a.name,a.cover_url coverUrl
from atl_time a
where a.status = 1
<if
test=
"isCommend != null"
>
and a.is_commend =#{isCommend}
</if>
order by a.create_date desc
</select>
<select
id=
"selectRandomAtlTime"
resultType=
"com.hwstudio.antaile.dto.OfficialWebsiteAtlTimeVO"
>
SELECT
a.id,a.template_id templateId,a.name,a.cover_url coverUrl
FROM
atl_time a
where a.status = 1
and a.is_commend = 1
ORDER BY RAND()
LIMIT 3
</select>
</mapper>
\ No newline at end of file
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