| | |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * 微信工具类 |
| | |
| | | |
| | | // @Value("${wx.appSecret}") |
| | | private String webAppSecret; |
| | | |
| | | @Resource |
| | | private RedisService redisService; |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | |
| | | public String getWxAppletsAccessToken(){ |
| | | Object wxAppletsAccessToken = redisService.getCacheObject("wxAppletsAccessToken"); |
| | | if(null != wxAppletsAccessToken){ |
| | | return wxAppletsAccessToken.toString(); |
| | | } |
| | | String appletsAccessToken = getAppletsAccessToken(); |
| | | redisService.setCacheObject("wxAppletsAccessToken", appletsAccessToken, 7200L, TimeUnit.SECONDS); |
| | | return appletsAccessToken; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取微信小程序token |
| | | * @return |
| | | */ |
| | | public String getWxAppletsAccessToken() throws Exception{ |
| | | public String getAppletsAccessToken() { |
| | | String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + wxAppletsAppid + "&secret=" + wxAppletsAppSecret; |
| | | HttpRequest get = HttpUtil.createGet(url); |
| | | HttpResponse response = get.execute(); |