Json化数据-调微信接口

// 先获取用户openid列表
List<String> openids = wxPhotoUpload.getUserOpenIdList(access_token);
TreeMap<String, String> params = new TreeMap<>();
params.put("access_token", access_token);
// post 提交的参数
Map<String, Object> mpnewsParams = new HashMap<>();
mpnewsParams.put("media_id", messageMediaId);
TreeMap<String,Object> dataParams = new TreeMap<>();
dataParams.put("touser", openids);
dataParams.put("mpnews", mpnewsParams);
dataParams.put("msgtype", "mpnews");
dataParams.put("send_ignore_reprint", 0);
String data = JSON.toJSONString(dataParams);
String URL = "https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token="+access_token; // 正式群发接口
// String URL = "https://api.weixin.qq.com/cgi-bin/message/mass/preview?access_token="+access_token; // 阅览群发接口
String jsonStr = HttpClientUtil.post(URL, data);
if(jsonStr.indexOf("msg_id") != -1 ){
jsonStr = jsonStr.replaceAll("[\\]", "");
net.sf.json.JSONObject resultJSON= net.sf.json.JSONObject.fromObject(jsonStr);
if (resultJSON != null && resultJSON.get("msg_id") != null) {
groupWxMessage.setUploadTime(new Date());
groupWxMessage.setGmtModified(new Date());
if(groupWxMessage.getStatus() ==1 ){
groupWxMessage.setStatus(2);
}
i = groupWxMessageMapper.updateByPrimaryKeySelective(groupWxMessage);
}
}
原文地址:https://www.cnblogs.com/jabez1992/p/9722322.html