快捷搜索:

微信协议接口调用-群发微信好友,群发群消息

微信协议接口调用-群发微信好友,群发群消息

群发微信好友、群发群
private static void talkMsgToFriend(TaskTimeInfo info, TimeTaskDetailsDao timeTaskDetailsDao,

List<String> friends) {
String executeTime = info.getExecute_time();
Date newDate = DateUtil.convertString2Date(executeTime, DateUtil.DATE_FORMAT_4);
Integer betweenTime = info.getBetween_time();

if (betweenTime ==null || betweenTime==0) {
betweenTime = (int)(Math.random()*3+3);
}

for (String friend : friends) {

String newExecuteTime = DateUtil.convertDate2String(newDate, DateUtil.DATE_FORMAT_4);
String msgStr = "";
String jsonStr = info.getContent();
List<MessageVo> list = JsonUtils.json2Bean(jsonStr);

for (int i = 0; i < list.size(); i++) {
MessageVo msg = list.get(i);

ByteString byteString = ByteString.copyFromUtf8(msg.getContent());

TalkToFriendTaskMessage.Builder build = TalkToFriendTaskMessage.newBuilder();
build.setWeChatId(info.getWechatId());
build.setFriendId(friend);
build.setContent(byteString);
build.setMsgId(MsgIdBuilder.getId());

if (msg.getContentType().equalsIgnoreCase("Text")) {// 文本类型
build.setContentType(EnumContentType.Text);
} else if (msg.getContentType().equalsIgnoreCase("Picture")) {// 图片类型
build.setContentType(EnumContentType.Picture);
} else if (msg.getContentType().equalsIgnoreCase("Voice")) {// 语音类型
build.setContentType(EnumContentType.Voice);
} else if (msg.getContentType().equalsIgnoreCase("Video")) {// 视频类型
build.setContentType(EnumContentType.Video);
} else if (msg.getContentType().equalsIgnoreCase("Link")) {// 链接类型
build.setContentType(EnumContentType.Link);
} else if (msg.getContentType().equalsIgnoreCase("WeApp")) {// 小程序
build.setContentType(EnumContentType.WeApp);
}

TalkToFriendTaskMessage msg1 = build.build();
if (null != msg1) {
try {
String json = JsonFormat.printer().print(msg1);

if (!StringUtils.isEmpty(json)) {
msgStr = msgStr + json;
if (i != (list.size() - 1)) {
msgStr = msgStr + "&&";
}
}
} catch (Exception e) {
e.printStackTrace();
}
}

}

if (null != msgStr) {
try {
if (!StringUtils.isEmpty(msgStr)) {
TimeTaskDetails detail = new TimeTaskDetails();
detail.setTid(info.getId());
detail.setExecute_time(newExecuteTime);
detail.setJson_content(msgStr);
detail.setMsgid(String.valueOf(MsgIdBuilder.getId()));
timeTaskDetailsDao.insert(detail);
}
} catch (Exception e) {
e.printStackTrace();
}
}

newDate = DateUtil.offsetSecode(newDate, betweenTime);

}
}

微信协议接口调用-群发微信好友,群发群消息

以上代码依赖微信开发SDK,微信api接口方案咨询微信happybabby110

微信聚合聊天客服系统--微信SDK方案演示系统

拓展阅读:http://www.wlkankan.cn/cate41/301.html



文章来自:微赚淘客
分享地址:/bbs/cate40/211320.html