| | |
| | | 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; |
| | | 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; |
| | | @Resource |
| | | private StringRedisTemplate stringRedisTemplate; |
| | | UserService userService; |
| | | |
| | | 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 = ""; |
| | | 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")) { |
| | |
| | | return null; |
| | | } |
| | | |
| | | @PostConstruct |
| | | public void init() { |
| | | wxXCXTempSend = this; |
| | | wxXCXTempSend.redisTemplate = this.redisTemplate; |
| | | wxXCXTempSend.stringRedisTemplate=this.stringRedisTemplate; |
| | | } |
| | | |
| | | } |