Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
cms-ci-test
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
test-ci
cms-ci-test
Commits
d894e079
提交
d894e079
authored
7月 25, 2023
作者:
zhenjie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
依赖包升级
上级
f82dc9c6
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
64 行增加
和
28 行删除
+64
-28
pom.xml
csm-service/cms-service-user/pom.xml
+10
-17
WxServiceImpl.java
...in/java/com/mmc/iuav/user/service/impl/WxServiceImpl.java
+11
-11
XmlToMapUtil.java
...er/src/main/java/com/mmc/iuav/user/util/XmlToMapUtil.java
+43
-0
没有找到文件。
csm-service/cms-service-user/pom.xml
浏览文件 @
d894e079
...
...
@@ -68,23 +68,16 @@
<version>
5.5.0
</version>
<!-- 支持开源所有版本 -->
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.github.xiaoymin</groupId>-->
<!-- <artifactId>knife4j-spring-boot-starter</artifactId>-->
<!-- <version>2.0.5</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.github.xiaoymin</groupId>-->
<!-- <artifactId>knife4j-openapi2-spring-boot-starter</artifactId>-->
<!-- <version>4.0.0</version>-->
<!-- </dependency>-->
<!-- https://mvnrepository.com/artifact/com.github.wxpay/wxpay-sdk -->
<dependency>
<groupId>
com.github.wxpay
</groupId>
<artifactId>
wxpay-sdk
</artifactId>
<version>
0.0.3
</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.github.xiaoymin</groupId>-->
<!-- <artifactId>knife4j-spring-boot-starter</artifactId>-->
<!-- <version>2.0.5</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>com.github.xiaoymin</groupId>-->
<!-- <artifactId>knife4j-openapi2-spring-boot-starter</artifactId>-->
<!-- <version>4.0.0</version>-->
<!-- </dependency>-->
</dependencies>
...
...
csm-service/cms-service-user/src/main/java/com/mmc/iuav/user/service/impl/WxServiceImpl.java
浏览文件 @
d894e079
package
com
.
mmc
.
iuav
.
user
.
service
.
impl
;
import
com.alibaba.fastjson2.JSONObject
;
import
com.github.wxpay.sdk.WXPayUtil
;
import
com.mmc.iuav.http.HttpHelper
;
import
com.mmc.iuav.http.HttpsRequestUtil
;
import
com.mmc.iuav.response.ResultBody
;
...
...
@@ -15,6 +14,7 @@ import com.mmc.iuav.user.model.vo.WxLoginVO;
import
com.mmc.iuav.user.model.vo.WxMsgVO
;
import
com.mmc.iuav.user.service.WxService
;
import
com.mmc.iuav.user.util.WxApiUtil
;
import
com.mmc.iuav.user.util.XmlToMapUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -65,7 +65,7 @@ public class WxServiceImpl implements WxService {
public
String
getAccessToken
()
{
//token有效期为7200s,需要保存起来,先从redis中获取accessToken,没有则请求获取
String
accessToken
=
stringRedisTemplate
.
opsForValue
().
get
(
WxConstant
.
IUAV_MINI_PROGRAM_ACCESS_TOKEN
);
if
(
StringUtils
.
isBlank
(
accessToken
)){
if
(
StringUtils
.
isBlank
(
accessToken
))
{
String
getAccessTokenUrl
=
"https://api.weixin.qq.com/cgi-bin/token"
+
"?grant_type=client_credential"
+
"&appid="
+
userSystemConstant
.
getWxAppId
()
+
"&secret="
+
userSystemConstant
.
getWxAppSecret
();
String
accessTokenMsg
=
HttpsRequestUtil
.
httpsGet
(
getAccessTokenUrl
,
null
);
...
...
@@ -86,7 +86,7 @@ public class WxServiceImpl implements WxService {
public
String
getStableAccessToken
()
{
//token有效期为7200s,需要保存起来,先从redis中获取accessToken,没有则请求获取
String
accessToken
=
stringRedisTemplate
.
opsForValue
().
get
(
WxConstant
.
IUAV_MINI_PROGRAM_STABLE_ACCESS_TOKEN
);
if
(
StringUtils
.
isBlank
(
accessToken
)){
if
(
StringUtils
.
isBlank
(
accessToken
))
{
Map
<
String
,
String
>
params
=
new
HashMap
<
String
,
String
>();
params
.
put
(
"grant_type"
,
"client_credential"
);
params
.
put
(
"appid"
,
userSystemConstant
.
getWxAppId
());
...
...
@@ -115,13 +115,13 @@ public class WxServiceImpl implements WxService {
public
String
getSubAccessToken
()
{
//token有效期为7200s,需要保存起来,先从redis中获取accessToken,没有则请求获取
String
accessToken
=
stringRedisTemplate
.
opsForValue
().
get
(
WxConstant
.
SHARE_FLY_SUB_ACCESS_TOKEN
);
if
(
StringUtils
.
isBlank
(
accessToken
)){
if
(
StringUtils
.
isBlank
(
accessToken
))
{
String
getAccessTokenUrl
=
"https://api.weixin.qq.com/cgi-bin/token"
+
"?grant_type=client_credential"
+
"&appid="
+
userSystemConstant
.
getWxSubAppId
()
+
"&secret="
+
userSystemConstant
.
getWxSubSecret
();
String
accessTokenMsg
=
HttpsRequestUtil
.
httpsGet
(
getAccessTokenUrl
,
null
);
JSONObject
tokenResult
=
JSONObject
.
parseObject
(
accessTokenMsg
);
if
(
accessTokenMsg
.
indexOf
(
"access_token"
)
==
-
1
)
{
log
.
info
(
"获取公众号access_token有误:{}"
,
tokenResult
);
log
.
info
(
"获取公众号access_token有误:{}"
,
tokenResult
);
return
null
;
}
accessToken
=
tokenResult
.
getString
(
"access_token"
);
...
...
@@ -177,7 +177,7 @@ public class WxServiceImpl implements WxService {
buffer
.
append
(
line
);
}
String
notifyXml
=
buffer
.
toString
();
return
WXPay
Util
.
xmlToMap
(
notifyXml
);
return
XmlToMap
Util
.
xmlToMap
(
notifyXml
);
}
private
void
updateWXUserInfo
(
String
openid
)
{
...
...
@@ -205,7 +205,7 @@ public class WxServiceImpl implements WxService {
log
.
info
(
"未订阅公众号,无法拉取信息。"
);
return
;
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
();
}
}
...
...
@@ -220,7 +220,7 @@ public class WxServiceImpl implements WxService {
String
param
=
ws
.
buildMsgJson
();
String
result
=
HttpHelper
.
httpPost
(
url
,
param
);
}
catch
(
Exception
e
)
{
log
.
error
(
"accessToken获取失败:{}"
,
e
.
getMessage
());
log
.
error
(
"accessToken获取失败:{}"
,
e
.
getMessage
());
return
ResultBody
.
error
(
ResultEnum
.
WX_ACCESS_TOKEN_ERROR
.
getResultCode
(),
ResultEnum
.
WX_ACCESS_TOKEN_ERROR
.
getResultMsg
()
+
e
.
getMessage
());
}
...
...
@@ -250,7 +250,7 @@ public class WxServiceImpl implements WxService {
@Override
public
ResultBody
sendAppletMsg
(
AppletMsgVO
appletMsgVO
)
{
String
accessToken
=
this
.
getStableAccessToken
();
if
(
StringUtils
.
isBlank
(
accessToken
)){
if
(
StringUtils
.
isBlank
(
accessToken
))
{
return
ResultBody
.
error
(
ResultEnum
.
WX_ACCESS_TOKEN_ERROR
.
getResultCode
(),
ResultEnum
.
WX_ACCESS_TOKEN_ERROR
.
getResultMsg
());
}
...
...
@@ -259,8 +259,8 @@ public class WxServiceImpl implements WxService {
appletMsgVO
.
setData
(
WxApiUtil
.
buildMsgJson
(
appletMsgVO
.
getData
()));
String
param
=
JSONObject
.
toJSONString
(
appletMsgVO
);
HttpHelper
.
httpPost
(
url
,
param
);
}
catch
(
Exception
e
){
log
.
error
(
"系统异常:{}"
,
e
.
getMessage
());
}
catch
(
Exception
e
)
{
log
.
error
(
"系统异常:{}"
,
e
.
getMessage
());
}
return
ResultBody
.
success
();
}
...
...
csm-service/cms-service-user/src/main/java/com/mmc/iuav/user/util/XmlToMapUtil.java
0 → 100644
浏览文件 @
d894e079
package
com
.
mmc
.
iuav
.
user
.
util
;
import
org.w3c.dom.Document
;
import
org.w3c.dom.Element
;
import
org.w3c.dom.Node
;
import
org.w3c.dom.NodeList
;
import
javax.xml.parsers.DocumentBuilder
;
import
javax.xml.parsers.DocumentBuilderFactory
;
import
java.io.ByteArrayInputStream
;
import
java.io.InputStream
;
import
java.util.HashMap
;
import
java.util.Map
;
/**
* @author: zj
* @Date: 2023/7/25 10:13
*/
public
class
XmlToMapUtil
{
public
static
Map
<
String
,
String
>
xmlToMap
(
String
strXML
)
throws
Exception
{
Map
<
String
,
String
>
data
=
new
HashMap
();
DocumentBuilderFactory
documentBuilderFactory
=
DocumentBuilderFactory
.
newInstance
();
DocumentBuilder
documentBuilder
=
documentBuilderFactory
.
newDocumentBuilder
();
InputStream
stream
=
new
ByteArrayInputStream
(
strXML
.
getBytes
(
"UTF-8"
));
Document
doc
=
documentBuilder
.
parse
(
stream
);
doc
.
getDocumentElement
().
normalize
();
NodeList
nodeList
=
doc
.
getDocumentElement
().
getChildNodes
();
for
(
int
idx
=
0
;
idx
<
nodeList
.
getLength
();
++
idx
)
{
Node
node
=
nodeList
.
item
(
idx
);
if
(
node
.
getNodeType
()
==
1
)
{
Element
element
=
(
Element
)
node
;
data
.
put
(
element
.
getNodeName
(),
element
.
getTextContent
());
}
}
try
{
stream
.
close
();
}
catch
(
Exception
var10
)
{
}
return
data
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论