Browse Source

推送修改

develop
wangsixiang 6 months ago
parent
commit
8ec92ed1b2
  1. 18
      zc-business/src/main/java/com/zc/business/service/impl/MsmServiceImpl.java

18
zc-business/src/main/java/com/zc/business/service/impl/MsmServiceImpl.java

@ -138,10 +138,10 @@ public class MsmServiceImpl implements IMsmService {
String expiresIn = jsonObject.getString("expires_in");//token有效秒数 String expiresIn = jsonObject.getString("expires_in");//token有效秒数
redisCache.setCacheObject(WEIXINTUISONTOKEN, accessToken, Integer.parseInt(expiresIn), TimeUnit.SECONDS);//把token存入到redis中,并设置过期时间(时间来自于微信接口返回) redisCache.setCacheObject(WEIXINTUISONTOKEN, accessToken, Integer.parseInt(expiresIn), TimeUnit.SECONDS);//把token存入到redis中,并设置过期时间(时间来自于微信接口返回)
} }
JSONArray userListOpenid = msmService.getUserListOpenid(accessToken); JSONArray userListOpenid = msmService.getUserListOpenid(accessToken).getJSONObject("data").getJSONArray("openid");
CountDownLatch latch = new CountDownLatch(userListOpenid.size()); CountDownLatch latch = new CountDownLatch(userListOpenid.size());
for (Object openid : userListOpenid) { for (Object openid : userListOpenid) {
String token = accessToken; String token = redisCache.getCacheObject(WEIXINTUISONTOKEN);
executor.execute(() -> { executor.execute(() -> {
// 封装要发送的json // 封装要发送的json
Map<String, Object> map = new HashMap(); Map<String, Object> map = new HashMap();
@ -190,7 +190,7 @@ public class MsmServiceImpl implements IMsmService {
} }
//获取微信公众号全部关注人的openid //获取微信公众号全部关注人的openid
public static JSONArray getUserListOpenid(String accessToken) { public static com.alibaba.fastjson.JSONObject getUserListOpenid(String accessToken) {
String url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=" + accessToken; String url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=" + accessToken;
com.alibaba.fastjson.JSONObject jsonObj = null; com.alibaba.fastjson.JSONObject jsonObj = null;
try { try {
@ -206,11 +206,19 @@ public class MsmServiceImpl implements IMsmService {
String userOpenid = new String(jsonBytes, "UTF-8"); String userOpenid = new String(jsonBytes, "UTF-8");
jsonObj = com.alibaba.fastjson.JSONObject.parseObject(userOpenid); jsonObj = com.alibaba.fastjson.JSONObject.parseObject(userOpenid);
is.close(); is.close();
if(jsonObj.getInteger("errcode")!=null&&"40001".equals(jsonObj.getInteger("errcode").toString())){//token失效
RedisCache redisCache = SpringUtils.getBean(RedisCache.class);
com.alibaba.fastjson.JSONObject jsonObject =getAccessToken(WEIXINAPPID, WEIXINAPPSECRET);
accessToken = jsonObject.getString("access_token");//获取到了access_token
String expiresIn = jsonObject.getString("expires_in");//token有效秒数
redisCache.setCacheObject(WEIXINTUISONTOKEN, accessToken, Integer.parseInt(expiresIn), TimeUnit.SECONDS);//把token存入到redis中,并设置过期时间(时间来自于微信接口返回)
jsonObj = getUserListOpenid(accessToken);
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
com.alibaba.fastjson.JSONObject data = jsonObj.getJSONObject("data"); return jsonObj;
return data.getJSONArray("openid"); // return data.getJSONArray("openid");
} }
//整合推送 //整合推送
@Override @Override

Loading…
Cancel
Save