Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
江名洋
/
linkwe-scrm
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit ce192681
authored
Apr 07, 2021
by
danmo
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
微信授权接口及拦截器修改
1 parent
7bdd048c
Hide whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
546 additions
and
27 deletions
linkwe-admin/src/main/java/com/linkwechat/web/controller/weixin/WxAuthController.java
linkwe-common/src/main/java/com/linkwechat/common/constant/WeConstans.java
linkwe-framework/src/main/java/com/linkwechat/framework/config/SecurityConfig.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeAccessTokenClient.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeAppClient.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeCropTagClient.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeCustomerClient.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeCustomerGroupClient.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeCustomerMessagePushClient.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeDepartMentClient.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeExternalContactClient.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeMediaClient.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeMessagePushClient.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeMsgAuditClient.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeTicketClient.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeUserClient.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/weixin/dto/WxAuthUserInfoDto.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/weixin/dto/WxBaseResultDto.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/weixin/dto/WxTokenDto.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/interceptor/WeAccessTokenInterceptor.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/interceptor/WeiXinAccessTokenInterceptor.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/interceptor/WeiXinAuthInterceptor.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWxAuthService.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/IWxAuthServiceImpl.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/wxclient/WxAuthClient.java
linkwe-wecom/src/main/java/com/linkwechat/wecom/wxclient/WxCommonClient.java
linkwe-admin/src/main/java/com/linkwechat/web/controller/weixin/WxAuthController.java
0 → 100644
View file @
ce19268
package
com
.
linkwechat
.
web
.
controller
.
weixin
;
import
com.linkwechat.common.core.domain.AjaxResult
;
import
com.linkwechat.web.controller.common.CommonController
;
import
com.linkwechat.wecom.domain.weixin.dto.WxAuthUserInfoDto
;
import
com.linkwechat.wecom.domain.weixin.dto.WxTokenDto
;
import
com.linkwechat.wecom.service.IWxAuthService
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiParam
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* @author danmo
* @description 微信授权controller
* @date 2021/4/5 18:37
**/
@Api
(
"微信授权controller"
)
@Slf4j
@RestController
@RequestMapping
(
"/weixin/auth"
)
public
class
WxAuthController
extends
CommonController
{
@Autowired
private
IWxAuthService
wxAuthService
;
/**
* 通过code获取网页授权token
*/
@ApiOperation
(
value
=
"通过code获取网页授权token"
,
httpMethod
=
"GET"
)
@GetMapping
(
"/getToken"
)
public
AjaxResult
<
WxTokenDto
>
getToken
(
@ApiParam
(
value
=
"URL上的code参数"
,
required
=
true
)
String
code
,
@ApiParam
(
value
=
"用户的唯一标识"
,
required
=
true
)
String
openId
)
{
return
AjaxResult
.
success
(
wxAuthService
.
getToken
(
code
,
openId
));
}
/**
* 拉取用户信息(需scope为 snsapi_userinfo)
*/
@ApiOperation
(
value
=
"拉取用户信息(需scope为 snsapi_userinfo)"
,
httpMethod
=
"GET"
)
@GetMapping
(
"/getUserInfo"
)
public
AjaxResult
<
WxAuthUserInfoDto
>
getUserInfo
(
@ApiParam
(
value
=
"用户的唯一标识"
,
required
=
true
)
String
openId
,
@ApiParam
(
value
=
"语言版本"
,
required
=
true
)
String
lang
)
{
return
AjaxResult
.
success
(
wxAuthService
.
getUserInfo
(
openId
,
lang
));
}
}
linkwe-common/src/main/java/com/linkwechat/common/constant/WeConstans.java
View file @
ce19268
...
@@ -14,6 +14,17 @@ import java.util.Map;
...
@@ -14,6 +14,17 @@ import java.util.Map;
public
class
WeConstans
{
public
class
WeConstans
{
/**
/**
* 微信授权token
*/
public
static
final
String
WX_AUTH_ACCESS_TOKEN
=
"wx_auth_access_token"
;
public
static
final
String
WX_AUTH_REFRESH_ACCESS_TOKEN
=
"wx_auth_refresh_access_token"
;
/**
* 微信通用token
*/
public
static
final
String
WX_ACCESS_TOKEN
=
"wx_access_token"
;
/**
* 企业微信相关token
* 企业微信相关token
*/
*/
public
static
final
String
WE_COMMON_ACCESS_TOKEN
=
"we_common_access_token"
;
public
static
final
String
WE_COMMON_ACCESS_TOKEN
=
"we_common_access_token"
;
...
...
linkwe-framework/src/main/java/com/linkwechat/framework/config/SecurityConfig.java
View file @
ce19268
...
@@ -128,7 +128,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
...
@@ -128,7 +128,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
// 获取实际群活码和社群运营H5页面不需要登录
// 获取实际群活码和社群运营H5页面不需要登录
.
antMatchers
(
"/wecom/groupCode/getActualCode/**"
).
anonymous
()
.
antMatchers
(
"/wecom/groupCode/getActualCode/**"
).
anonymous
()
.
antMatchers
(
"/wecom/community/h5/**"
).
anonymous
()
.
antMatchers
(
"/wecom/community/h5/**"
).
anonymous
()
//微信授权接口
.
antMatchers
(
"/weixin/auth/**"
).
anonymous
()
// 除上面外的所有请求全部需要鉴权认证
// 除上面外的所有请求全部需要鉴权认证
.
anyRequest
().
authenticated
()
.
anyRequest
().
authenticated
()
.
and
()
.
and
()
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeAccessTokenClient.java
View file @
ce19268
package
com
.
linkwechat
.
wecom
.
client
;
package
com
.
linkwechat
.
wecom
.
client
;
import
com.dtflys.forest.annotation.BaseRequest
;
import
com.dtflys.forest.annotation.Body
;
import
com.dtflys.forest.annotation.Body
;
import
com.dtflys.forest.annotation.Query
;
import
com.dtflys.forest.annotation.Query
;
import
com.dtflys.forest.annotation.Request
;
import
com.dtflys.forest.annotation.Request
;
import
com.linkwechat.wecom.domain.dto.WeAccessTokenDtoDto
;
import
com.linkwechat.wecom.domain.dto.WeAccessTokenDtoDto
;
import
com.linkwechat.wecom.domain.dto.WeLoginUserInfoDto
;
import
com.linkwechat.wecom.domain.dto.WeLoginUserInfoDto
;
import
com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor
;
/**
/**
* @description: 获取企业微信Token相关
* @description: 获取企业微信Token相关
* @author: HaoN
* @author: HaoN
* @create: 2020-08-26 14:33
* @create: 2020-08-26 14:33
**/
**/
@BaseRequest
(
interceptor
=
WeAccessTokenInterceptor
.
class
)
public
interface
WeAccessTokenClient
{
public
interface
WeAccessTokenClient
{
/**
/**
* 获取token(常用token,联系人token)
* 获取token(常用token,联系人token)
* @param corpId 企业id
* @param corpId 企业id
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeAppClient.java
View file @
ce19268
package
com
.
linkwechat
.
wecom
.
client
;
package
com
.
linkwechat
.
wecom
.
client
;
import
com.dtflys.forest.annotation.BaseRequest
;
import
com.dtflys.forest.annotation.DataObject
;
import
com.dtflys.forest.annotation.DataObject
;
import
com.dtflys.forest.annotation.Query
;
import
com.dtflys.forest.annotation.Query
;
import
com.dtflys.forest.annotation.Request
;
import
com.dtflys.forest.annotation.Request
;
import
com.linkwechat.wecom.domain.dto.WeAppDetailDto
;
import
com.linkwechat.wecom.domain.dto.WeAppDetailDto
;
import
com.linkwechat.wecom.domain.dto.WeAppDto
;
import
com.linkwechat.wecom.domain.dto.WeAppDto
;
import
com.linkwechat.wecom.domain.dto.WeResultDto
;
import
com.linkwechat.wecom.domain.dto.WeResultDto
;
import
com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor
;
/**
/**
* 应用管理相关接口
* 应用管理相关接口
*/
*/
@BaseRequest
(
interceptor
=
WeAccessTokenInterceptor
.
class
)
public
interface
WeAppClient
{
public
interface
WeAppClient
{
/**
/**
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeCropTagClient.java
View file @
ce19268
package
com
.
linkwechat
.
wecom
.
client
;
package
com
.
linkwechat
.
wecom
.
client
;
import
com.dtflys.forest.annotation.BaseRequest
;
import
com.dtflys.forest.annotation.Body
;
import
com.dtflys.forest.annotation.Body
;
import
com.dtflys.forest.annotation.DataObject
;
import
com.dtflys.forest.annotation.DataObject
;
import
com.dtflys.forest.annotation.Request
;
import
com.dtflys.forest.annotation.Request
;
import
com.linkwechat.wecom.domain.dto.WeResultDto
;
import
com.linkwechat.wecom.domain.dto.WeResultDto
;
import
com.linkwechat.wecom.domain.dto.tag.*
;
import
com.linkwechat.wecom.domain.dto.tag.*
;
import
com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor
;
/**
/**
* @description: 企业微信标签相关
* @description: 企业微信标签相关
* @author: HaoN
* @author: HaoN
* @create: 2020-10-17 11:00
* @create: 2020-10-17 11:00
**/
**/
@BaseRequest
(
interceptor
=
WeAccessTokenInterceptor
.
class
)
public
interface
WeCropTagClient
{
public
interface
WeCropTagClient
{
/**
/**
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeCustomerClient.java
View file @
ce19268
package
com
.
linkwechat
.
wecom
.
client
;
package
com
.
linkwechat
.
wecom
.
client
;
import
com.dtflys.forest.annotation.DataObject
;
import
com.dtflys.forest.annotation.*
;
import
com.dtflys.forest.annotation.JSONBody
;
import
com.dtflys.forest.annotation.Query
;
import
com.dtflys.forest.annotation.Request
;
import
com.linkwechat.wecom.domain.dto.*
;
import
com.linkwechat.wecom.domain.dto.*
;
import
com.linkwechat.wecom.domain.dto.customer.*
;
import
com.linkwechat.wecom.domain.dto.customer.*
;
import
com.linkwechat.wecom.domain.query.GroupChatStatisticQuery
;
import
com.linkwechat.wecom.domain.query.GroupChatStatisticQuery
;
import
com.linkwechat.wecom.domain.query.UserBehaviorDataQuery
;
import
com.linkwechat.wecom.domain.query.UserBehaviorDataQuery
;
import
com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -17,6 +15,7 @@ import java.util.Map;
...
@@ -17,6 +15,7 @@ import java.util.Map;
* @author: HaoN
* @author: HaoN
* @create: 2020-09-15 14:15
* @create: 2020-09-15 14:15
**/
**/
@BaseRequest
(
interceptor
=
WeAccessTokenInterceptor
.
class
)
public
interface
WeCustomerClient
{
public
interface
WeCustomerClient
{
/**
/**
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeCustomerGroupClient.java
View file @
ce19268
package
com
.
linkwechat
.
wecom
.
client
;
package
com
.
linkwechat
.
wecom
.
client
;
import
com.dtflys.forest.annotation.BaseRequest
;
import
com.dtflys.forest.annotation.DataObject
;
import
com.dtflys.forest.annotation.DataObject
;
import
com.dtflys.forest.annotation.Query
;
import
com.dtflys.forest.annotation.Query
;
import
com.dtflys.forest.annotation.Request
;
import
com.dtflys.forest.annotation.Request
;
import
com.linkwechat.wecom.domain.dto.customer.CustomerGroupDetail
;
import
com.linkwechat.wecom.domain.dto.customer.CustomerGroupDetail
;
import
com.linkwechat.wecom.domain.dto.customer.CustomerGroupList
;
import
com.linkwechat.wecom.domain.dto.customer.CustomerGroupList
;
import
com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor
;
/**
/**
* @description: 客户群
* @description: 客户群
* @author: HaoN
* @author: HaoN
* @create: 2020-10-20 21:50
* @create: 2020-10-20 21:50
**/
**/
@BaseRequest
(
interceptor
=
WeAccessTokenInterceptor
.
class
)
public
interface
WeCustomerGroupClient
{
public
interface
WeCustomerGroupClient
{
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeCustomerMessagePushClient.java
View file @
ce19268
package
com
.
linkwechat
.
wecom
.
client
;
package
com
.
linkwechat
.
wecom
.
client
;
import
com.dtflys.forest.annotation.Body
;
import
com.dtflys.forest.annotation.*
;
import
com.dtflys.forest.annotation.DataObject
;
import
com.dtflys.forest.annotation.Query
;
import
com.dtflys.forest.annotation.Request
;
import
com.linkwechat.wecom.domain.dto.message.QueryCustomerMessageStatusResultDataObjectDto
;
import
com.linkwechat.wecom.domain.dto.message.QueryCustomerMessageStatusResultDataObjectDto
;
import
com.linkwechat.wecom.domain.dto.message.QueryCustomerMessageStatusResultDto
;
import
com.linkwechat.wecom.domain.dto.message.QueryCustomerMessageStatusResultDto
;
import
com.linkwechat.wecom.domain.dto.message.SendMessageResultDto
;
import
com.linkwechat.wecom.domain.dto.message.SendMessageResultDto
;
import
com.linkwechat.wecom.domain.dto.message.WeCustomerMessagePushDto
;
import
com.linkwechat.wecom.domain.dto.message.WeCustomerMessagePushDto
;
import
com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor
;
/**
/**
* @description: 群发消息
* @description: 群发消息
* @author: KeWen
* @author: KeWen
* @create: 2020-10-25 21:34
* @create: 2020-10-25 21:34
**/
**/
@BaseRequest
(
interceptor
=
WeAccessTokenInterceptor
.
class
)
public
interface
WeCustomerMessagePushClient
{
public
interface
WeCustomerMessagePushClient
{
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeDepartMentClient.java
View file @
ce19268
package
com
.
linkwechat
.
wecom
.
client
;
package
com
.
linkwechat
.
wecom
.
client
;
import
com.dtflys.forest.annotation.BaseRequest
;
import
com.dtflys.forest.annotation.DataObject
;
import
com.dtflys.forest.annotation.DataObject
;
import
com.dtflys.forest.annotation.Query
;
import
com.dtflys.forest.annotation.Query
;
import
com.dtflys.forest.annotation.Request
;
import
com.dtflys.forest.annotation.Request
;
import
com.linkwechat.wecom.domain.dto.WeDepartMentDto
;
import
com.linkwechat.wecom.domain.dto.WeDepartMentDto
;
import
com.linkwechat.wecom.domain.dto.WeResultDto
;
import
com.linkwechat.wecom.domain.dto.WeResultDto
;
import
com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor
;
/**
/**
* @description: 企业微信部门相关客户端
* @description: 企业微信部门相关客户端
* @author: HaoN
* @author: HaoN
* @create: 2020-08-27 16:40
* @create: 2020-08-27 16:40
**/
**/
@BaseRequest
(
interceptor
=
WeAccessTokenInterceptor
.
class
)
public
interface
WeDepartMentClient
{
public
interface
WeDepartMentClient
{
/**
/**
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeExternalContactClient.java
View file @
ce19268
package
com
.
linkwechat
.
wecom
.
client
;
package
com
.
linkwechat
.
wecom
.
client
;
import
com.dtflys.forest.annotation.BaseRequest
;
import
com.dtflys.forest.annotation.DataObject
;
import
com.dtflys.forest.annotation.DataObject
;
import
com.dtflys.forest.annotation.Query
;
import
com.dtflys.forest.annotation.Query
;
import
com.dtflys.forest.annotation.Request
;
import
com.dtflys.forest.annotation.Request
;
import
com.linkwechat.wecom.domain.dto.WeExternalContactDto
;
import
com.linkwechat.wecom.domain.dto.WeExternalContactDto
;
import
com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor
;
/**
/**
* @description: 员工对外联系方式
* @description: 员工对外联系方式
* @author: HaoN
* @author: HaoN
* @create: 2020-10-13 10:39
* @create: 2020-10-13 10:39
**/
**/
@BaseRequest
(
interceptor
=
WeAccessTokenInterceptor
.
class
)
public
interface
WeExternalContactClient
{
public
interface
WeExternalContactClient
{
@Request
(
url
=
"/externalcontact/add_contact_way"
,
@Request
(
url
=
"/externalcontact/add_contact_way"
,
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeMediaClient.java
View file @
ce19268
package
com
.
linkwechat
.
wecom
.
client
;
package
com
.
linkwechat
.
wecom
.
client
;
import
com.dtflys.forest.annotation.BaseRequest
;
import
com.dtflys.forest.annotation.DataFile
;
import
com.dtflys.forest.annotation.DataFile
;
import
com.dtflys.forest.annotation.Post
;
import
com.dtflys.forest.annotation.Post
;
import
com.dtflys.forest.annotation.Query
;
import
com.dtflys.forest.annotation.Query
;
import
com.linkwechat.wecom.domain.dto.WeMediaDto
;
import
com.linkwechat.wecom.domain.dto.WeMediaDto
;
import
com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor
;
import
org.springframework.web.multipart.MultipartFile
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.File
;
import
java.io.File
;
...
@@ -15,6 +17,7 @@ import java.io.InputStream;
...
@@ -15,6 +17,7 @@ import java.io.InputStream;
* @Description:
* @Description:
* @Date: create in 2020/9/24 0024 0:14
* @Date: create in 2020/9/24 0024 0:14
*/
*/
@BaseRequest
(
interceptor
=
WeAccessTokenInterceptor
.
class
)
public
interface
WeMediaClient
{
public
interface
WeMediaClient
{
/**
/**
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeMessagePushClient.java
View file @
ce19268
package
com
.
linkwechat
.
wecom
.
client
;
package
com
.
linkwechat
.
wecom
.
client
;
import
com.dtflys.forest.annotation.BaseRequest
;
import
com.dtflys.forest.annotation.DataObject
;
import
com.dtflys.forest.annotation.DataObject
;
import
com.dtflys.forest.annotation.Header
;
import
com.dtflys.forest.annotation.Header
;
import
com.dtflys.forest.annotation.Request
;
import
com.dtflys.forest.annotation.Request
;
import
com.linkwechat.wecom.domain.dto.WeMessagePushDto
;
import
com.linkwechat.wecom.domain.dto.WeMessagePushDto
;
import
com.linkwechat.wecom.domain.dto.WeMessagePushGroupDto
;
import
com.linkwechat.wecom.domain.dto.WeMessagePushGroupDto
;
import
com.linkwechat.wecom.domain.dto.WeMessagePushResultDto
;
import
com.linkwechat.wecom.domain.dto.WeMessagePushResultDto
;
import
com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor
;
/**
/**
* @description: 消息推送
* @description: 消息推送
...
@@ -13,6 +15,7 @@ import com.linkwechat.wecom.domain.dto.WeMessagePushResultDto;
...
@@ -13,6 +15,7 @@ import com.linkwechat.wecom.domain.dto.WeMessagePushResultDto;
* @create: 2020-10-17 22:41
* @create: 2020-10-17 22:41
**/
**/
@SuppressWarnings
(
"all"
)
@SuppressWarnings
(
"all"
)
@BaseRequest
(
interceptor
=
WeAccessTokenInterceptor
.
class
)
public
interface
WeMessagePushClient
{
public
interface
WeMessagePushClient
{
/**
/**
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeMsgAuditClient.java
View file @
ce19268
package
com
.
linkwechat
.
wecom
.
client
;
package
com
.
linkwechat
.
wecom
.
client
;
import
com.dtflys.forest.annotation.BaseRequest
;
import
com.dtflys.forest.annotation.DataObject
;
import
com.dtflys.forest.annotation.DataObject
;
import
com.dtflys.forest.annotation.DataVariable
;
import
com.dtflys.forest.annotation.DataVariable
;
import
com.dtflys.forest.annotation.Request
;
import
com.dtflys.forest.annotation.Request
;
import
com.linkwechat.wecom.domain.dto.msgaudit.WeMsgAuditDto
;
import
com.linkwechat.wecom.domain.dto.msgaudit.WeMsgAuditDto
;
import
com.linkwechat.wecom.domain.vo.WeMsgAuditVo
;
import
com.linkwechat.wecom.domain.vo.WeMsgAuditVo
;
import
com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor
;
/**
/**
* @author danmo
* @author danmo
* @description 会话存档接口
* @description 会话存档接口
* @date 2020/12/2 16:45
* @date 2020/12/2 16:45
**/
**/
@BaseRequest
(
interceptor
=
WeAccessTokenInterceptor
.
class
)
public
interface
WeMsgAuditClient
{
public
interface
WeMsgAuditClient
{
/**
/**
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeTicketClient.java
View file @
ce19268
package
com
.
linkwechat
.
wecom
.
client
;
package
com
.
linkwechat
.
wecom
.
client
;
import
com.dtflys.forest.annotation.BaseRequest
;
import
com.dtflys.forest.annotation.Header
;
import
com.dtflys.forest.annotation.Header
;
import
com.dtflys.forest.annotation.Request
;
import
com.dtflys.forest.annotation.Request
;
import
com.linkwechat.wecom.domain.WeH5TicketDto
;
import
com.linkwechat.wecom.domain.WeH5TicketDto
;
import
com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor
;
/**
/**
* @author danmo
* @author danmo
* @description h5获取签名
* @description h5获取签名
* @date 2021/1/6 11:51
* @date 2021/1/6 11:51
**/
**/
@BaseRequest
(
interceptor
=
WeAccessTokenInterceptor
.
class
)
public
interface
WeTicketClient
{
public
interface
WeTicketClient
{
/**
/**
* 获取去企业jsapi_ticket
* 获取去企业jsapi_ticket
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/client/WeUserClient.java
View file @
ce19268
package
com
.
linkwechat
.
wecom
.
client
;
package
com
.
linkwechat
.
wecom
.
client
;
import
com.dtflys.forest.annotation.DataObject
;
import
com.dtflys.forest.annotation.*
;
import
com.dtflys.forest.annotation.Header
;
import
com.dtflys.forest.annotation.Query
;
import
com.dtflys.forest.annotation.Request
;
import
com.linkwechat.wecom.domain.dto.*
;
import
com.linkwechat.wecom.domain.dto.*
;
import
com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor
;
/**
/**
* @description: 企业微信通讯录成员
* @description: 企业微信通讯录成员
* @author: HaoN
* @author: HaoN
* @create: 2020-08-27 16:42
* @create: 2020-08-27 16:42
**/
**/
@BaseRequest
(
interceptor
=
WeAccessTokenInterceptor
.
class
)
public
interface
WeUserClient
{
public
interface
WeUserClient
{
/**
/**
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/weixin/dto/WxAuthUserInfoDto.java
0 → 100644
View file @
ce19268
package
com
.
linkwechat
.
wecom
.
domain
.
weixin
.
dto
;
import
com.alibaba.fastjson.JSONArray
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
/**
* @author danmo
* @description 授权用户信息
* @date 2021/4/5 16:12
**/
@ApiModel
@Data
public
class
WxAuthUserInfoDto
extends
WxBaseResultDto
{
@ApiModelProperty
(
"用户的唯一标识"
)
private
String
openId
;
@ApiModelProperty
(
"用户昵称"
)
private
String
nickName
;
@ApiModelProperty
(
"用户的性别,值为1时是男性,值为2时是女性,值为0时是未知"
)
private
String
sex
;
@ApiModelProperty
(
"用户个人资料填写的省份"
)
private
String
province
;
@ApiModelProperty
(
"普通用户个人资料填写的城市"
)
private
String
city
;
@ApiModelProperty
(
"国家,如中国为CN"
)
private
String
country
;
@ApiModelProperty
(
"用户头像"
)
private
String
headImgUrl
;
@ApiModelProperty
(
"用户特权信息,json 数组,如微信沃卡用户为(chinaunicom)"
)
private
JSONArray
privilege
;
@ApiModelProperty
(
"只有在用户将公众号绑定到微信开放平台帐号后,才会出现该字段。"
)
private
String
unionId
;
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/weixin/dto/WxBaseResultDto.java
0 → 100644
View file @
ce19268
package
com
.
linkwechat
.
wecom
.
domain
.
weixin
.
dto
;
import
lombok.Data
;
/**
* @author danmo
* @description
* @date 2021/4/5 15:59
**/
@Data
public
class
WxBaseResultDto
{
private
Integer
errcode
;
private
String
errmsg
;
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/domain/weixin/dto/WxTokenDto.java
0 → 100644
View file @
ce19268
package
com
.
linkwechat
.
wecom
.
domain
.
weixin
.
dto
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
/**
* @author danmo
* @description
* @date 2021/4/5 16:01
**/
@ApiModel
@Data
public
class
WxTokenDto
extends
WxBaseResultDto
{
@ApiModelProperty
(
"网页授权接口调用凭证token"
)
private
String
accessToken
;
@ApiModelProperty
(
"超时时间,单位(秒)"
)
private
Integer
expiresIn
;
@ApiModelProperty
(
"用户刷新access_token"
)
private
String
refreshToken
;
@ApiModelProperty
(
"用户唯一标识"
)
private
String
openId
;
@ApiModelProperty
(
"用户授权的作用域,使用逗号(,)分隔"
)
private
String
scope
;
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/interceptor/WeAccessTokenInterceptor.java
View file @
ce19268
...
@@ -40,12 +40,6 @@ public class WeAccessTokenInterceptor implements Interceptor{
...
@@ -40,12 +40,6 @@ public class WeAccessTokenInterceptor implements Interceptor{
*/
*/
@Override
@Override
public
boolean
beforeExecute
(
ForestRequest
request
)
{
public
boolean
beforeExecute
(
ForestRequest
request
)
{
String
uri
=
request
.
getUrl
().
replace
(
"http://"
,
""
);
String
uri
=
request
.
getUrl
().
replace
(
"http://"
,
""
);
log
.
info
(
">>>>>>>>>>>>>>>>>>>>>>>>uri:{}"
,
uri
);
log
.
info
(
">>>>>>>>>>>>>>>>>>>>>>>>uri:{}"
,
uri
);
//request.setContentType("application/json");
//request.setContentType("application/json");
...
@@ -53,9 +47,6 @@ public class WeAccessTokenInterceptor implements Interceptor{
...
@@ -53,9 +47,6 @@ public class WeAccessTokenInterceptor implements Interceptor{
request
.
setDataType
(
ForestDataType
.
JSON
);
request
.
setDataType
(
ForestDataType
.
JSON
);
request
.
setContentType
(
"application/json"
);
request
.
setContentType
(
"application/json"
);
}
}
// 添加请求参数access_token
// 添加请求参数access_token
if
(!
Arrays
.
asList
(
weComeConfig
.
getNoAccessTokenUrl
()).
contains
(
uri
)){
if
(!
Arrays
.
asList
(
weComeConfig
.
getNoAccessTokenUrl
()).
contains
(
uri
)){
String
token
=
""
;
String
token
=
""
;
...
@@ -77,8 +68,6 @@ public class WeAccessTokenInterceptor implements Interceptor{
...
@@ -77,8 +68,6 @@ public class WeAccessTokenInterceptor implements Interceptor{
request
.
addQuery
(
"access_token"
,
token
);
request
.
addQuery
(
"access_token"
,
token
);
}
}
//添加服务器统一请求地址
//添加服务器统一请求地址
request
.
setUrl
(
weComeConfig
.
getServerUrl
()+
weComeConfig
.
getWeComePrefix
()+
uri
);
request
.
setUrl
(
weComeConfig
.
getServerUrl
()+
weComeConfig
.
getWeComePrefix
()+
uri
);
...
...
linkwe-wecom/src/main/java/com/linkwechat/wecom/interceptor/WeiXinAccessTokenInterceptor.java
0 → 100644
View file @
ce19268
package
com
.
linkwechat
.
wecom
.
interceptor
;
import
cn.hutool.json.JSONUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.dtflys.forest.exceptions.ForestRuntimeException
;
import
com.dtflys.forest.http.ForestRequest
;
import
com.dtflys.forest.http.ForestResponse
;
import
com.dtflys.forest.interceptor.Interceptor
;
import
com.dtflys.forest.utils.ForestDataType
;
import
com.linkwechat.common.constant.WeConstans
;
import
com.linkwechat.common.core.redis.RedisCache
;
import
com.linkwechat.common.utils.StringUtils
;
import
com.linkwechat.wecom.domain.weixin.dto.WxBaseResultDto
;
import
com.linkwechat.wecom.domain.weixin.dto.WxTokenDto
;
import
com.linkwechat.wecom.wxclient.WxCommonClient
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
java.util.concurrent.TimeUnit
;
/**
* @author danmo
* @description 微信请求拦截器
* @date 2021/4/5 15:17
**/
@Slf4j
@Component
public
class
WeiXinAccessTokenInterceptor
implements
Interceptor
{
//暂时写到配置文件,之后写入数据库
@Value
(
"${weixin.appid}"
)
private
String
appId
;
@Value
(
"${weixin.secret}"
)
private
String
secret
;
private
final
String
grantType
=
"client_credential"
;
@Autowired
private
WxCommonClient
wxCommonClient
;
@Autowired
private
RedisCache
redisCache
;
@Override
public
boolean
beforeExecute
(
ForestRequest
request
){
request
.
setDataType
(
ForestDataType
.
JSON
);
String
accessToken
=
findAccessToken
();
request
.
addQuery
(
"access_token"
,
accessToken
);
return
true
;
}
private
String
findAccessToken
(){
//获取用户token
String
accessToken
=
redisCache
.
getCacheObject
(
WeConstans
.
WX_ACCESS_TOKEN
);
if
(
StringUtils
.
isEmpty
(
accessToken
)){
//当用户token失效,重新获取token
WxTokenDto
wxTokenDto
=
wxCommonClient
.
getToken
(
grantType
,
appId
,
secret
);
if
(
wxTokenDto
!=
null
&&
StringUtils
.
isNotEmpty
(
wxTokenDto
.
getAccessToken
())){
redisCache
.
setCacheObject
(
WeConstans
.
WX_AUTH_ACCESS_TOKEN
,
wxTokenDto
.
getAccessToken
(),
wxTokenDto
.
getExpiresIn
(),
TimeUnit
.
SECONDS
);
accessToken
=
wxTokenDto
.
getAccessToken
();
}
}
return
accessToken
;
}
/**
* 请求发送失败时被调用
* @param e
* @param request
* @param response
*/
@Override
public
void
onError
(
ForestRuntimeException
e
,
ForestRequest
request
,
ForestResponse
response
)
{
log
.
info
(
"url:{},------params:{},----------result:"
+
request
.
getUrl
(),
JSONObject
.
toJSONString
(
request
.
getArguments
()),
response
.
getContent
());
throw
new
ForestRuntimeException
(
response
.
getContent
());
}
@Override
public
void
onSuccess
(
Object
data
,
ForestRequest
request
,
ForestResponse
response
)
{
log
.
info
(
"url:【{}】,result:【{}】"
,
request
.
getUrl
(),
response
.
getContent
());
WxBaseResultDto
wxBaseResultDto
=
JSONUtil
.
toBean
(
response
.
getContent
(),
WxBaseResultDto
.
class
);
if
(
null
!=
wxBaseResultDto
.
getErrcode
()
&&
!
wxBaseResultDto
.
getErrcode
().
equals
(
WeConstans
.
WE_SUCCESS_CODE
)){
throw
new
ForestRuntimeException
(
response
.
getContent
());
}
}
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/interceptor/WeiXinAuthInterceptor.java
0 → 100644
View file @
ce19268
package
com
.
linkwechat
.
wecom
.
interceptor
;
import
cn.hutool.json.JSONUtil
;
import
com.alibaba.fastjson.JSONObject
;
import
com.dtflys.forest.exceptions.ForestRuntimeException
;
import
com.dtflys.forest.http.ForestRequest
;
import
com.dtflys.forest.http.ForestResponse
;
import
com.dtflys.forest.interceptor.Interceptor
;
import
com.dtflys.forest.utils.ForestDataType
;
import
com.linkwechat.common.constant.WeConstans
;
import
com.linkwechat.common.core.redis.RedisCache
;
import
com.linkwechat.common.exception.wecom.WeComException
;
import
com.linkwechat.common.utils.StringUtils
;
import
com.linkwechat.wecom.domain.weixin.dto.WxTokenDto
;
import
com.linkwechat.wecom.domain.weixin.dto.WxBaseResultDto
;
import
com.linkwechat.wecom.wxclient.WxAuthClient
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
java.util.concurrent.TimeUnit
;
/**
* @author danmo
* @description 微信授权拦截器
* @date 2021/4/5 15:28
**/
@Slf4j
@Component
public
class
WeiXinAuthInterceptor
implements
Interceptor
{
//暂时写到配置文件,之后写入数据库
@Value
(
"${weixin.appid}"
)
private
String
appId
;
@Value
(
"${weixin.secret}"
)
private
String
secret
;
private
final
String
grantType
=
"refresh_token"
;
@Autowired
private
WxAuthClient
wxAuthClient
;
@Autowired
private
RedisCache
redisCache
;
@Override
public
boolean
beforeExecute
(
ForestRequest
request
){
Object
openId
=
request
.
getQuery
(
"openid"
);
request
.
setDataType
(
ForestDataType
.
JSON
);
if
(
openId
!=
null
){
request
.
addQuery
(
"access_token"
,
findAccessToken
(
openId
.
toString
()));
}
return
true
;
}
private
String
findAccessToken
(
String
openId
){
//获取用户token
String
accessToken
=
redisCache
.
getCacheObject
(
WeConstans
.
WX_AUTH_ACCESS_TOKEN
+
":"
+
openId
);
if
(
StringUtils
.
isEmpty
(
accessToken
)){
//当用户token失效,则获取refreshToken
String
refreshToken
=
redisCache
.
getCacheObject
(
WeConstans
.
WX_AUTH_REFRESH_ACCESS_TOKEN
+
":"
+
openId
);
if
(
StringUtils
.
isEmpty
(
refreshToken
)){
throw
new
WeComException
(
1001
,
"token失效,请重新授权"
);
}
else
{
WxTokenDto
wxTokenDto
=
wxAuthClient
.
refreshToken
(
appId
,
secret
,
grantType
,
refreshToken
);
if
(
wxTokenDto
!=
null
&&
StringUtils
.
isNotEmpty
(
wxTokenDto
.
getAccessToken
())){
redisCache
.
setCacheObject
(
WeConstans
.
WX_AUTH_ACCESS_TOKEN
+
":"
+
openId
,
wxTokenDto
.
getAccessToken
(),
wxTokenDto
.
getExpiresIn
(),
TimeUnit
.
SECONDS
);
accessToken
=
wxTokenDto
.
getAccessToken
();
}
}
}
return
accessToken
;
}
/**
* 请求发送失败时被调用
* @param e
* @param request
* @param response
*/
@Override
public
void
onError
(
ForestRuntimeException
e
,
ForestRequest
request
,
ForestResponse
response
)
{
log
.
info
(
"url:{},------params:{},----------result:"
+
request
.
getUrl
(),
JSONObject
.
toJSONString
(
request
.
getArguments
()),
response
.
getContent
());
throw
new
ForestRuntimeException
(
response
.
getContent
());
}
@Override
public
void
onSuccess
(
Object
data
,
ForestRequest
request
,
ForestResponse
response
)
{
log
.
info
(
"url:【{}】,result:【{}】"
,
request
.
getUrl
(),
response
.
getContent
());
WxBaseResultDto
wxBaseResultDto
=
JSONUtil
.
toBean
(
response
.
getContent
(),
WxBaseResultDto
.
class
);
if
(
null
!=
wxBaseResultDto
.
getErrcode
()
&&
!
wxBaseResultDto
.
getErrcode
().
equals
(
WeConstans
.
WE_SUCCESS_CODE
)){
throw
new
ForestRuntimeException
(
response
.
getContent
());
}
}
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/IWxAuthService.java
0 → 100644
View file @
ce19268
package
com
.
linkwechat
.
wecom
.
service
;
import
com.linkwechat.wecom.domain.weixin.dto.WxAuthUserInfoDto
;
import
com.linkwechat.wecom.domain.weixin.dto.WxTokenDto
;
/**
* @author danmo
* @description
* @date 2021/4/5 22:45
**/
public
interface
IWxAuthService
{
WxTokenDto
getToken
(
String
code
,
String
openId
);
WxAuthUserInfoDto
getUserInfo
(
String
openId
,
String
lang
);
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/service/impl/IWxAuthServiceImpl.java
0 → 100644
View file @
ce19268
package
com
.
linkwechat
.
wecom
.
service
.
impl
;
import
com.linkwechat.common.constant.WeConstans
;
import
com.linkwechat.common.core.redis.RedisCache
;
import
com.linkwechat.common.utils.StringUtils
;
import
com.linkwechat.wecom.domain.weixin.dto.WxAuthUserInfoDto
;
import
com.linkwechat.wecom.domain.weixin.dto.WxTokenDto
;
import
com.linkwechat.wecom.service.IWxAuthService
;
import
com.linkwechat.wecom.wxclient.WxAuthClient
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Service
;
import
java.util.concurrent.TimeUnit
;
/**
* @author danmo
* @description
* @date 2021/4/5 22:45
**/
@Slf4j
@Service
public
class
IWxAuthServiceImpl
implements
IWxAuthService
{
@Autowired
private
WxAuthClient
wxAuthClient
;
@Autowired
private
RedisCache
redisCache
;
@Value
(
"${weixin.appid}"
)
private
String
appId
;
@Value
(
"${weixin.secret}"
)
private
String
secret
;
private
final
String
grantType
=
"authorization_code"
;
@Override
public
WxTokenDto
getToken
(
String
code
,
String
openId
)
{
WxTokenDto
authToken
;
if
(
StringUtils
.
isNotEmpty
(
openId
)){
authToken
=
redisCache
.
getCacheObject
(
WeConstans
.
WX_AUTH_ACCESS_TOKEN
+
":"
+
openId
);
}
else
{
authToken
=
wxAuthClient
.
getAuthToken
(
appId
,
secret
,
code
,
grantType
);
if
(
authToken
!=
null
&&
StringUtils
.
isNotEmpty
(
authToken
.
getAccessToken
())){
redisCache
.
setCacheObject
(
WeConstans
.
WX_AUTH_ACCESS_TOKEN
+
":"
+
authToken
.
getOpenId
(),
authToken
,
authToken
.
getExpiresIn
(),
TimeUnit
.
SECONDS
);
redisCache
.
setCacheObject
(
WeConstans
.
WX_AUTH_REFRESH_ACCESS_TOKEN
+
":"
+
authToken
.
getOpenId
(),
authToken
.
getRefreshToken
(),
30
,
TimeUnit
.
DAYS
);
}
}
return
authToken
;
}
@Override
public
WxAuthUserInfoDto
getUserInfo
(
String
openId
,
String
lang
)
{
return
wxAuthClient
.
getUserInfo
(
openId
,
lang
);
}
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/wxclient/WxAuthClient.java
0 → 100644
View file @
ce19268
package
com
.
linkwechat
.
wecom
.
wxclient
;
import
com.dtflys.forest.annotation.BaseRequest
;
import
com.dtflys.forest.annotation.Query
;
import
com.dtflys.forest.annotation.Request
;
import
com.linkwechat.wecom.domain.weixin.dto.WxTokenDto
;
import
com.linkwechat.wecom.domain.weixin.dto.WxAuthUserInfoDto
;
import
com.linkwechat.wecom.interceptor.WeiXinAuthInterceptor
;
/**
* @author danmo
* @description
* @date 2021/4/5 15:47
**/
@BaseRequest
(
baseURL
=
"https://api.weixin.qq.com/sns"
,
contentType
=
"application/json"
,
interceptor
=
WeiXinAuthInterceptor
.
class
)
public
interface
WxAuthClient
{
/**
* 获取微信授权token
*
* @param appId 公众号的唯一标识
* @param secret 密钥
* @param code 302重定向code
* @param grantType 填写为authorization_code
* @return
*/
@Request
(
url
=
"/oauth2/access_token"
,
type
=
"GET"
)
WxTokenDto
getAuthToken
(
@Query
(
"appid"
)
String
appId
,
@Query
(
"secret"
)
String
secret
,
@Query
(
"code"
)
String
code
,
@Query
(
"grant_type"
)
String
grantType
);
/**
* 刷新access_token
*
*
* @param id
* @param appId 公众号的唯一标识
* @param grantType 填写为refresh_token
* @param refreshToken 填写通过access_token获取到的refresh_token参数
* @return
*/
@Request
(
url
=
"/oauth2/refresh_token"
,
type
=
"GET"
)
WxTokenDto
refreshToken
(
String
id
,
@Query
(
"appid"
)
String
appId
,
@Query
(
"grant_type"
)
String
grantType
,
@Query
(
"refresh_token"
)
String
refreshToken
);
/**
* 检验授权凭证(access_token)是否有效
* @param openId 用户的唯一标识
* @return
*/
@Request
(
url
=
"/auth"
,
type
=
"GET"
)
WxTokenDto
auth
(
@Query
(
"openid"
)
String
openId
);
/**
* 拉取用户信息(需scope为 snsapi_userinfo)
* @param openId 用户的唯一标识
* @param lang 返回国家地区语言版本,zh_CN 简体,zh_TW 繁体,en 英语
* @return
*/
@Request
(
url
=
"/userinfo"
,
type
=
"GET"
)
WxAuthUserInfoDto
getUserInfo
(
@Query
(
"openid"
)
String
openId
,
@Query
(
"lang"
)
String
lang
);
}
linkwe-wecom/src/main/java/com/linkwechat/wecom/wxclient/WxCommonClient.java
0 → 100644
View file @
ce19268
package
com
.
linkwechat
.
wecom
.
wxclient
;
import
com.dtflys.forest.annotation.BaseRequest
;
import
com.dtflys.forest.annotation.Query
;
import
com.dtflys.forest.annotation.Request
;
import
com.linkwechat.wecom.domain.weixin.dto.WxTokenDto
;
import
com.linkwechat.wecom.interceptor.WeiXinAccessTokenInterceptor
;
/**
* @author danmo
* @description
* @date 2021/4/5 17:11
**/
@BaseRequest
(
baseURL
=
"https://api.weixin.qq.com/cgi-bin"
,
contentType
=
"application/json"
)
public
interface
WxCommonClient
{
/**
* 获取微信token
*
* @param grantType 填写为client_credential
* @param appId 公众号的唯一标识
* @param secret 密钥
* @return
*/
@Request
(
url
=
"/token"
,
type
=
"GET"
)
WxTokenDto
getToken
(
@Query
(
"grant_type"
)
String
grantType
,
@Query
(
"appid"
)
String
appId
,
@Query
(
"secret"
)
String
secret
);
/**
*
* @param type
* @return
*/
@Request
(
url
=
"/ticket/getticket"
,
type
=
"GET"
,
interceptor
=
WeiXinAccessTokenInterceptor
.
class
)
WxTokenDto
getTicket
(
@Query
(
"type"
)
String
type
);
}
Write
Preview
Markdown
is supported
Attach a file
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 post a comment