Merge branches 'master' and 'xzj' of https://gitee.com/darlk/ShengTangManage into xzj

This commit is contained in:
xiezhijun 2021-05-17 16:31:51 +08:00
commit 11a4c69fef
3 changed files with 9 additions and 10 deletions

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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<String> 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;