diff --git a/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/WechatAppletController.java b/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/WechatAppletController.java index a1c48c6de..f4c6c4834 100644 --- a/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/WechatAppletController.java +++ b/stdiet-admin/src/main/java/com/stdiet/web/controller/custom/WechatAppletController.java @@ -534,7 +534,7 @@ public class WechatAppletController extends BaseController { } @GetMapping("/getToken") - public String getToken(@RequestParam String appId) { + public String getToken(@RequestParam String appId) throws Exception { return iWechatAppletService.getAccessToken(appId); } diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/IWechatAppletService.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/IWechatAppletService.java index af555b9c1..61b66e351 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/IWechatAppletService.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/IWechatAppletService.java @@ -2,7 +2,7 @@ package com.stdiet.custom.service; public interface IWechatAppletService { - public String getAccessToken(String appId); + public String getAccessToken(String appId) throws Exception; - public void postRecipesMessage(String appId, String openId, String name, String startDate, String endDate, String remark); + public void postRecipesMessage(String appId, String openId, String name, String startDate, String endDate, String remark) throws Exception; } diff --git a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/WeChartAppletServiceImp.java b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/WeChartAppletServiceImp.java index 300d512bf..21199866f 100644 --- a/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/WeChartAppletServiceImp.java +++ b/stdiet-custom/src/main/java/com/stdiet/custom/service/impl/WeChartAppletServiceImp.java @@ -24,7 +24,7 @@ public class WeChartAppletServiceImp implements IWechatAppletService { private RestTemplate restTemplate; @Override - public String getAccessToken(String appId) { + public String getAccessToken(String appId) throws Exception { String accessToken = redisCache.getCacheObject(appId); if (StringUtils.isNull(accessToken)) { String appSecret = ""; @@ -38,19 +38,18 @@ public class WeChartAppletServiceImp implements IWechatAppletService { ResponseEntity entity = restTemplate.getForEntity(url, String.class, param); + JSONObject resultObj = JSONObject.parseObject(entity.getBody()); - if (resultObj.getInteger("errcode") == 0) { - accessToken = resultObj.getString("access_token"); - Integer expiresIn = resultObj.getInteger("expires_in"); - redisCache.setCacheObject(appId, accessToken, expiresIn, TimeUnit.SECONDS); - } + accessToken = resultObj.getString("access_token"); + Integer expiresIn = resultObj.getInteger("expires_in"); + redisCache.setCacheObject(appId, accessToken, expiresIn, TimeUnit.SECONDS); } return accessToken; } @Override - public void postRecipesMessage(String appId, String openId, String name, String startDate, String endDate, String remark) { + public void postRecipesMessage(String appId, String openId, String name, String startDate, String endDate, String remark) throws Exception { String accessToken = getAccessToken(appId); if (StringUtils.isNull(accessToken)) { return;