| | |
| | | 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, getAppAccessToken()); |
| | | 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=wxXCXTempSend.stringRedisTemplate.boundValueOps("access_token:access_token:"+this.getAppId()).get(); |
| | | return accessToken; |
| | | } |
| | | public String getAccessToken(String appid) throws Exception { |
| | | String accessToken = ""; |
| | | accessToken=wxXCXTempSend.stringRedisTemplate.boundValueOps("access_token:access_token:"+appid).get(); |
| | | return accessToken; |
| | | } |
| | | |
| | |
| | | } |
| | | return accessToken; |
| | | } |
| | | |
| | | public String getWsAccessToken() throws Exception { |
| | | String accessToken = "0"; |
| | | try { |
| | | // log.info("获取微信token参数:appid=" + APP_ID + ",appSecret=" + APP_SECRET); |
| | | String accessTokenUrl = ACCESS_TOKEN_URL + "&appid=wx98d62711dfbd8425"+ "&secret=97a2a10b990c2774ed279724337b5337"; |
| | | String result = HttpClientUtil.httpGet(accessTokenUrl, null, null); |
| | | Map<String, Object> resultMap = JSON.parseObject(result, Map.class); |
| | | if (resultMap.containsKey("access_token")) { |
| | | accessToken = resultMap.get("access_token").toString(); |
| | | } |
| | | } catch (IOException ioe) { |
| | | log.error("小程序http请求异常"); |
| | | ioe.printStackTrace(); |
| | | } |
| | | return accessToken; |
| | | } |
| | | /** |
| | | * 获取西区社区通微信token |
| | | * @return 西区社区通微信token |
| | |
| | | public void init() { |
| | | wxXCXTempSend = this; |
| | | wxXCXTempSend.redisTemplate = this.redisTemplate; |
| | | wxXCXTempSend.stringRedisTemplate=this.stringRedisTemplate; |
| | | } |
| | | |
| | | } |