微信API接口、微信二次开发API调用

简介: 微信API接口、微信二次开发API调用

微信API接口、微信二次开发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){
                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);
        }
    }

微信协议接口调用-群发微信好友,群发群消息

群发微信好友、群发群

private static void talkMsgToFriend(TaskTimeInfo info, TimeTaskDetailsDao timeTaskDetailsDao,
List<String> friends) {
String executeTime = info.getExecute_time();
Date newDate = DateUtil.convertString2Date(executeTime, DateUtil.DATE_FORMAT_4);
Integer betweenTime = info.getBetween_time();
if (betweenTime ==null || betweenTime==0) {
betweenTime = (int)(Math.random()*3+3);
}
for (String friend : friends) {
String newExecuteTime = DateUtil.convertDate2String(newDate, DateUtil.DATE_FORMAT_4);
String msgStr = "";
String jsonStr = info.getContent();
List<MessageVo> list = JsonUtils.json2Bean(jsonStr);
for (int i = 0; i < list.size(); i++) {
MessageVo msg = list.get(i);
ByteString byteString = ByteString.copyFromUtf8(msg.getContent());
TalkToFriendTaskMessage.Builder build = TalkToFriendTaskMessage.newBuilder();
build.setWeChatId(info.getWechatId());
build.setFriendId(friend);
build.setContent(byteString);
build.setMsgId(MsgIdBuilder.getId());
if (msg.getContentType().equalsIgnoreCase("Text")) {// 文本类型
build.setContentType(EnumContentType.Text);
} else if (msg.getContentType().equalsIgnoreCase("Picture")) {// 图片类型
build.setContentType(EnumContentType.Picture);
} else if (msg.getContentType().equalsIgnoreCase("Voice")) {// 语音类型
build.setContentType(EnumContentType.Voice);
} else if (msg.getContentType().equalsIgnoreCase("Video")) {// 视频类型
build.setContentType(EnumContentType.Video);
} else if (msg.getContentType().equalsIgnoreCase("Link")) {// 链接类型
build.setContentType(EnumContentType.Link);
} else if (msg.getContentType().equalsIgnoreCase("WeApp")) {// 小程序
build.setContentType(EnumContentType.WeApp);
}
TalkToFriendTaskMessage msg1 = build.build();
if (null != msg1) {
try {
String json = JsonFormat.printer().print(msg1);
if (!StringUtils.isEmpty(json)) {
msgStr = msgStr + json;
if (i != (list.size() - 1)) {
msgStr = msgStr + "&&";
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
if (null != msgStr) {
try {
if (!StringUtils.isEmpty(msgStr)) {
TimeTaskDetails detail = new TimeTaskDetails();
detail.setTid(info.getId());
detail.setExecute_time(newExecuteTime);
detail.setJson_content(msgStr);
detail.setMsgid(String.valueOf(MsgIdBuilder.getId()));
timeTaskDetailsDao.insert(detail);
}
} catch (Exception e) {
e.printStackTrace();
}
}
newDate = DateUtil.offsetSecode(newDate, betweenTime);
}
}

个人微信api接口调用-发微信朋友圈、拉取朋友圈数据功能

推送微信朋友圈列表

/**
     * 触发推送朋友圈列表
     * @author wechatno:tangjinjinwx 
     * @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);
        }
    }
相关文章
|
2月前
|
JSON API 数据格式
淘宝/天猫图片搜索API接口,json返回数据。
淘宝/天猫平台虽未开放直接的图片搜索API,但可通过阿里妈妈淘宝联盟或天猫开放平台接口实现类似功能。本文提供基于淘宝联盟的图片关联商品搜索Curl示例及JSON响应说明,适用于已获权限的开发者。如需更高精度搜索,可选用阿里云视觉智能API。
|
2月前
|
JSON API 数据安全/隐私保护
深度分析淘宝卖家订单详情API接口,用json返回数据
淘宝卖家订单详情API(taobao.trade.fullinfo.get)是淘宝开放平台提供的重要接口,用于获取单个订单的完整信息,包括订单状态、买家信息、商品明细、支付与物流信息等,支撑订单管理、ERP对接及售后处理。需通过appkey、appsecret和session认证,并遵守调用频率与数据权限限制。本文详解其使用方法并附Python调用示例。
|
16天前
|
数据可视化 测试技术 API
从接口性能到稳定性:这些API调试工具,让你的开发过程事半功倍
在软件开发中,接口调试与测试对接口性能、稳定性、准确性及团队协作至关重要。随着开发节奏加快,传统方式已难满足需求,专业API工具成为首选。本文介绍了Apifox、Postman、YApi、SoapUI、JMeter、Swagger等主流工具,对比其功能与适用场景,并推荐Apifox作为集成度高、支持中文、可视化强的一体化解决方案,助力提升API开发与测试效率。
|
2月前
|
监控 算法 API
电商API接口对接实录:淘宝优惠券接口对接处理促销监控系统
在电商开发中,淘宝详情页的“券后价计算”是极易出错的环节。本文作者结合实战经验,分享了因忽略满减券门槛、有效期、适用范围等导致的踩坑经历,并提供了完整的解决方案,包括淘宝API签名生成、券后价计算逻辑、常见坑点及优化建议,助力开发者精准实现券后价功能,避免业务损失。
|
2月前
|
JSON 算法 安全
淘宝商品详情API接口系列,json数据返回
淘宝开放平台提供了多种API接口用于获取商品详情信息,主要通过 淘宝开放平台(Taobao Open Platform, TOP) 的 taobao.tbk.item.info.get(淘宝客商品详情)或 taobao.item.get(标准商品API)等接口实现。以下是关键信息及JSON返回示例:
|
2月前
|
设计模式 JSON Unix
微店商品详情API接口,json数据返回
微店商品详情API接口的典型JSON返回数据结构说明,基于公开的微店开放平台API文档和常见电商API设计模式整理。实际使用时请以微店官方最新文档为准
|
4天前
|
JSON 前端开发 API
如何调用体育数据足篮接口API
本文介绍如何调用体育数据API:首先选择可靠服务商并注册获取密钥,接着阅读文档了解基础URL、端点、参数及请求头,然后使用Python等语言发送请求、解析JSON数据,最后将数据应用于Web、App或分析场景,同时注意密钥安全、速率限制与错误处理。
|
14天前
|
JSON API 数据安全/隐私保护
Python采集淘宝评论API接口及JSON数据返回全流程指南
Python采集淘宝评论API接口及JSON数据返回全流程指南
|
23天前
|
JSON 供应链 监控
1688商品详情API技术深度解析:从接口架构到数据融合实战
1688商品详情API(item_get接口)可通过商品ID获取标题、价格、库存、SKU等核心数据,适用于价格监控、供应链管理等场景。支持JSON格式返回,需企业认证。Python示例展示如何调用接口获取商品信息。
|
4天前
|
JSON 自然语言处理 监控
淘宝关键词搜索与商品详情API接口(JSON数据返回)
通过商品ID(num_iid)获取商品全量信息,包括SKU规格、库存、促销活动、卖家信息、详情页HTML等。

热门文章

最新文章