企业微信api,企业微信sdk接口java调用源码

简介: 企业微信api,企业微信sdk接口java调用源码

企业微信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);
    }
}


相关文章
|
9月前
|
Java API 数据处理
Java新特性:使用Stream API重构你的数据处理
Java新特性:使用Stream API重构你的数据处理
|
9月前
|
Java 大数据 API
Java Stream API:现代集合处理与函数式编程
Java Stream API:现代集合处理与函数式编程
411 100
|
9月前
|
Java API 数据处理
Java Stream API:现代集合处理新方式
Java Stream API:现代集合处理新方式
389 101
|
9月前
|
并行计算 Java 大数据
Java Stream API:现代数据处理之道
Java Stream API:现代数据处理之道
490 101
|
9月前
|
安全 Java API
使用 Java 构建强大的 REST API 的四个基本技巧
本文结合探险领域案例,分享Java构建REST API的四大核心策略:统一资源命名、版本控制与自动化文档、安全防护及标准化异常处理,助力开发者打造易用、可维护、安全可靠的稳健API服务。
536 116
|
9月前
|
存储 数据可视化 Java
Java Stream API 的强大功能
Java Stream API 是 Java 8 引入的重要特性,它改变了集合数据的处理方式。通过声明式语法,开发者可以更简洁地进行过滤、映射、聚合等操作。Stream API 支持惰性求值和并行处理,提升了代码效率和可读性,是现代 Java 开发不可或缺的工具。
192 0
Java Stream API 的强大功能
|
9月前
|
缓存 小程序 前端开发
商城/点餐/家政类小程序源码合集_微信抖音小程序源码开发从入门到精通实战
本文系统讲解如何利用现有源码快速开发商城、点餐、家政类微信/抖音小程序,涵盖环境搭建、核心功能实现、多平台部署与优化,提供完整技术方案。实战导向,助力开发者高效入门与落地。
|
9月前
|
小程序 PHP 图形学
热门小游戏源码(Python+PHP)下载-微信小程序游戏源码Unity发实战指南​
本文详解如何结合Python、PHP与Unity开发并部署小游戏至微信小程序。涵盖技术选型、Pygame实战、PHP后端对接、Unity转换适配及性能优化,提供从原型到发布的完整指南,助力开发者快速上手并发布游戏。
|
9月前
|
存储 小程序 Java
热门小程序源码合集:微信抖音小程序源码支持PHP/Java/uni-app完整项目实践指南
小程序已成为企业获客与开发者创业的重要载体。本文详解PHP、Java、uni-app三大技术栈在电商、工具、服务类小程序中的源码应用,提供从开发到部署的全流程指南,并分享选型避坑与商业化落地策略,助力开发者高效构建稳定可扩展项目。
|
10月前
|
安全 Java API
Java日期时间API:从Date到Java.time
本文深入解析了Java 8中引入的全新日期时间API,涵盖LocalDate、LocalTime、LocalDateTime、ZonedDateTime等核心类的使用,以及时间调整、格式化、时区处理和与旧API的互操作。通过实例对比,展示了新API在可变性、线程安全与易用性方面的显著优势,并提供迁移方案与实战技巧,助你掌握现代Java时间处理的最佳实践。