| | |
| | | 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 { |
| | | |
| | | public static final String APP_ID = "wx0cef797390444b75"; |
| | | private static final String APP_SECRET = "c7ea9aaa7e391a487e8a5b9ba61045d1"; |
| | | public static final String APP_ID = "wx118de8a734d269f0"; |
| | | private static final String APP_SECRET = "0264342daefde5cd70a6adada09ee5b1"; |
| | | 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 { |
| | | 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")) { |
| | | accessToken = resultMap.get("access_token").toString(); |
| | | } |
| | | } catch (IOException ioe) { |
| | | log.error("小程序http请求异常"); |
| | | ioe.printStackTrace(); |
| | | } |
| | | return accessToken; |
| | | } |
| | | |
| | | /** |
| | | * 获取西区社区通微信token |
| | | * @return 西区社区通微信token |
| | | * @throws Exception 异常 |
| | | */ |
| | | public String getXQAppAccessToken() throws Exception { |
| | | String accessToken = "0"; |
| | | try { |
| | | // 此处APP_ID APP_SECRET 在微信小程序后端可见 |
| | | // String accessTokenUrl = String.format(TEMP_URL, APP_ID, APP_SECRET); |
| | | String accessTokenUrl = ACCESS_TOKEN_URL + "&appid=" + getAppId() + "&secret=" + getAppSecret(); |
| | | 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; |
| | | } |
| | | |
| | | } |