Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yanxuan-wx-store-sharer
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
wx
yanxuan-wx-store-sharer
Commits
d7ab7fad
Commit
d7ab7fad
authored
Mar 12, 2025
by
fanjiaxin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码初始化
parent
7b535c89
Pipeline
#71432
passed with stages
in 1 minute 0 seconds
Changes
12
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
98 additions
and
13 deletions
+98
-13
SpringContextUtils.java
...nxuan/wx/store/sharer/common/util/SpringContextUtils.java
+82
-0
WeChatContextHolder.java
...wx/store/sharer/integration/core/WeChatContextHolder.java
+0
-1
IWeChatRequest.java
...n/wx/store/sharer/integration/handler/IWeChatRequest.java
+7
-0
WeChatRestTemplateHandler.java
...sharer/integration/handler/WeChatRestTemplateHandler.java
+1
-4
WeChatGetSharerProductCommissionRequest.java
...handler/impl/WeChatGetSharerProductCommissionRequest.java
+1
-1
WeChatPromoteProductDetailRequest.java
...ation/handler/impl/WeChatPromoteProductDetailRequest.java
+1
-1
WeChatPromoteProductLinkRequest.java
...gration/handler/impl/WeChatPromoteProductLinkRequest.java
+1
-1
WeChatPromoteProductListRequest.java
...gration/handler/impl/WeChatPromoteProductListRequest.java
+1
-1
WeChatSetSharerCommissionRequest.java
...ration/handler/impl/WeChatSetSharerCommissionRequest.java
+1
-1
WeChatSetSharerProductCommissionRequest.java
...handler/impl/WeChatSetSharerProductCommissionRequest.java
+1
-1
WeChatSharerListRequest.java
...rer/integration/handler/impl/WeChatSharerListRequest.java
+1
-1
WeChatSharerRegisterBindRequest.java
...gration/handler/impl/WeChatSharerRegisterBindRequest.java
+1
-1
No files found.
yanxuan-wx-store-sharer-common/src/main/java/com/netease/yanxuan/wx/store/sharer/common/util/SpringContextUtils.java
0 → 100644
View file @
d7ab7fad
package
com
.
netease
.
yanxuan
.
wx
.
store
.
sharer
.
common
.
util
;
import
org.springframework.beans.BeansException
;
import
org.springframework.beans.factory.NoSuchBeanDefinitionException
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ApplicationContextAware
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.servlet.http.HttpServletRequest
;
@Component
public
class
SpringContextUtils
implements
ApplicationContextAware
{
/**
* 上下文对象实例
*/
private
static
ApplicationContext
applicationContext
;
@Override
public
void
setApplicationContext
(
ApplicationContext
applicationContext
)
throws
BeansException
{
SpringContextUtils
.
applicationContext
=
applicationContext
;
}
/**
* 获取applicationContext
*/
public
static
ApplicationContext
getApplicationContext
()
{
return
applicationContext
;
}
/**
* 获取HttpServletRequest
*/
public
static
HttpServletRequest
getHttpServletRequest
()
{
return
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
();
}
public
static
String
getDomain
()
{
HttpServletRequest
request
=
getHttpServletRequest
();
StringBuffer
url
=
request
.
getRequestURL
();
return
url
.
delete
(
url
.
length
()
-
request
.
getRequestURI
().
length
(),
url
.
length
()).
toString
();
}
public
static
String
getOrigin
()
{
HttpServletRequest
request
=
getHttpServletRequest
();
return
request
.
getHeader
(
"Origin"
);
}
/**
* 通过name获取 Bean.
*/
public
static
Object
getBean
(
String
name
)
{
return
getApplicationContext
().
getBean
(
name
);
}
/**
* 通过class获取Bean.
*/
public
static
<
T
>
T
getBean
(
Class
<
T
>
clazz
)
{
return
getApplicationContext
().
getBean
(
clazz
);
}
/**
* 通过name,以及Clazz返回指定的Bean
*/
public
static
<
T
>
T
getBean
(
String
name
,
Class
<
T
>
clazz
)
{
return
getApplicationContext
().
getBean
(
name
,
clazz
);
}
/**
* 通过name,以及Clazz返回指定的Bean,为空不报错
*/
public
static
<
T
>
T
getBeanIfExists
(
String
name
,
Class
<
T
>
clazz
)
{
try
{
return
getApplicationContext
().
getBean
(
name
,
clazz
);
}
catch
(
NoSuchBeanDefinitionException
e
)
{
return
null
;
}
}
}
yanxuan-wx-store-sharer-integration/src/main/java/com/netease/yanxuan/wx/store/sharer/integration/core/WeChatContextHolder.java
View file @
d7ab7fad
...
@@ -53,7 +53,6 @@ public class WeChatContextHolder {
...
@@ -53,7 +53,6 @@ public class WeChatContextHolder {
return
createAccessToken
();
return
createAccessToken
();
}
}
// 双重检查锁定
// 双重检查锁定
// 双重检查锁定
String
accessToken
=
redisClient
.
getStr
(
CoreConstant
.
REDIS_TOKEN_WECHAT_KEY
);
String
accessToken
=
redisClient
.
getStr
(
CoreConstant
.
REDIS_TOKEN_WECHAT_KEY
);
if
(
StringUtils
.
isNotBlank
(
accessToken
))
{
if
(
StringUtils
.
isNotBlank
(
accessToken
))
{
return
accessToken
;
return
accessToken
;
...
...
yanxuan-wx-store-sharer-integration/src/main/java/com/netease/yanxuan/wx/store/sharer/integration/handler/IWeChatRequest.java
View file @
d7ab7fad
package
com
.
netease
.
yanxuan
.
wx
.
store
.
sharer
.
integration
.
handler
;
package
com
.
netease
.
yanxuan
.
wx
.
store
.
sharer
.
integration
.
handler
;
import
com.netease.yanxuan.wx.store.sharer.common.util.SpringContextUtils
;
import
com.netease.yanxuan.wx.store.sharer.integration.core.WeChatContextHolder
;
import
org.springframework.http.HttpMethod
;
import
org.springframework.http.HttpMethod
;
/**
/**
...
@@ -17,4 +19,9 @@ public interface IWeChatRequest {
...
@@ -17,4 +19,9 @@ public interface IWeChatRequest {
* 请求地址
* 请求地址
*/
*/
String
getRequestUrl
();
String
getRequestUrl
();
default
String
getAccessToken
()
{
WeChatContextHolder
weChatContextHolder
=
SpringContextUtils
.
getBean
(
WeChatContextHolder
.
class
);
return
weChatContextHolder
.
getAccessToken
();
}
}
}
yanxuan-wx-store-sharer-integration/src/main/java/com/netease/yanxuan/wx/store/sharer/integration/handler/WeChatRestTemplateHandler.java
View file @
d7ab7fad
...
@@ -2,7 +2,6 @@ package com.netease.yanxuan.wx.store.sharer.integration.handler;
...
@@ -2,7 +2,6 @@ package com.netease.yanxuan.wx.store.sharer.integration.handler;
import
com.netease.yanxuan.wx.store.sharer.common.exception.BizException
;
import
com.netease.yanxuan.wx.store.sharer.common.exception.BizException
;
import
com.netease.yanxuan.wx.store.sharer.common.handler.RestTemplateClient
;
import
com.netease.yanxuan.wx.store.sharer.common.handler.RestTemplateClient
;
import
com.netease.yanxuan.wx.store.sharer.integration.core.WeChatContextHolder
;
import
com.netease.yanxuan.wx.store.sharer.integration.meta.model.vo.WeChatCoreVO
;
import
com.netease.yanxuan.wx.store.sharer.integration.meta.model.vo.WeChatCoreVO
;
import
lombok.RequiredArgsConstructor
;
import
lombok.RequiredArgsConstructor
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
@@ -19,11 +18,9 @@ import org.springframework.stereotype.Service;
...
@@ -19,11 +18,9 @@ import org.springframework.stereotype.Service;
@RequiredArgsConstructor
@RequiredArgsConstructor
public
class
WeChatRestTemplateHandler
{
public
class
WeChatRestTemplateHandler
{
private
final
RestTemplateClient
restTemplateClient
;
private
final
RestTemplateClient
restTemplateClient
;
private
final
WeChatContextHolder
weChatContextHolder
;
public
<
T
,
R
extends
WeChatCoreVO
>
R
execute
(
String
url
,
HttpMethod
method
,
T
params
,
Class
<
R
>
resType
)
{
public
<
T
,
R
extends
WeChatCoreVO
>
R
execute
(
String
url
,
HttpMethod
method
,
T
params
,
Class
<
R
>
resType
)
{
String
accessToken
=
weChatContextHolder
.
getAccessToken
();
R
result
=
restTemplateClient
.
execute
(
url
,
method
,
params
,
resType
);
R
result
=
restTemplateClient
.
execute
(
url
+
"?access_token="
+
accessToken
,
method
,
params
,
resType
);
if
(!
"0"
.
equals
(
result
.
getErrcode
()))
{
if
(!
"0"
.
equals
(
result
.
getErrcode
()))
{
throw
new
BizException
(
"调用微信接口失败,"
+
result
.
getErrmsg
());
throw
new
BizException
(
"调用微信接口失败,"
+
result
.
getErrmsg
());
}
}
...
...
yanxuan-wx-store-sharer-integration/src/main/java/com/netease/yanxuan/wx/store/sharer/integration/handler/impl/WeChatGetSharerProductCommissionRequest.java
View file @
d7ab7fad
...
@@ -31,7 +31,7 @@ public class WeChatGetSharerProductCommissionRequest implements IWeChatRequest {
...
@@ -31,7 +31,7 @@ public class WeChatGetSharerProductCommissionRequest implements IWeChatRequest {
@Override
@Override
public
String
getRequestUrl
()
{
public
String
getRequestUrl
()
{
return
weChatConfig
.
getUrl
()
+
WeChatApi
.
GET_SHARER_PRODUCT_COMMISSION_INFO
;
return
weChatConfig
.
getUrl
()
+
WeChatApi
.
GET_SHARER_PRODUCT_COMMISSION_INFO
+
"?access_token="
+
getAccessToken
()
;
}
}
/**
/**
...
...
yanxuan-wx-store-sharer-integration/src/main/java/com/netease/yanxuan/wx/store/sharer/integration/handler/impl/WeChatPromoteProductDetailRequest.java
View file @
d7ab7fad
...
@@ -32,7 +32,7 @@ public class WeChatPromoteProductDetailRequest implements IWeChatRequest {
...
@@ -32,7 +32,7 @@ public class WeChatPromoteProductDetailRequest implements IWeChatRequest {
@Override
@Override
public
String
getRequestUrl
()
{
public
String
getRequestUrl
()
{
return
weChatConfig
.
getUrl
()
+
WeChatApi
.
GET_PROMOTE_PRODUCT_DETAIL
;
return
weChatConfig
.
getUrl
()
+
WeChatApi
.
GET_PROMOTE_PRODUCT_DETAIL
+
"?access_token="
+
getAccessToken
()
;
}
}
/**
/**
...
...
yanxuan-wx-store-sharer-integration/src/main/java/com/netease/yanxuan/wx/store/sharer/integration/handler/impl/WeChatPromoteProductLinkRequest.java
View file @
d7ab7fad
...
@@ -31,7 +31,7 @@ public class WeChatPromoteProductLinkRequest implements IWeChatRequest {
...
@@ -31,7 +31,7 @@ public class WeChatPromoteProductLinkRequest implements IWeChatRequest {
@Override
@Override
public
String
getRequestUrl
()
{
public
String
getRequestUrl
()
{
return
weChatConfig
.
getUrl
()
+
WeChatApi
.
GET_PRODUCT_PROMOTION_LINK_INFO
;
return
weChatConfig
.
getUrl
()
+
WeChatApi
.
GET_PRODUCT_PROMOTION_LINK_INFO
+
"?access_token="
+
getAccessToken
()
;
}
}
/**
/**
...
...
yanxuan-wx-store-sharer-integration/src/main/java/com/netease/yanxuan/wx/store/sharer/integration/handler/impl/WeChatPromoteProductListRequest.java
View file @
d7ab7fad
...
@@ -32,7 +32,7 @@ public class WeChatPromoteProductListRequest implements IWeChatRequest {
...
@@ -32,7 +32,7 @@ public class WeChatPromoteProductListRequest implements IWeChatRequest {
@Override
@Override
public
String
getRequestUrl
()
{
public
String
getRequestUrl
()
{
return
weChatConfig
.
getUrl
()
+
WeChatApi
.
GET_PROMOTE_PRODUCT_LIST
;
return
weChatConfig
.
getUrl
()
+
WeChatApi
.
GET_PROMOTE_PRODUCT_LIST
+
"?access_token="
+
getAccessToken
()
;
}
}
/**
/**
...
...
yanxuan-wx-store-sharer-integration/src/main/java/com/netease/yanxuan/wx/store/sharer/integration/handler/impl/WeChatSetSharerCommissionRequest.java
View file @
d7ab7fad
...
@@ -32,7 +32,7 @@ public class WeChatSetSharerCommissionRequest implements IWeChatRequest {
...
@@ -32,7 +32,7 @@ public class WeChatSetSharerCommissionRequest implements IWeChatRequest {
@Override
@Override
public
String
getRequestUrl
()
{
public
String
getRequestUrl
()
{
return
weChatConfig
.
getUrl
()
+
WeChatApi
.
SET_SHARER_COMMISSION_INFO
;
return
weChatConfig
.
getUrl
()
+
WeChatApi
.
SET_SHARER_COMMISSION_INFO
+
"?access_token="
+
getAccessToken
()
;
}
}
/**
/**
...
...
yanxuan-wx-store-sharer-integration/src/main/java/com/netease/yanxuan/wx/store/sharer/integration/handler/impl/WeChatSetSharerProductCommissionRequest.java
View file @
d7ab7fad
...
@@ -31,7 +31,7 @@ public class WeChatSetSharerProductCommissionRequest implements IWeChatRequest {
...
@@ -31,7 +31,7 @@ public class WeChatSetSharerProductCommissionRequest implements IWeChatRequest {
@Override
@Override
public
String
getRequestUrl
()
{
public
String
getRequestUrl
()
{
return
weChatConfig
.
getUrl
()
+
WeChatApi
.
SET_SHARER_PRODUCT_COMMISSION_INFO
;
return
weChatConfig
.
getUrl
()
+
WeChatApi
.
SET_SHARER_PRODUCT_COMMISSION_INFO
+
"?access_token="
+
getAccessToken
()
;
}
}
/**
/**
...
...
yanxuan-wx-store-sharer-integration/src/main/java/com/netease/yanxuan/wx/store/sharer/integration/handler/impl/WeChatSharerListRequest.java
View file @
d7ab7fad
...
@@ -31,7 +31,7 @@ public class WeChatSharerListRequest implements IWeChatRequest {
...
@@ -31,7 +31,7 @@ public class WeChatSharerListRequest implements IWeChatRequest {
@Override
@Override
public
String
getRequestUrl
()
{
public
String
getRequestUrl
()
{
return
weChatConfig
.
getUrl
()
+
WeChatApi
.
GET_BIND_SHARER_LIST
;
return
weChatConfig
.
getUrl
()
+
WeChatApi
.
GET_BIND_SHARER_LIST
+
"?access_token="
+
getAccessToken
()
;
}
}
/**
/**
...
...
yanxuan-wx-store-sharer-integration/src/main/java/com/netease/yanxuan/wx/store/sharer/integration/handler/impl/WeChatSharerRegisterBindRequest.java
View file @
d7ab7fad
...
@@ -31,7 +31,7 @@ public class WeChatSharerRegisterBindRequest implements IWeChatRequest {
...
@@ -31,7 +31,7 @@ public class WeChatSharerRegisterBindRequest implements IWeChatRequest {
@Override
@Override
public
String
getRequestUrl
()
{
public
String
getRequestUrl
()
{
return
weChatConfig
.
getUrl
()
+
WeChatApi
.
GET_USER_INFO
;
return
weChatConfig
.
getUrl
()
+
WeChatApi
.
GET_USER_INFO
+
"?access_token="
+
getAccessToken
()
;
}
}
/**
/**
...
...
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