企業微信api,企業微信sdk接口
1、企業微信SDK接口API調用-企業微信好友收發消息
/**
* 給企業微信好友發消息
* @author wechat:happybabby110
* @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.msgSend2Phone(ctx, String.valueOf(req.getWxId()), EnumMsgType.TalkToFriendTask, vo, req);
} catch (Exception e) {
e.printStackTrace();
MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);
}
}
/**
* 企業微信好友發來聊天消息
* @author wechat:happybabby110
* @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());
//消息轉發到pc端
asyncTaskService.msgSend2pc(String.valueOf(req.getWxId()), EnumMsgType.FriendTalkNotice, req);
// 告訴客戶端消息已收到
MessageUtil.sendMsg(ctx, EnumMsgType.MsgReceivedAck, vo.getAccessToken(), vo.getId(), null);
} catch (Exception e) {
e.printStackTrace();
MessageUtil.sendErrMsg(ctx, EnumErrorCode.InvalidParam,vo.getId(), e.getMessage());
}
}
2、企業微信SDK接口API調用-通過手機號或微信好友添加客戶
/**
* 企業微信搜索手機號添加微信
* @author wechat:happybabby110
* @blog http://www.wlkankan.cn
*/
public void handleMsg(ChannelHandlerContext ctx ,TransportMessage vo, String contentJsonStr) {
try {
log.debug(contentJsonStr);
AddCustomerFromSearchTaskMessage.Builder bd = AddCustomerFromSearchTaskMessage.newBuilder();
JsonFormat.parser().merge(contentJsonStr, bd);
AddCustomerFromSearchTaskMessage req = bd.build();
// 將消息轉發送給手機客戶端
asyncTaskService.msgSend2Phone(ctx, String.valueOf(req.getWxId()), EnumMsgType.AddCustomerFromSearchTask, vo, req);
} catch (Exception e) {
e.printStackTrace();
MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);
}
}
/**
* 從企業微信好友中添加客戶
* @author wechat:happybabby110
* @blog http://www.wlkankan.cn
*/
public void handleMsg(ChannelHandlerContext ctx ,TransportMessage vo, String contentJsonStr) {
try {
log.debug(contentJsonStr);
AddCustomerFromWxTaskMessage.Builder bd = AddCustomerFromWxTaskMessage.newBuilder();
JsonFormat.parser().merge(contentJsonStr, bd);
AddCustomerFromWxTaskMessage req = bd.build();
// 將消息轉發送給手機客戶端
asyncTaskService.msgSend2Phone(ctx, String.valueOf(req.getWxId()), EnumMsgType.AddCustomerFromWxTask, vo, req);
} catch (Exception e) {
e.printStackTrace();
MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);
}
}
3、企業微信SDK接口API調用-觸發企業微信推送聯系人列表
/**
* 觸發推送企業微信聯系人列表任務
* @author wechat:happybabby110
* @blog http://www.wlkankan.cn
*/
@Async
public void handleMsg(ChannelHandlerContext ctx,TransportMessage vo, String contentJsonStr) {
try {
log.debug(contentJsonStr);
CommonTriggerTaskMessage.Builder bd = CommonTriggerTaskMessage.newBuilder();
JsonFormat.parser().merge(contentJsonStr, bd);
CommonTriggerTaskMessage req = bd.build();
//將消息轉發送給手機客戶端
asyncTaskService.msgSend2Phone(ctx, String.valueOf(req.getWxId()), EnumMsgType.TriggerContactPushTask, vo, req);
} catch (Exception e) {
e.printStackTrace();
MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);
}
}
/**
* 企業微信推送聯系人列表
* @author wechat:happybabby110
* @blog http://www.wlkankan.cn
*/
@Async
public void handleMsg(ChannelHandlerContext ctx, TransportMessage vo) {
try {
ContactPushNoticeMessage req = vo.getContent().unpack(ContactPushNoticeMessage.class);
log.debug(JsonFormat.printer().print(req));
asyncTaskService.msgSend2pc(String.valueOf(req.getWxId()), EnumMsgType.ContactPushNotice, 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、企業微信SDK接口API調用-觸發企業微信推送會話列表
/**
* 觸發企業微信推送會話列表任務
* @author wechat:happybabby110
* @blog http://www.wlkankan.cn
*/
@Async
public void handleMsg(ChannelHandlerContext ctx,TransportMessage vo, String contentJsonStr) {
try {
log.debug(contentJsonStr);
CommonTriggerTaskMessage.Builder bd = CommonTriggerTaskMessage.newBuilder();
JsonFormat.parser().merge(contentJsonStr, bd);
CommonTriggerTaskMessage req = bd.build();
//將消息轉發送給手機客戶端
asyncTaskService.msgSend2Phone(ctx, String.valueOf(req.getWxId()), EnumMsgType.TriggerConversationPushTask, vo, req);
} catch (Exception e) {
e.printStackTrace();
MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);
}
}
/**
* 企業微信聊天會話列表推送
* @author wechat:happybabby110
* @blog http://www.wlkankan.cn
*/
@Async
public void handleMsg(ChannelHandlerContext ctx, TransportMessage vo) {
try {
ConversationPushNoticeMessage req = vo.getContent().unpack(ConversationPushNoticeMessage.class);
log.debug(JsonFormat.printer().print(req));
asyncTaskService.msgSend2pc(String.valueOf(req.getWxId()), EnumMsgType.ConversationPushNotice, 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);
}
}
5、企業微信SDK接口API調用-觸發推送企業微信微信好友
/**
* 觸發企業微信推送微信好友列表
* @author wechat:happybabby110
* @blog http://www.wlkankan.cn
*/
@Async
public void handleMsg(ChannelHandlerContext ctx,TransportMessage vo, String contentJsonStr) {
try {
log.debug(contentJsonStr);
CommonTriggerTaskMessage.Builder bd = CommonTriggerTaskMessage.newBuilder();
JsonFormat.parser().merge(contentJsonStr, bd);
CommonTriggerTaskMessage req = bd.build();
//將消息轉發送給手機客戶端
asyncTaskService.msgSend2Phone(ctx, String.valueOf(req.getWxId()), EnumMsgType.TriggerWechatFriendPushTask, vo, req);
} catch (Exception e) {
e.printStackTrace();
MessageUtil.sendJsonErrMsg(ctx, EnumErrorCode.InvalidParam, Constant.ERROR_MSG_DECODFAIL);
}
}
/**
* 企業微信好友列表推送,用於從微信好友中添加客戶
* @author wechat:happybabby110
* @blog http://www.wlkankan.cn
*/
@Async
public void handleMsg(ChannelHandlerContext ctx, TransportMessage vo) {
try {
WxFriendPushNoticeMessage req = vo.getContent().unpack(WxFriendPushNoticeMessage.class);
log.debug(JsonFormat.printer().print(req));
asyncTaskService.msgSend2pc(String.valueOf(req.getWxId()), EnumMsgType.WxFriendPushNotice, 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);
}
}