个人微信api接口调用,微信加好友、新增好友通知
加好友及通过好友请求
/**
* 微信自动添加好友
* @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);
}
}
FriendAddTaskSetting 、FriendAddNoticeMessage 类是自己封装的,具体个人博客有介绍