| | |
| | | import java.util.Map; |
| | | |
| | | import com.panzhihua.common.controller.BaseController; |
| | | import com.panzhihua.common.model.vos.R; |
| | | import com.panzhihua.common.model.vos.user.SysAppConfigVO; |
| | | import com.panzhihua.common.service.user.UserService; |
| | | import org.apache.commons.fileupload.FileItem; |
| | | import org.apache.commons.fileupload.FileItemFactory; |
| | | import org.apache.commons.fileupload.disk.DiskFileItemFactory; |
| | |
| | | private static String APP_IMAGE_NAME = "5.jpg"; |
| | | @Resource |
| | | private RedisTemplate redisTemplate; |
| | | @Resource |
| | | private StringRedisTemplate stringRedisTemplate; |
| | | UserService userService; |
| | | |
| | | private static WxXCXTempSend wxXCXTempSend; |
| | | /** |
| | |
| | | */ |
| | | public String getAccessToken() throws Exception { |
| | | String accessToken = ""; |
| | | Boolean aBoolean = wxXCXTempSend.redisTemplate.hasKey(SecurityConstants.APPLETS_ACCESS_TOKEN); |
| | | ValueOperations<String, String> valueOperations = wxXCXTempSend.redisTemplate.opsForValue(); |
| | | if(aBoolean){ |
| | | Long expireTime = Long.parseLong(valueOperations.get(SecurityConstants.APPLETS_ACCESS_TOKEN_TIME)); |
| | | if(expireTime <= System.currentTimeMillis()){ |
| | | wxXCXTempSend.redisTemplate.delete(SecurityConstants.APPLETS_ACCESS_TOKEN);//如果过期则删除 |
| | | wxXCXTempSend.redisTemplate.delete(SecurityConstants.APPLETS_ACCESS_TOKEN_TIME);//如果过期则删除 |
| | | |
| | | valueOperations.set(SecurityConstants.APPLETS_ACCESS_TOKEN, accessToken); |
| | | valueOperations.set(SecurityConstants.APPLETS_ACCESS_TOKEN_TIME, System.currentTimeMillis() + 1100000 + ""); |
| | | }else{ |
| | | accessToken = valueOperations.get(SecurityConstants.APPLETS_ACCESS_TOKEN); |
| | | } |
| | | }else{ |
| | | accessToken = getAppAccessToken(); |
| | | valueOperations.set(SecurityConstants.APPLETS_ACCESS_TOKEN, accessToken); |
| | | valueOperations.set(SecurityConstants.APPLETS_ACCESS_TOKEN_TIME, System.currentTimeMillis() + 1100000 + ""); |
| | | } |
| | | accessToken=stringRedisTemplate.boundValueOps("access_token:access_token:"+this.getAppId()).get(); |
| | | return accessToken; |
| | | } |
| | | |
| | | public String getAppAccessToken() throws Exception { |
| | | String accessToken = "0"; |
| | | try { |
| | | // 此处APP_ID APP_SECRET 在微信小程序后端可见 |
| | | // String accessTokenUrl = String.format(TEMP_URL, APP_ID, APP_SECRET); |
| | | String appId = getAppId(); |
| | | String appSecret = getAppSecret(); |
| | | if(StringUtils.isEmpty(appId)){ |
| | | appId = APP_ID; |
| | | } |
| | | if(StringUtils.isEmpty(appSecret)){ |
| | | appSecret = APP_SECRET; |
| | | } |
| | | log.info("获取微信token参数:appid=" + appId + ",appSecret=" + appSecret); |
| | | String accessTokenUrl = ACCESS_TOKEN_URL + "&appid=" + appId + "&secret=" + appSecret; |
| | | log.info("获取微信token参数:appid=" + APP_ID + ",appSecret=" + APP_SECRET); |
| | | String accessTokenUrl = ACCESS_TOKEN_URL + "&appid=" + APP_ID + "&secret=" + APP_SECRET; |
| | | String result = HttpClientUtil.httpGet(accessTokenUrl, null, null); |
| | | Map<String, Object> resultMap = JSON.parseObject(result, Map.class); |
| | | if (resultMap.containsKey("access_token")) { |
| | |
| | | public void init() { |
| | | wxXCXTempSend = this; |
| | | wxXCXTempSend.redisTemplate = this.redisTemplate; |
| | | wxXCXTempSend.stringRedisTemplate=this.stringRedisTemplate; |
| | | } |
| | | |
| | | } |