| | |
| | | import org.apache.commons.fileupload.disk.DiskFileItemFactory; |
| | | import org.apache.http.entity.ContentType; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.data.redis.core.StringRedisTemplate; |
| | | import org.springframework.data.redis.core.ValueOperations; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import javax.annotation.Resource; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | public class WxXCXTempSend extends BaseController { |
| | |
| | | private static String ACCESS_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential"; |
| | | private static String APP_IMAGE_URL = "https://www.psciio.com//idcard/8fa82cfba258498eab2fa818220fb592.jpg"; |
| | | private static String APP_IMAGE_NAME = "5.jpg"; |
| | | @Autowired |
| | | private StringRedisTemplate redisTemplate; |
| | | @Resource |
| | | private RedisTemplate redisTemplate; |
| | | |
| | | private static WxXCXTempSend wxXCXTempSend; |
| | | /** |
| | | * url转变为 MultipartFile对象 |
| | | * |
| | |
| | | * @return |
| | | */ |
| | | public String getAccessToken() throws Exception { |
| | | // String accessToken = ; |
| | | // Boolean aBoolean = redisTemplate.hasKey(SecurityConstants.APPLETS_ACCESS_TOKEN); |
| | | // ValueOperations<String, String> valueOperations = redisTemplate.opsForValue(); |
| | | // if(aBoolean){ |
| | | // Long expireTime = Long.parseLong(valueOperations.get(SecurityConstants.APPLETS_ACCESS_TOKEN_TIME)); |
| | | // if(expireTime <= System.currentTimeMillis()){ |
| | | // redisTemplate.delete(SecurityConstants.APPLETS_ACCESS_TOKEN);//如果过期则删除 |
| | | // 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 + ""); |
| | | // } |
| | | return getAppAccessToken(); |
| | | 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 + ""); |
| | | } |
| | | return accessToken; |
| | | } |
| | | |
| | | public String getAppAccessToken() throws Exception { |
| | |
| | | return null; |
| | | } |
| | | |
| | | @PostConstruct |
| | | public void init() { |
| | | wxXCXTempSend = this; |
| | | wxXCXTempSend.redisTemplate = this.redisTemplate; |
| | | } |
| | | |
| | | } |