聚合微信聊天crm调用代码
聚合微信聊天crm调用代码
/**
* 群发好友消息任务
*
* @author wechatno:tangjinjinwx
* @blog http://www.wlkankan.cn
*/
@Async
public void handleMsg(ChannelHandlerContext ctx, TransportMessage vo, String contentJsonStr) {try {log.debug(contentJsonStr);
WeChatGroupSendTaskMessage.Builder bd = WeChatGroupSendTaskMessage.newBuilder();
JsonFormat.parser().merge(contentJsonStr, bd);
WeChatGroupSendTaskMessage req = bd.build();asyncTaskService.msgSend2Phone(ctx, req.getWeChatId(), EnumMsgType.WeChatGroupSendTask, vo, req);
} catch (Exception e) {e.printStackTrace();
MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);
}
}/**
* 群发群消息任务
* 接口参考http://www.wlkankan.cn/cate40/247.html
* @author wechatno:tangjinjinwx
*/private static void talkMsgToFriend(TaskTimeInfo info, TimeTaskDetailsDao timeTaskDetailsDao,List<String> friends) {for(String friend:friends){ByteString byteString = ByteString.copyFromUtf8(info.getContent());
TalkToFriendTaskMessage.Builder build=TalkToFriendTaskMessage.newBuilder();
build.setWeChatId(info.getWechatId());
build.setFriendId(friend);
build.setContent(byteString);
build.setMsgId(MsgIdBuilder.getId());
if(info.getRestype()==1){//文本类型
build.setContentType(EnumContentType.Text);
}else if(info.getRestype()==2){//图片类型
build.setContentType(EnumContentType.Picture);
}else if(info.getRestype()==3){//语音类型
build.setContentType(EnumContentType.Voice);
}else if(info.getRestype()==4){//视频类型
build.setContentType(EnumContentType.Video);
}else if(info.getRestype()==6){//链接类型
build.setContentType(EnumContentType.Link);
}else if(info.getRestype()==13){//小程序
build.setContentType(EnumContentType.WeApp);
}
TalkToFriendTaskMessage msg = build.build();
if (null != msg) {try {String json = JsonFormat.printer().print(msg);
if(!StringUtils.isEmpty(json)){TimeTaskDetails detail = new TimeTaskDetails();
detail.setTid(info.getId());
detail.setExecute_time(info.getExecute_time());
detail.setJson_content(json);
timeTaskDetailsDao.insert(detail);
}
} catch (Exception e) {e.printStackTrace();
}
}
}
}1、微信好友收发消息/*** 给微信好友发消息* @author wechatno:tangjinjinwx* @blog http://www.wlkankan.cn*/@Asyncpublic void handleMsg(ChannelHandlerContext ctx, TransportMessage vo, String contentJsonStr) {try {log.debug(contentJsonStr);TalkToFriendTaskMessage.Builder bd = TalkToFriendTaskMessage.newBuilder();JsonFormat.parser().merge(contentJsonStr, bd);TalkToFriendTaskMessage req = bd.build();// 消息记录数据库asyncTaskService.savePcMessage(req);// 将消息转发送给手机客户端asyncTaskService.msgSend2Phone(ctx, req.getWeChatId(), EnumMsgType.TalkToFriendTask, vo, req);} catch (Exception e) {e.printStackTrace();MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);}}/*** 微信好友发来聊天消息通知* @author wechatno:tangjinjinwx* @blog http://www.wlkankan.cn*/@Asyncpublic void handleMsg(ChannelHandlerContext ctx, TransportMessage vo) {try {FriendTalkNoticeMessage req = vo.getContent().unpack(FriendTalkNoticeMessage.class);log.debug(JsonFormat.printer().print(req));log.debug(LocalDateTime.now()+" 微信好友发来聊天消息 对应的线程名: "+Thread.currentThread().getName());//拦截消息asyncTaskService.msgAopTask(ctx,req,vo.getAccessToken(), vo.getId());//消息转发到pc端asyncTaskService.msgSend2pc(req.getWeChatId(), EnumMsgType.FriendTalkNotice, req);// 告诉客户端消息已收到MessageUtil.sendMsg(ctx, EnumMsgType.MsgReceivedAck, vo.getAccessToken(), vo.getId(), null);WxAccountInfo account = weChatAccountService.findWeChatAccountInfoByWeChatId(req.getWeChatId());//消息记录数据库if (null != account){asyncTaskService.saveMessage(account, req);}} catch (Exception e) {e.printStackTrace();MessageUtil.sendErrMsg(ctx, EnumErrorCode.InvalidParam,vo.getId(), e.getMessage());}}2、触发手机推送微信好友列表及返回/*** 触发手机推送微信好友列表* @author wechatno:tangjinjinwx* @blog http://www.wlkankan.cn*/@Asyncpublic void handleMsg(ChannelHandlerContext ctx,TransportMessage vo, String contentJsonStr) {try {log.debug(contentJsonStr);TriggerFriendPushTaskMessage.Builder bd = TriggerFriendPushTaskMessage.newBuilder();JsonFormat.parser().merge(contentJsonStr, bd);TriggerFriendPushTaskMessage req = bd.build();//TriggerFriendPushTaskMessage req = vo.getContent().unpack(TriggerFriendPushTaskMessage.class);//将消息转发送给手机客户端asyncTaskService.msgSend2Phone(ctx, req.getWeChatId(), EnumMsgType.TriggerFriendPushTask, vo, req);} catch (Exception e) {e.printStackTrace();MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);}}/*** 微信好友列表消息推送* @author wechatno:tangjinjinwx* @blog http://www.wlkankan.cn*/@Asyncpublic void handleMsg(ChannelHandlerContext ctx, TransportMessage vo) {try {FriendPushNoticeMessage req = vo.getContent().unpack(FriendPushNoticeMessage.class);log.debug(JsonFormat.printer().print(req));// 把消息转发给pc端asyncTaskService.msgSend2pc(req.getWeChatId(), EnumMsgType.FriendPushNotice, req);// 异步保存到数据库asyncTaskService.friendListSave(req);// 告诉客户端消息已收到MessageUtil.sendMsg(ctx, EnumMsgType.MsgReceivedAck, vo.getAccessToken(), vo.getId(), null);} catch (Exception e) {e.printStackTrace();MessageUtil.sendErrMsg(ctx, EnumErrorCode.InvalidParam, vo.getId(), Constant.ERROR_MSG_DECODFAIL);}}3、触发推送微信群聊列表及返回/*** 触发推送微信群聊列表* @author wechatno:tangjinjinwx* @blog http://www.wlkankan.cn*/@Asyncpublic void handleMsg(ChannelHandlerContext ctx, TransportMessage vo, String contentJsonStr) {try {log.debug(contentJsonStr);TriggerChatRoomPushTaskMessage.Builder bd = TriggerChatRoomPushTaskMessage.newBuilder();JsonFormat.parser().merge(contentJsonStr, bd);TriggerChatRoomPushTaskMessage req = bd.build();// 将消息转发送给手机客户端asyncTaskService.msgSend2Phone(ctx, req.getWeChatId(), EnumMsgType.TriggerChatroomPushTask, vo, req);} catch (Exception e) {e.printStackTrace();MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);}}/*** 推送微信群聊列表* @author wechatno:tangjinjinwx* @blog http://www.wlkankan.cn*/@Asyncpublic void handleMsg(ChannelHandlerContext ctx, TransportMessage vo) {try {ChatRoomPushNoticeMessage req = vo.getContent().unpack(ChatRoomPushNoticeMessage.class);log.debug(JsonFormat.printer().print(req));asyncTaskService.msgSend2pc(req.getWeChatId(), EnumMsgType.ChatroomPushNotice, req);asyncTaskService.qunListSave(req);// 告诉客户端消息已收到MessageUtil.sendMsg(ctx, EnumMsgType.MsgReceivedAck, vo.getAccessToken(), vo.getId(), null);} catch (Exception e) {e.printStackTrace();MessageUtil.sendErrMsg(ctx, EnumErrorCode.InvalidParam,vo.getId(), Constant.ERROR_MSG_DECODFAIL);}}4、推送微信朋友圈、发朋友圈/*** 触发推送朋友圈列表* @author wechatno:tangjinjinwx * startTime传秒* @blog http://www.wlkankan.cn*/@Asyncpublic void handleMsg(ChannelHandlerContext ctx, TransportMessage vo, String contentJsonStr) {try {log.debug(contentJsonStr);TriggerCirclePushTaskMessage.Builder bd = TriggerCirclePushTaskMessage.newBuilder();JsonFormat.parser().merge(contentJsonStr, bd);TriggerCirclePushTaskMessage req = bd.build();// TriggerCirclePushTaskMessage req =// vo.getContent().unpack(TriggerCirclePushTaskMessage.class);// 将消息转发送给手机客户端asyncTaskService.msgSend2Phone(ctx, req.getWeChatId(), EnumMsgType.TriggerCirclePushTask, vo, req);} catch (Exception e) {e.printStackTrace();MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);}}/*** 回传手机微信朋友圈数据* @author wechatno:tangjinjinwx* @blog http://www.wlkankan.cn*/@Asyncpublic void handleMsg(ChannelHandlerContext ctx, TransportMessage vo) {try {CirclePushNoticeMessage req = vo.getContent().unpack(CirclePushNoticeMessage.class);log.debug(JsonFormat.printer().print(req));//把消息转发给pc端asyncTaskService.msgSend2pc(req.getWeChatId(), EnumMsgType.CirclePushNotice, req);//保存朋友圈信息asyncTaskService.asyncSaveCircleMsg(req, circleService, weChatContactService);//告诉客户端消息已收到MessageUtil.sendMsg(ctx, EnumMsgType.MsgReceivedAck, vo.getAccessToken(), vo.getId(), null);} catch (Exception e) {e.printStackTrace();MessageUtil.sendErrMsg(ctx, EnumErrorCode.InvalidParam,vo.getId(), Constant.ERROR_MSG_DECODFAIL);}}/*** 发微信朋友圈* @author wechatno:tangjinjinwx* @blog http://www.wlkankan.cn*/@Asyncpublic void handleMsg(ChannelHandlerContext ctx,TransportMessage vo, String contentJsonStr) {try {log.debug(contentJsonStr);PostSNSNewsTaskMessage.Builder bd = PostSNSNewsTaskMessage.newBuilder();JsonFormat.parser().merge(contentJsonStr, bd);PostSNSNewsTaskMessage req = bd.build();//PostSNSNewsTaskMessage req = vo.getContent().unpack(PostSNSNewsTaskMessage.class);asyncTaskService.msgSend2Phone(ctx, req.getWeChatId(), EnumMsgType.PostSNSNewsTask, vo, req);} catch (Exception e) {e.printStackTrace();MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);}}5、加好友及通过好友请求/** * 微信自动添加好友* @author wechatno:tangjinjinwx* @blog http://www.wlkankan.cn*/@Asyncpublic void handleMsg(ChannelHandlerContext ctx ,TransportMessage vo, String contentJsonStr) {try {log.debug(contentJsonStr);FriendAddTaskSetting req = JSON.parseObject(contentJsonStr,FriendAddTaskSetting.class);if(null != req){String resp ="fail";resp = friendAddTaskService.savePcTask(req);//3、告诉PC客户端消息已收到MessageUtil.sendCustomJsonMsg(ctx, "AutoFriendAddTaskResp", resp);} } catch (Exception e) {e.printStackTrace();MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);}}/*** 微信新增好友通知* @author wechatno:tangjinjinwx* @blog http://www.wlkankan.cn*/@Asyncpublic void handleMsg(ChannelHandlerContext ctx, TransportMessage vo) {try {FriendAddNoticeMessage req = vo.getContent().unpack(FriendAddNoticeMessage.class);//把消息转发给pc端asyncTaskService.msgSend2pc(req.getWeChatId(), EnumMsgType.FriendAddNotice, req);//保存新增好友asyncTaskService.saveFriendAddContactinfo(req);//告诉客户端消息已收到MessageUtil.sendMsg(ctx, EnumMsgType.MsgReceivedAck, vo.getAccessToken(), vo.getId(), null);} catch (Exception e) {e.printStackTrace();MessageUtil.sendErrMsg(ctx, EnumErrorCode.InvalidParam,vo.getId(), Constant.ERROR_MSG_DECODFAIL);}}
TalkToFriendTaskMessage、TriggerChatRoomPushTaskMessage、TriggerCirclePushTaskMessage、PostSNSNewsTaskMessage、FriendAddTaskSetting、WeChatGroupSendTaskMessage等是封装类,个人博客有详细介绍。
聚合微信聊天crm调用代码相关推荐
- 微信群发接口调用代码
//找到需要发的微信号,参考https://www.wuliaokankan.cn/url301/138.html List<AccountInfo> accLis ...
- 微信公众号图灵机器人开发php,使用图灵机器人api搭建微信聊天机器人php实现,图灵微信聊天机器人...
使用图灵机器人api搭建微信聊天机器人php实现,图灵微信聊天机器人之前通过hook技术实现了微信pc端发送消息功能,如果在结合图灵机器人就能实现微信聊天机器人. 代码下载:http://blog.y ...
- 【模仿】调用微信聊天功能和分享功能
今天整理个不是问题的问题,没学到啥,主要完成功能: 老大要求能调用手机号码然后通过微信聊, 我去,说白了老大看到了应用-通讯录plus-的微信功能,要我模仿. 首先,坑啊,我以为是开放的功能,就去看了 ...
- Python30行代码实现微信聊天机器人(基于WXPY+百度理解与交互技术UNIT)
引言: 前几天看到新闻说一个程序员开发了微信聊天机器人陪女朋友聊天,感觉有兴趣,之前听说过WXPY,由于本人Python真的很菜,一直没有动手,受新闻启发开发了一个简单的基于Python微信机器人.有 ...
- 个人微信api接口java调用代码
个人微信api接口java调用代码 1.微信好友收发消息 /** * 给微信好友发消息 * @author wechatno:tangjinjinwx * ...
- html5图灵机器人自动会话代码,Vue结合图灵机器人制作的一个简单的仿微信聊天的自动回复机器人...
HTML5模拟微信聊天界面 /**重置标签默认样式*/ * { margin: 0; padding: 0; list-style: none; font-family: '微软雅黑' } #cont ...
- java 朋友圈分享接口_微信发朋友圈api接口调用代码
微信发朋友圈api接口调用代码,推送微信朋友圈.发朋友圈 /** * 触发推送朋友圈列表 * @author wechatno:tangjinjinwx * startTime传秒 * @blog h ...
- html5仿网页版微信聊天界面代码
2019独角兽企业重金招聘Python工程师标准>>> html5仿网页版微信聊天界面代码 转载于:https://my.oschina.net/u/1266171/blog/783 ...
- android仿微信聊天功能,Android高仿微信聊天界面代码分享
微信聊天现在非常火,是因其界面漂亮吗,哈哈,也许吧.微信每条消息都带有一个气泡,非常迷人,看起来感觉实现起来非常难,其实并不难.下面小编给大家分享实现代码. 先给大家展示下实现效果图: OK,下面我们 ...
最新文章
- 一键下载,双击上传,带你探索提升工作效率的秘密“武器”
- 《javaScript100例|04》自动播放——Js幻灯片缓冲效果
- [html] 如何根据设备尺寸做页面自适应?
- linux获取文件的md5,linux shell 获取文件md5的命令linux操作系统 -电脑资料
- 女程序媛面试总结:我是这样脱颖而出的
- 【Python】http.client库的用法
- 推荐算法-GBDT与LR算法融合
- setting文件详解
- 前端后台常见问题总结
- 计算机上e盘拒绝访问,E盘拒绝访问怎么办?Win7系统E盘拒绝访问的方法
- 工业级POE交换机、企业级交换机、普通交换机之间各区别?
- 选择第K大元素(快排、快选以及k-选取比较)
- mybatis+spring+springmvc ssm整合
- 为何vSAN需要至少2n+1台主机,来防止n台主机出现故障(FTT=n)?
- 【25】数据可视化:基于 Echarts + Python Flask框架动态实时大屏范例 - 企业宣传
- 基于Simulink的雷达系统射频前端建模仿真(附源码)
- STM32——I2S简介硬件连接
- 未来可能发生的十大颠覆性科技创新
- js中关于length与size的区别
- [html5游戏开发]经典的推箱子