个人微信api接口源代码
个人微信api接口调用源码
1、微信好友收发消息
/**
* 给微信好友发消息
* @author wechatno:tangjinjinwx
* @blog http://www.wlkankan.cn
*/
@Async
public 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
*/
@Async
public 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
*/
@Async
public 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
*/
@Async
public 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
*/
@Async
public 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
*/
@Async
public 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
*/
@Async
public 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
*/
@Async
public 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
*/
@Async
public 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
*/
@Async
public 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
*/
@Async
public 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);
}
}
个人微信api接口源代码相关推荐
- 微信api接口调用-发朋友圈
微信api接口调用-发朋友圈 /*** 发微信朋友圈* @author wechatno:tangjinjinwx* @blog http://www.wlkankan.cn*/@Asyncpubli ...
- java给朋友发微信_微信api接口,给微信好友收发消息
微信api接口,给微信好友收发消息 /** * 给微信好友发消息 * @author wechatno:tangjinjinwx * @blog http://www.wlkankan.cn */ @ ...
- php获取蓝奏云直连,最新php蓝奏云直链api接口源代码
最新php蓝奏云直链API接口源代码<?php $url=base64_decode('aHR0cHM6Ly9hcGkucGluZ3Bpbmc2LmNvbS90b29scy9sYW56b3Uv' ...
- 最新php蓝奏云直链api接口源代码
最新php蓝奏云直链API接口源代码 <?php$url=base64_decode('aHR0cHM6Ly9hcGkucGluZ3Bpbmc2LmNvbS90b29scy9sYW56b3Uv' ...
- 个人微信api接口调用-微信群管理
个人微信api接口调用-微信群管理 /*** 微信群聊管理* @author wechatno:tangjinjinwx* @blog http://www.wlkankan.cn*/@Asyncpu ...
- 微信API接口目录大全
微信API接口目录大全 1.基础消息类型 1.客户端发送的心跳包HeartBeatReq = 1001; 2.消息接收确认回复(接收或拒绝接收)MsgReceivedAck = 1002; 3.错 ...
- 微信API接口、微信二次开发API调用
微信API接口.微信二次开发API调用 微信协议接口调用-加微信好友及通过好友请求 加微信好友 /** * 微信自动添加好友 * @author wechatno:tangjin ...
- 个人微信api接口调用-给微信好友或群聊发消息
个人微信api接口调用-给微信好友或群聊发消息 /*** 给微信好友发消息* @author wechatno:tangjinjinwx* @blog http://www.wlkankan.cn*/ ...
- java版微信朋友圈_java调用个人微信API接口发朋友圈,评论和删除朋友圈
java调用个人微信API接口发朋友圈,评论和删除朋友圈 /** * 发送朋友圈任务 * @author wechatno:tangjinjinwx * @param ctx * @param vo ...
最新文章
- 借助深度卷积神经网络对图片 GIF 视频进行超分辨率放大(即放大与降噪) 以及 对视频进行 插帧(即补帧).
- php mysql备份成sql_单php文件实现备份MySQL导出为.sql数据库代码
- linux编写复制脚本程,常用的Shell脚本
- android 例子源码_AOSP系列文章(一)-Android系统源码下载和编译
- 决策树缺失值python_【机器学习笔记之二】决策树的python实现
- 混淆矩阵与精确度、召回率、F1 Score
- Vue CLI 3.0 正式发布,Vue.js 开发标准化工具
- 从caffe2 开源的代码中抽取 用于加载已训练神经网络参数,使用CPU进行预测的 部分代码,并运行成功一个预测模型...
- [原译]实现IEnumerable接口理解yield关键字
- 拥塞控制,图文并茂(挺丰富,借鉴较多大佬的思想)
- 不足300的游戏蓝牙耳机靠谱吗?五款高人气蓝牙耳机测评
- Android中app的请求抓包工具 Fiddler 详解
- 按键精灵手机助手错误:at tempt to compare nu11 with number
- python程序设计实用教程答案_Python程序设计实用教程
- bzoj5145 [Ynoi2018]未来日记 (多校第4场1013 Yuno and Claris)
- java id 锁_java 多线程synchronized同步锁锁住相同用户Id
- 实现蓝色理想的运行代码
- 【Scratch画图100例】图39-scratch实心圆 少儿编程 scratch编程画图案例教程 考级比赛画图集训案例
- 金蝶专业版过账提示运行时错误5_金蝶专业版过账提示运行时错误5_金蝶KIS专业版常见故障及解决办法...
- 2022-11-01 网工进阶(三十四) IP组播协议(PIM)-模式概述、组播分发树的分类、PIM路由表项、PIM-DM工作原理(组播分发树的形成、配置举例)