|
@@ -9,6 +9,7 @@ import com.fdkankan.tk.common.ResultCode;
|
|
|
import com.fdkankan.tk.common.util.RedisKeyUtil;
|
|
|
import com.fdkankan.tk.common.util.UploadToOssUtil;
|
|
|
import com.fdkankan.tk.entity.Room;
|
|
|
+import com.fdkankan.tk.entity.WxConfig;
|
|
|
import com.fdkankan.tk.entity.WxUser;
|
|
|
import com.fdkankan.tk.exception.BusinessException;
|
|
|
import com.fdkankan.tk.httpClient.client.WxClient;
|
|
@@ -53,6 +54,8 @@ public class WxServiceImpl implements IWxService {
|
|
|
String envVersion;
|
|
|
@Value("${wx.path}")
|
|
|
String wxPath;
|
|
|
+ @Autowired
|
|
|
+ IWxConfigService wxConfigService;
|
|
|
|
|
|
//二维码
|
|
|
static String getWxQrCodeUrl ="https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token=%s";
|
|
@@ -61,11 +64,15 @@ public class WxServiceImpl implements IWxService {
|
|
|
|
|
|
@Override
|
|
|
public String getToken(){
|
|
|
- String redisKey = RedisKeyUtil.AccessToken + WxConfigServiceImpl.wxConfig.getAppId();
|
|
|
+ WxConfig wxConfig = wxConfigService.getWxConfig();
|
|
|
+ if(wxConfig == null){
|
|
|
+ throw new BusinessException(ResultCode.WX_CONFIG_ERROR);
|
|
|
+ }
|
|
|
+ String redisKey = RedisKeyUtil.AccessToken + wxConfig.getAppId();
|
|
|
if(redisUtil.hasKey(redisKey)){
|
|
|
return redisUtil.get(redisKey);
|
|
|
}
|
|
|
- JSONObject jsonObject = wxClient.getToken(WxConfigServiceImpl.wxConfig.getAppId(), WxConfigServiceImpl.wxConfig.getAppSecret());
|
|
|
+ JSONObject jsonObject = wxClient.getToken(wxConfig.getAppId(), wxConfig.getAppSecret());
|
|
|
String access_token = jsonObject.getString("access_token");
|
|
|
if(StringUtils.isNotBlank(access_token)){
|
|
|
redisUtil.set(redisKey,access_token,7000);
|
|
@@ -77,6 +84,10 @@ public class WxServiceImpl implements IWxService {
|
|
|
//生成分享二维码
|
|
|
@Override
|
|
|
public void getWxQRCode(String path, String targetTmpPath,Integer reCount) {
|
|
|
+ WxConfig wxConfig = wxConfigService.getWxConfig();
|
|
|
+ if(wxConfig == null){
|
|
|
+ throw new BusinessException(ResultCode.WX_CONFIG_ERROR);
|
|
|
+ }
|
|
|
InputStream is = null;
|
|
|
FileOutputStream fileOutputStream =null;
|
|
|
try {
|
|
@@ -97,7 +108,7 @@ public class WxServiceImpl implements IWxService {
|
|
|
int errcode = jsonObject.getInteger("errcode");
|
|
|
if(errcode == 40001) {
|
|
|
log.info("token过期了");
|
|
|
- String redisKey = RedisKeyUtil.AccessToken + WxConfigServiceImpl.wxConfig.getAppId();
|
|
|
+ String redisKey = RedisKeyUtil.AccessToken + wxConfig.getAppId();
|
|
|
redisUtil.del(redisKey);
|
|
|
getWxQRCode(path, targetTmpPath,reCount);
|
|
|
}
|