|
@@ -7,6 +7,7 @@ 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.StringUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.google.zxing.BarcodeFormat;
|
|
|
import com.google.zxing.client.j2se.MatrixToImageWriter;
|
|
@@ -29,9 +30,7 @@ import com.zhongzheng.modules.user.entity.ClientLoginUser;
|
|
|
import com.zhongzheng.modules.user.mapper.UserMapper;
|
|
|
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.bo.*;
|
|
|
import com.zhongzheng.modules.wx.service.IWxLoginService;
|
|
|
import org.apache.commons.codec.binary.Base64;
|
|
|
import org.slf4j.Logger;
|
|
@@ -128,6 +127,10 @@ public class WxLoginService implements IWxLoginService {
|
|
|
|
|
|
private String small_wxEnCodeParam = "access_token=%s";
|
|
|
|
|
|
+ private String small_LinkUrl = "https://api.weixin.qq.com/wxa/generate_urllink";
|
|
|
+
|
|
|
+ private String small_LinkParam = "access_token=%s";
|
|
|
+
|
|
|
@Autowired
|
|
|
private IUserService iUserService;
|
|
|
|
|
@@ -985,6 +988,73 @@ public class WxLoginService implements IWxLoginService {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public WxInfoBo getWxInfo(WxInfoQuery query) {
|
|
|
+ Long time = System.currentTimeMillis();
|
|
|
+ String nonceStr = UUID.randomUUID().toString();
|
|
|
+ String ticket = "";
|
|
|
+ String signature = "";
|
|
|
+ //获取ticket
|
|
|
+ String url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket";
|
|
|
+ String param = String.format("access_token=%s&type=jsapi", getWxSmallAccessToken());
|
|
|
+ String result = HttpUtils.sendGet(url, param);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ if (Integer.valueOf(jsonObject.get("errcode").toString()) != 0){
|
|
|
+ //请求失败(可能是access_token过期或者失效)刷新access_token
|
|
|
+ String key = "WX_SMALL_ACCESS_TOKEN";
|
|
|
+ redisCache.deleteObject(key);
|
|
|
+ param = String.format("access_token=%s&type=jsapi", getWxSmallAccessToken());
|
|
|
+ result = HttpUtils.sendGet(url, param);
|
|
|
+ jsonObject = JSONObject.parseObject(result);
|
|
|
+ }
|
|
|
+ ticket = jsonObject.get("ticket").toString();
|
|
|
+ if (StringUtils.isBlank(ticket)){
|
|
|
+ throw new CustomException("微信ticket获取失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ //签名 = 随机串 + ticket + 时间戳 + URL(当前页面)
|
|
|
+ signature = nonceStr+ticket+time+query.getWebUrl();
|
|
|
+
|
|
|
+ WxInfoBo bo = new WxInfoBo();
|
|
|
+ bo.setWxAppId(appid);
|
|
|
+ bo.setTimestamp(time);
|
|
|
+ bo.setSignature(signature);
|
|
|
+ bo.setNonceStr(nonceStr);
|
|
|
+ bo.setAppUrl("pages/index/index");
|
|
|
+ bo.setUsername("gh_9bdfc9ccd1fa");
|
|
|
+ return bo;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getWxSmallLink() {
|
|
|
+ String wxGzhAccessToken = getWxSmallAccessToken();
|
|
|
+ String param = String.format(small_LinkParam, wxGzhAccessToken);
|
|
|
+ String url = small_LinkUrl + "?" + param;
|
|
|
+ JSONObject obj = new JSONObject();
|
|
|
+ obj.put("path", "pages/index/index");
|
|
|
+ obj.put("is_expire",true);
|
|
|
+ obj.put("expire_type",1);
|
|
|
+ obj.put("expire_interval",1);
|
|
|
+ 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_LinkParam, wxGzhAccessTokenTo);
|
|
|
+ String urlTo = small_LinkUrl + "?" + paramTo;
|
|
|
+ result = HttpUtils.sendPost(urlTo, obj);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+
|
|
|
+ return jsonObject.get("url_link").toString();
|
|
|
+ }
|
|
|
+
|
|
|
public Boolean subGzh(String openId) {
|
|
|
String unionId = getWxGzhUserCgiInfo(openId);
|
|
|
if (Validator.isNotEmpty(unionId)) {
|