From 037480cc3276a3b163d07fcb670127a5d3ae24eb Mon Sep 17 00:00:00 2001 From: huangdeliang Date: Thu, 13 May 2021 20:20:06 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stdiet/web/controller/custom/WechatAppletController.java | 2 +- .../java/com/stdiet/custom/service/IWechatAppletService.java | 4 ++-- .../stdiet/custom/service/impl/WeChartAppletServiceImp.java | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) 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..4d0a04e99 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 = ""; @@ -50,7 +50,7 @@ public class WeChartAppletServiceImp implements IWechatAppletService { } @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; From e6a1a8d8ca6edc266e08653a867687d0b6bf7c0a Mon Sep 17 00:00:00 2001 From: huangdeliang Date: Thu, 13 May 2021 20:25:04 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/WeChartAppletServiceImp.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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 4d0a04e99..8e425e5c8 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 @@ -38,13 +38,15 @@ public class WeChartAppletServiceImp implements IWechatAppletService { ResponseEntity entity = restTemplate.getForEntity(url, String.class, param); - JSONObject resultObj = JSONObject.parseObject(entity.getBody()); + return 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); - } +// 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); +// } } return accessToken; } From 8b068b0f1a37db8e4253315af9c1885eacc0ad56 Mon Sep 17 00:00:00 2001 From: huangdeliang Date: Thu, 13 May 2021 20:27:17 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/WeChartAppletServiceImp.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) 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 8e425e5c8..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 @@ -38,15 +38,12 @@ public class WeChartAppletServiceImp implements IWechatAppletService { ResponseEntity entity = restTemplate.getForEntity(url, String.class, param); - return entity.getBody(); -// 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); -// } + JSONObject resultObj = JSONObject.parseObject(entity.getBody()); + + accessToken = resultObj.getString("access_token"); + Integer expiresIn = resultObj.getInteger("expires_in"); + redisCache.setCacheObject(appId, accessToken, expiresIn, TimeUnit.SECONDS); } return accessToken; }