微信接口开发

Merge pull request  from 德仔/develop
This commit is contained in:
德仔 2021-05-14 21:02:54 +08:00 committed by Gitee
commit c6fdacd9ba
3 changed files with 9 additions and 10 deletions
stdiet-admin/src/main/java/com/stdiet/web/controller/custom
stdiet-custom/src/main/java/com/stdiet/custom/service

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

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

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