|
@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.google.zxing.BarcodeFormat;
|
|
|
import com.google.zxing.client.j2se.MatrixToImageWriter;
|
|
@@ -20,6 +21,8 @@ import com.zhongzheng.common.utils.http.HttpUtils;
|
|
|
import com.zhongzheng.common.utils.ip.IpUtils;
|
|
|
import com.zhongzheng.modules.alisms.service.IAliSmsService;
|
|
|
import com.zhongzheng.modules.course.bo.SectionWatchPerBo;
|
|
|
+import com.zhongzheng.modules.goods.service.IGoodsService;
|
|
|
+import com.zhongzheng.modules.goods.vo.GoodsVo;
|
|
|
import com.zhongzheng.modules.user.bo.UserWxFollowAddBo;
|
|
|
import com.zhongzheng.modules.user.domain.User;
|
|
|
import com.zhongzheng.modules.user.entity.ClientLoginUser;
|
|
@@ -28,6 +31,7 @@ import com.zhongzheng.modules.user.service.IUserService;
|
|
|
import com.zhongzheng.modules.user.service.IUserWxFollowService;
|
|
|
import com.zhongzheng.modules.wx.bo.TemplatData;
|
|
|
import com.zhongzheng.modules.wx.bo.WxLoginBody;
|
|
|
+import com.zhongzheng.modules.wx.bo.WxShareGoodsBo;
|
|
|
import com.zhongzheng.modules.wx.service.IWxLoginService;
|
|
|
import org.apache.commons.codec.binary.Base64;
|
|
|
import org.slf4j.Logger;
|
|
@@ -38,10 +42,7 @@ import org.springframework.stereotype.Component;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.LinkedHashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
@@ -142,6 +143,9 @@ public class WxLoginService implements IWxLoginService {
|
|
|
@Autowired
|
|
|
private IUserWxFollowService iUserWxFollowService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IGoodsService iGoodsService;
|
|
|
+
|
|
|
|
|
|
public Map<String, String> test_login() {
|
|
|
String unionId = "oQ2yp56PgQ-PfwN4vxTZhR5eTpzk";
|
|
@@ -531,6 +535,19 @@ public class WxLoginService implements IWxLoginService {
|
|
|
obj.put("scene",sceneParam.toString());
|
|
|
obj.put("env_version",enCodeVersion);
|
|
|
String result = HttpUtils.sendPost(url, obj);
|
|
|
+ if (result.contains("errcode")){
|
|
|
+ List<String> codes = Arrays.asList("40001", "42001");
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ if(ObjectUtils.isNotNull(jsonObject.get("errcode")) && codes.contains(jsonObject.get("errcode").toString())){
|
|
|
+ //微信access_token 过期或者失效,刷新access_token
|
|
|
+ String key = "WX_SMALL_ACCESS_TOKEN";
|
|
|
+ redisCache.deleteObject(key);
|
|
|
+ String wxGzhAccessTokenTo = getWxSmallAccessToken();
|
|
|
+ String paramTo = String.format(small_wxEnCodeParam, wxGzhAccessTokenTo);
|
|
|
+ String urlTo = small_wxEnCodeUrl + "?" + paramTo;
|
|
|
+ return HttpUtils.sendPost(urlTo, obj);
|
|
|
+ }
|
|
|
+ }
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -880,6 +897,19 @@ public class WxLoginService implements IWxLoginService {
|
|
|
obj.put("scene",String.format("tid=%s",activityId));
|
|
|
obj.put("env_version",enCodeVersion);
|
|
|
String result = HttpUtils.sendPost(url, obj);
|
|
|
+ if (result.contains("errcode")){
|
|
|
+ List<String> codes = Arrays.asList("40001", "42001");
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ if(ObjectUtils.isNotNull(jsonObject.get("errcode")) && codes.contains(jsonObject.get("errcode").toString())){
|
|
|
+ //微信access_token 过期或者失效,刷新access_token
|
|
|
+ String key = "WX_SMALL_ACCESS_TOKEN";
|
|
|
+ redisCache.deleteObject(key);
|
|
|
+ String wxGzhAccessTokenTo = getWxSmallAccessToken();
|
|
|
+ String paramTo = String.format(small_wxEnCodeParam, wxGzhAccessTokenTo);
|
|
|
+ String urlTo = small_wxEnCodeUrl + "?" + paramTo;
|
|
|
+ return HttpUtils.sendPost(urlTo, obj);
|
|
|
+ }
|
|
|
+ }
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -894,6 +924,64 @@ public class WxLoginService implements IWxLoginService {
|
|
|
obj.put("env_version",enCodeVersion);
|
|
|
// obj.put("env_version","trial");
|
|
|
String result = HttpUtils.sendPost(url, obj);
|
|
|
+ if (result.contains("errcode")){
|
|
|
+ List<String> codes = Arrays.asList("40001", "42001");
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ if(ObjectUtils.isNotNull(jsonObject.get("errcode")) && codes.contains(jsonObject.get("errcode").toString())){
|
|
|
+ //微信access_token 过期或者失效,刷新access_token
|
|
|
+ String key = "WX_SMALL_ACCESS_TOKEN";
|
|
|
+ redisCache.deleteObject(key);
|
|
|
+ String wxGzhAccessTokenTo = getWxSmallAccessToken();
|
|
|
+ String paramTo = String.format(small_wxEnCodeParam, wxGzhAccessTokenTo);
|
|
|
+ String urlTo = small_wxEnCodeUrl + "?" + paramTo;
|
|
|
+ return HttpUtils.sendPost(urlTo, obj);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String shareGoodsCode(WxShareGoodsBo bo) {
|
|
|
+ GoodsVo goodsVo = iGoodsService.queryById(bo.getGoodsId());
|
|
|
+ if(Validator.isEmpty(goodsVo)){
|
|
|
+ throw new CustomException("商品ID错误");
|
|
|
+ }
|
|
|
+ StringBuilder sceneParam = new StringBuilder();
|
|
|
+ String pageUrl = "";
|
|
|
+
|
|
|
+ String wxGzhAccessToken = getWxSmallAccessToken();
|
|
|
+ String param = String.format(small_wxEnCodeParam, wxGzhAccessToken);
|
|
|
+ String url = small_wxEnCodeUrl + "?" + param;
|
|
|
+ JSONObject obj = new JSONObject();
|
|
|
+
|
|
|
+ if(goodsVo.getGoodsType()==2){
|
|
|
+ pageUrl = "pages2/bank/detail";
|
|
|
+ sceneParam.append("id=").append(goodsVo.getGoodsId()).append("&");
|
|
|
+ sceneParam.append("sc=").append(bo.getShareCode());
|
|
|
+ }
|
|
|
+ if(goodsVo.getGoodsType()==1||goodsVo.getGoodsType()==6){
|
|
|
+ pageUrl = "pages3/course/detail";
|
|
|
+ sceneParam.append("id=").append(goodsVo.getGoodsId()).append("&");
|
|
|
+ sceneParam.append("goodsType=").append(goodsVo.getGoodsType()).append("&");
|
|
|
+ sceneParam.append("sc=").append(bo.getShareCode());
|
|
|
+ }
|
|
|
+ obj.put("page", pageUrl);
|
|
|
+ obj.put("scene",sceneParam.toString());
|
|
|
+ obj.put("env_version",enCodeVersion);
|
|
|
+ String result = HttpUtils.sendPost(url, obj);
|
|
|
+ if (result.contains("errcode")){
|
|
|
+ List<String> codes = Arrays.asList("40001", "42001");
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ if(ObjectUtils.isNotNull(jsonObject.get("errcode")) && codes.contains(jsonObject.get("errcode").toString())){
|
|
|
+ //微信access_token 过期或者失效,刷新access_token
|
|
|
+ String key = "WX_SMALL_ACCESS_TOKEN";
|
|
|
+ redisCache.deleteObject(key);
|
|
|
+ String wxGzhAccessTokenTo = getWxSmallAccessToken();
|
|
|
+ String paramTo = String.format(small_wxEnCodeParam, wxGzhAccessTokenTo);
|
|
|
+ String urlTo = small_wxEnCodeUrl + "?" + paramTo;
|
|
|
+ return HttpUtils.sendPost(urlTo, obj);
|
|
|
+ }
|
|
|
+ }
|
|
|
return result;
|
|
|
}
|
|
|
|