提交 d894e079 作者: zhenjie

依赖包升级

上级 f82dc9c6
...@@ -68,23 +68,16 @@ ...@@ -68,23 +68,16 @@
<version>5.5.0</version> <!-- 支持开源所有版本 --> <version>5.5.0</version> <!-- 支持开源所有版本 -->
</dependency> </dependency>
<!-- <dependency>--> <!-- <dependency>-->
<!-- <groupId>com.github.xiaoymin</groupId>--> <!-- <groupId>com.github.xiaoymin</groupId>-->
<!-- <artifactId>knife4j-spring-boot-starter</artifactId>--> <!-- <artifactId>knife4j-spring-boot-starter</artifactId>-->
<!-- <version>2.0.5</version>--> <!-- <version>2.0.5</version>-->
<!-- </dependency>--> <!-- </dependency>-->
<!-- <dependency>--> <!-- <dependency>-->
<!-- <groupId>com.github.xiaoymin</groupId>--> <!-- <groupId>com.github.xiaoymin</groupId>-->
<!-- <artifactId>knife4j-openapi2-spring-boot-starter</artifactId>--> <!-- <artifactId>knife4j-openapi2-spring-boot-starter</artifactId>-->
<!-- <version>4.0.0</version>--> <!-- <version>4.0.0</version>-->
<!-- </dependency>--> <!-- </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>
</dependencies> </dependencies>
......
package com.mmc.iuav.user.service.impl; package com.mmc.iuav.user.service.impl;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.github.wxpay.sdk.WXPayUtil;
import com.mmc.iuav.http.HttpHelper; import com.mmc.iuav.http.HttpHelper;
import com.mmc.iuav.http.HttpsRequestUtil; import com.mmc.iuav.http.HttpsRequestUtil;
import com.mmc.iuav.response.ResultBody; import com.mmc.iuav.response.ResultBody;
...@@ -15,6 +14,7 @@ import com.mmc.iuav.user.model.vo.WxLoginVO; ...@@ -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.model.vo.WxMsgVO;
import com.mmc.iuav.user.service.WxService; import com.mmc.iuav.user.service.WxService;
import com.mmc.iuav.user.util.WxApiUtil; import com.mmc.iuav.user.util.WxApiUtil;
import com.mmc.iuav.user.util.XmlToMapUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -65,7 +65,7 @@ public class WxServiceImpl implements WxService { ...@@ -65,7 +65,7 @@ public class WxServiceImpl implements WxService {
public String getAccessToken() { public String getAccessToken() {
//token有效期为7200s,需要保存起来,先从redis中获取accessToken,没有则请求获取 //token有效期为7200s,需要保存起来,先从redis中获取accessToken,没有则请求获取
String accessToken = stringRedisTemplate.opsForValue().get(WxConstant.IUAV_MINI_PROGRAM_ACCESS_TOKEN); 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=" + String getAccessTokenUrl = "https://api.weixin.qq.com/cgi-bin/token" + "?grant_type=client_credential" + "&appid=" +
userSystemConstant.getWxAppId() + "&secret=" + userSystemConstant.getWxAppSecret(); userSystemConstant.getWxAppId() + "&secret=" + userSystemConstant.getWxAppSecret();
String accessTokenMsg = HttpsRequestUtil.httpsGet(getAccessTokenUrl, null); String accessTokenMsg = HttpsRequestUtil.httpsGet(getAccessTokenUrl, null);
...@@ -86,7 +86,7 @@ public class WxServiceImpl implements WxService { ...@@ -86,7 +86,7 @@ public class WxServiceImpl implements WxService {
public String getStableAccessToken() { public String getStableAccessToken() {
//token有效期为7200s,需要保存起来,先从redis中获取accessToken,没有则请求获取 //token有效期为7200s,需要保存起来,先从redis中获取accessToken,没有则请求获取
String accessToken = stringRedisTemplate.opsForValue().get(WxConstant.IUAV_MINI_PROGRAM_STABLE_ACCESS_TOKEN); 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>(); Map<String, String> params = new HashMap<String, String>();
params.put("grant_type", "client_credential"); params.put("grant_type", "client_credential");
params.put("appid", userSystemConstant.getWxAppId()); params.put("appid", userSystemConstant.getWxAppId());
...@@ -115,13 +115,13 @@ public class WxServiceImpl implements WxService { ...@@ -115,13 +115,13 @@ public class WxServiceImpl implements WxService {
public String getSubAccessToken() { public String getSubAccessToken() {
//token有效期为7200s,需要保存起来,先从redis中获取accessToken,没有则请求获取 //token有效期为7200s,需要保存起来,先从redis中获取accessToken,没有则请求获取
String accessToken = stringRedisTemplate.opsForValue().get(WxConstant.SHARE_FLY_SUB_ACCESS_TOKEN); 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=" + String getAccessTokenUrl = "https://api.weixin.qq.com/cgi-bin/token" + "?grant_type=client_credential" + "&appid=" +
userSystemConstant.getWxSubAppId() + "&secret=" + userSystemConstant.getWxSubSecret(); userSystemConstant.getWxSubAppId() + "&secret=" + userSystemConstant.getWxSubSecret();
String accessTokenMsg = HttpsRequestUtil.httpsGet(getAccessTokenUrl, null); String accessTokenMsg = HttpsRequestUtil.httpsGet(getAccessTokenUrl, null);
JSONObject tokenResult = JSONObject.parseObject(accessTokenMsg); JSONObject tokenResult = JSONObject.parseObject(accessTokenMsg);
if (accessTokenMsg.indexOf("access_token") == -1) { if (accessTokenMsg.indexOf("access_token") == -1) {
log.info("获取公众号access_token有误:{}",tokenResult); log.info("获取公众号access_token有误:{}", tokenResult);
return null; return null;
} }
accessToken = tokenResult.getString("access_token"); accessToken = tokenResult.getString("access_token");
...@@ -177,7 +177,7 @@ public class WxServiceImpl implements WxService { ...@@ -177,7 +177,7 @@ public class WxServiceImpl implements WxService {
buffer.append(line); buffer.append(line);
} }
String notifyXml = buffer.toString(); String notifyXml = buffer.toString();
return WXPayUtil.xmlToMap(notifyXml); return XmlToMapUtil.xmlToMap(notifyXml);
} }
private void updateWXUserInfo(String openid) { private void updateWXUserInfo(String openid) {
...@@ -205,7 +205,7 @@ public class WxServiceImpl implements WxService { ...@@ -205,7 +205,7 @@ public class WxServiceImpl implements WxService {
log.info("未订阅公众号,无法拉取信息。"); log.info("未订阅公众号,无法拉取信息。");
return; return;
} }
}catch (Exception e){ } catch (Exception e) {
throw new RuntimeException(); throw new RuntimeException();
} }
} }
...@@ -220,7 +220,7 @@ public class WxServiceImpl implements WxService { ...@@ -220,7 +220,7 @@ public class WxServiceImpl implements WxService {
String param = ws.buildMsgJson(); String param = ws.buildMsgJson();
String result = HttpHelper.httpPost(url, param); String result = HttpHelper.httpPost(url, param);
} catch (Exception e) { } catch (Exception e) {
log.error("accessToken获取失败:{}", e.getMessage()); log.error("accessToken获取失败:{}", e.getMessage());
return ResultBody.error(ResultEnum.WX_ACCESS_TOKEN_ERROR.getResultCode(), return ResultBody.error(ResultEnum.WX_ACCESS_TOKEN_ERROR.getResultCode(),
ResultEnum.WX_ACCESS_TOKEN_ERROR.getResultMsg() + e.getMessage()); ResultEnum.WX_ACCESS_TOKEN_ERROR.getResultMsg() + e.getMessage());
} }
...@@ -250,7 +250,7 @@ public class WxServiceImpl implements WxService { ...@@ -250,7 +250,7 @@ public class WxServiceImpl implements WxService {
@Override @Override
public ResultBody sendAppletMsg(AppletMsgVO appletMsgVO) { public ResultBody sendAppletMsg(AppletMsgVO appletMsgVO) {
String accessToken = this.getStableAccessToken(); String accessToken = this.getStableAccessToken();
if (StringUtils.isBlank(accessToken)){ if (StringUtils.isBlank(accessToken)) {
return ResultBody.error(ResultEnum.WX_ACCESS_TOKEN_ERROR.getResultCode(), return ResultBody.error(ResultEnum.WX_ACCESS_TOKEN_ERROR.getResultCode(),
ResultEnum.WX_ACCESS_TOKEN_ERROR.getResultMsg()); ResultEnum.WX_ACCESS_TOKEN_ERROR.getResultMsg());
} }
...@@ -259,8 +259,8 @@ public class WxServiceImpl implements WxService { ...@@ -259,8 +259,8 @@ public class WxServiceImpl implements WxService {
appletMsgVO.setData(WxApiUtil.buildMsgJson(appletMsgVO.getData())); appletMsgVO.setData(WxApiUtil.buildMsgJson(appletMsgVO.getData()));
String param = JSONObject.toJSONString(appletMsgVO); String param = JSONObject.toJSONString(appletMsgVO);
HttpHelper.httpPost(url, param); HttpHelper.httpPost(url, param);
} catch (Exception e){ } catch (Exception e) {
log.error("系统异常:{}" ,e.getMessage()); log.error("系统异常:{}", e.getMessage());
} }
return ResultBody.success(); return ResultBody.success();
} }
......
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论