企业微信自动化发消息-从0到1开发实践

一、使用场景

**内部协同与办公管理 :**智能通知与提醒、数据化报告推送、制度与文化宣导。

**客户服务与外部协作:**客户关系维护、跨组织协作、营销与活动运营。

**行业特定场景:**零售与电商、教育行业、IT与互联网、制造业。

二、集成与扩展场景

  1. 连接业务系统

    • 与ERP、CRM、OA等系统集成,将业务流程关键节点通过企业微信自动触达。

    • 示例:CRM客户签约后,自动向销售团队群发送祝贺消息并同步客户详情。

  2. 机器人协同

    • 群机器人:自动推送代码提交、日志报警、舆情监控等信息到技术或运营群。

    • 助理机器人:员工通过关键词触发,自动查询数据(如业绩、排班)并返回结果。

三、核心API说明

1、好友操作

复制代码
1、获取内部联系人列表
请求
page_num 是第几页,从1开始
page_size 是每页获取多少数据

  "type": 11036,
  "data": {
    "page_num": 1,
    "page_size": 10
  }
}
{
    "data":{
        "page_num":1, // 当前页
        "page_size":10,  // 每页多少
        "total":26,       // 一共多少条数据
        "total_page":3,  // 共多少页
        "user_list":[
            {
                "acctid":"xxxx",
                "avatar":"http://wework.qpic.cn/bizmail/IHgRKfv9SqpPJEZUfiaUfqMkckbS0xxxxx",
                "conversation_id":"S:168885xx2_16888505xxx",
                "corp_id":"19703250xxx",
                "mobile":"手机号",
                "nickname":"1112",
                "position":"总经理",
                "realname":"xxxxx",
                "remark":"",
                "sex":2,
                "unionid":"ozynqspBJVmTEwLxxxx",
                "user_id":"1688850xxxx",
                "username":"7777x"
            }
        ]
    },
    "type":11036
}

2、获取联系人信息
请求

{
    "type": 11039,
    "data": {
        "user_id": "78813007149xxxxxxx"
    }
}
返回

{
    "data": {
        "acctid": "xxxx",
        "avatar": "http://wx.qlogo.cn/mmhead/M8Vj2ZxG8UHJx0xdowCt4xxxx/0",
        "conversation_id": "S:16888505xxx82_7881300xx",
        "corp_id": "1970325xxx8",
        "mobile": "",
        "nickname": "",
        "position": "",
        "realname": "",
        "remark": "",
        "sex": 1,
        "unionid": "ozynqspBJVmTEwLsxxxQ",
        "user_id": "788130071491xxxx",
        "username": "777xx"
    },
    "type": 11039
}

3、获取外部联系人列表
请求
page_num 是第几页,从1开始
page_size 是每页获取多少数据

  "type": 11037,
  "data": {
    "page_num": 1,
    "page_size": 10
  }
}
{
    "data":{
        "page_num":1, // 当前页
        "page_size":10,  // 每页多少
        "total":26,       // 一共多少条数据
        "total_page":3,  // 共多少页
        "user_list":[
            {
                "acctid":"xxxx",
                "avatar":"http://wework.qpic.cn/bizmail/IHgRKfv9SqpPJEZUfiaUfqMkckbS0xxxxx",
                "conversation_id":"S:168885xx2_16888505xxx",
                "corp_id":"19703250xxx",
                "mobile":"手机号",
                "nickname":"1112",
                "position":"总经理",
                "realname":"xxxxx",
                "remark":"",
                "sex":2,
                "unionid":"ozynqspBJVmTEwLxxxx",
                "user_id":"1688850xxxx",
                "username":"7777x"
            }
        ]
    },
    "type":11036
}

4、搜索微信/企微用户
请求

    "type": 11052,
    "data": {
        "keyword": "15666666666"
    }
}
返回的内容比较多, 有几个字段后续加人要用到,其他信息可以根据需要自提

{
    "data":{
        "contact_info":{
            "acctid":"YiYi",
            "alias":"",
            "attr":146210880,
            "bind_email":"",
            "bind_email_status":1,
            "birthday":"1970-01-01 00:00:00",
            "bizuin":0,
            "circle_language":0,
            "corpid":1970325xxxxxx,
            "create_source":1,
            "create_time":0,
            "department":"",
            "display_order":0,
            "emailaddr":"",
            "english_name":"",
            "extern_job":"",
            "extern_position":"",
            "external_corp_info":"",
            "external_custom_info":null,
            "external_pb":"",
            "external_wxfinder":null,
            "extra_info":null,
            "gender":2,
            "gid":2251800xxxxxx,
            "hash":0,
            "holiday_info":{
                "create_time":0,
                "holiday_desc":"",
                "holiday_generate_src":0,
                "holiday_icon_index":0,
                "holiday_info_id":0,
                "holiday_status":0,
                "holiday_status_new":0,
                "new_holiday_icon_index":0
            },
            "holiday_list_read_time":0,
            "iconurl":"http:\/\/wework.qpic.cn\/bizmail\/W9Sqc7EPicJeeR77ibdaMesvkicibwMdjCmaY6rIcpG8aytZJMCTrtVQgw\/0",
            "internation_code":"86",
            "is_name_verified":true,
            "job":"",
            "level":0,
            "main_partyid":16888xxx81,
            "mobile":"",
            "name":"一一xx",
            "name_status":1,
            "nation_code":"",
            "number":"",
            "openkfprofile":null,
            "partyid":0,
            "partymember_order":0,
            "personal_work_type":0,
            "phone":"",
            "position":"",
            "pstn_extension_number":"",
            "pstn_extension_number_new":"",
            "qqmail_uin":0,
            "realname":"xxxxx",
            "robot_profile":null,
            "school_parent_openid":"",
            "school_staff_relation":"",
            "school_user_type":0,
            "staff_attr":0,
            "staff_type":0,
            "staff_xid":0,
            "student_number":"",
            "subjectname":"",
            "tencent_info":{
                "work_card_image":""
            },
            "uin":16888xxx,
            "under_verify_name":"",
            "unionid":"ozynqsnJuiQexxxxbE",
            "use_attr2":5898244,
            "v_corp_name_full":"",
            "v_corp_name_short":"",
            "v_corp_use_status":1000,
            "v_create_mail":"",
            "v_hoster_vid":0,
            "v_is_init_moder":true,
            "v_recommend_info":null,
            "vcode":"vce5e8f7825e87c408",
            "xcx_corp_address":"",
            "xcx_style":0
        },
        "corpinfo":{
            "admin_vid":0,
            "appli_info":null,
            "auth_time":0,
            "authed_domain":"",
            "b_authed_licence":true,
            "b_has_info_corp":false,
            "b_hastoken":false,
            "b_internet_industry":false,
            "b_need_not_verify":false,
            "b_need_update_name":false,
            "card_url":"https:\/\/work.weixin.qq.com\/wework_admin\/xxxxp?",
            "coreate_source_info":"",
            "corp_desc":"",
            "corp_full_name":"xxxx科技有限公司",
            "corp_logo":"https:\/\/p.qlogo.cn\/bizmail\/1icHEZ7xxxx\/0",
            "corp_name":"xxxxxxxxx",
            "corp_stat":0,
            "corp_use_status":0,
            "corpid":19703250xxxxxxx,
            "create_time":1532394113,
            "custom_check_url":"",
            "email_need_auth":"",
            "internation_code":"",
            "isAccepted":false,
            "isTrust":true,
            "is_corp_verify":false,
            "is_init_moduser":false,
            "is_overseas_corp":false,
            "join_need_verify":false,
            "language":1,
            "mail":"",
            "mem_appli_time":0,
            "mem_create_time":0,
            "mobile_need_auth":"",
            "moduser_info":{
                "name":"",
                "vid":0
            },
            "ownername":"anme",
            "personal_work_info":"",
            "personal_work_type":0,
            "pstn_main_number":"",
            "pstn_officephone_state":0,
            "qyh_info":"",
            "scorp_id":"wwfd561047d79e1a2d",
            "staff_info":{
                "attr":0,
                "corp_mail":"",
                "corp_mail_active":false,
                "corp_position":"",
                "corp_rank":"",
                "custom_check_status":0,
                "english_name":"",
                "head_image":"http:\/\/wework.qpic.cn\/bizmail\/xxxxxxxxxxw\/0",
                "internation_code":"86",
                "mail":"yiyimama@lcwsl999.onexmail.com",
                "name":"一一xxxx",
                "phone":"",
                "pstn_extension_number":"",
                "real_name":""
            },
            "staffnum":0,
            "status":0,
            "unreadNum":0,
            "v_init_domain_name":"",
            "v_superadmin_name":"",
            "v_superadmin_vid":0,
            "verify_msg":"",
            "verify_submit_time":0,
            "vid":16888505xxxxxx,
            "virtual_can_change_full_name":false,
            "virtual_corp_claiming_name":"",
            "work_card_back_url":"",
            "work_card_face_url":""
        },
        "datalist":[{
                "contact_info":{
                    "acctid":"YiYiM",
                    "alias":"",
                    "attr":146210880,
                    "bind_email":"",
                    "bind_email_status":1,
                    "birthday":"1970-01-01 00:00:00",
                    "bizuin":0,
                    "circle_language":0,
                    "corpid":1970325xxx86,
                    "create_source":1,
                    "create_time":0,
                    "department":"",
                    "display_order":0,
                    "emailaddr":"",
                    "english_name":"",
                    "extern_job":"",
                    "extern_position":"",
                    "external_corp_info":"",
                    "external_custom_info":null,
                    "external_pb":"",
                    "external_wxfinder":null,
                    "extra_info":null,
                    "gender":2,
                    "gid":2251800xx9,
                    "hash":0,
                    "holiday_info":{
                        "create_time":0,
                        "holiday_desc":"",
                        "holiday_generate_src":0,
                        "holiday_icon_index":0,
                        "holiday_info_id":0,
                        "holiday_status":0,
                        "holiday_status_new":0,
                        "new_holiday_icon_index":0
                    },
                    "holiday_list_read_time":0,
                    "iconurl":"http:\/\/wework.qpic.cn\/bizmail\/W9Sqc7EPicJeeR77ibdaMesvkicibwMdjCmaY6rIcpG8aytZJMCTrtVQgw\/0",
                    "internation_code":"86",
                    "is_name_verified":true,
                    "job":"",
                    "level":0,
                    "main_partyid":16888505xxx1,
                    "mobile":"",
                    "name":"一一x",
                    "name_status":1,
                    "nation_code":"",
                    "number":"",
                    "openkfprofile":null,
                    "partyid":0,
                    "partymember_order":0,
                    "personal_work_type":0,
                    "phone":"",
                    "position":"",
                    "pstn_extension_number":"",
                    "pstn_extension_number_new":"",
                    "qqmail_uin":0,
                    "realname":"xxxx",
                    "robot_profile":null,
                    "school_parent_openid":"",
                    "school_staff_relation":"",
                    "school_user_type":0,
                    "staff_attr":0,
                    "staff_type":0,
                    "staff_xid":0,
                    "student_number":"",
                    "subjectname":"",
                    "tencent_info":{
                        "work_card_image":""
                    },
                    "uin":1688850xxxx3,
                    "under_verify_name":"",
                    "unionid":"ozynqsnJuiQerUcDxxE",
                    "use_attr2":5898244,
                    "v_corp_name_full":"",
                    "v_corp_name_short":"",
                    "v_corp_use_status":1000,
                    "v_create_mail":"",
                    "v_hoster_vid":0,
                    "v_is_init_moder":true,
                    "v_recommend_info":null,
                    "vcode":"vce5e8f78x8",
                    "xcx_corp_address":"",
                    "xcx_style":0
                },
                "contact_info_wx":{
                    "acctid":"",
                    "alias":"",
                    "attr":0,
                    "bind_email":"",
                    "bind_email_status":0,
                    "birthday":"",
                    "bizuin":0,
                    "circle_language":0,
                    "corpid":0,
                    "create_source":0,
                    "create_time":0,
                    "department":"",
                    "display_order":0,
                    "emailaddr":"",
                    "english_name":"",
                    "extern_job":"",
                    "extern_position":"",
                    "external_corp_info":"",
                    "external_custom_info":null,
                    "external_pb":"",
                    "external_wxfinder":null,
                    "extra_info":null,
                    "gender":2,
                    "gid":0,
                    "hash":0,
                    "holiday_info":null,
                    "holiday_list_read_time":0,
                    "iconurl":"http:\/\/wx.qlogo.cn\/mmhead\/Q3auHgz\/0",
                    "internation_code":"",
                    "is_name_verified":false,
                    "job":"",
                    "level":0,
                    "main_partyid":0,
                    "mobile":"",
                    "name":"一小口", // 名称
                    "name_status":0,
                    "nation_code":"",
                    "number":"",
                    "openkfprofile":null,
                    "partyid":0,
                    "partymember_order":0,
                    "personal_work_type":0,
                    "phone":"",
                    "position":"",
                    "pstn_extension_number":"",
                    "pstn_extension_number_new":"",
                    "qqmail_uin":0,
                    "realname":"",
                    "robot_profile":null,
                    "school_parent_openid":"",
                    "school_staff_relation":"",
                    "school_user_type":0,
                    "self_info":null,
                    "staff_attr":0,
                    "staff_type":0,
                    "staff_xid":0,
                    "student_number":"",
                    "subjectname":"",
                    "tencent_info":null,
                    "uin":7881299xxxxxx,   // 用户id
                    "under_verify_name":"",
                    "unionid":"",
                    "use_attr2":0,
                    "v_corp_name_full":"",
                    "v_corp_name_short":"",
                    "v_corp_use_status":0,
                    "v_create_mail":"",
                    "v_hoster_vid":0,
                    "v_is_init_moder":false,
                    "v_recommend_info":null,
                    "vcode":"",
                    "xcx_corp_address":"",
                    "xcx_style":0
                },
                "corpinfo":{
                    "admin_vid":0,
                    "appli_info":null,
                    "auth_time":0,
                    "authed_domain":"",
                    "b_authed_licence":true,
                    "b_has_info_corp":false,
                    "b_hastoken":false,
                    "b_internet_industry":false,
                    "b_need_not_verify":false,
                    "b_need_update_name":false,
                    "card_url":"https:\/\/work.weixin.qq.com\/wework_admin\/user\/h5\/corp?",
                    "coreate_source_info":"",
                    "corp_desc":"",
                    "corp_full_name":"xxxxxxx网络科技有限公司",
                    "corp_logo":"https:\/\/p.qlogo.cn\/bizmail\/1icHExxxxxxg\/0",
                    "corp_name":"xxxx",
                    "corp_stat":0,
                    "corp_use_status":0,
                    "corpid":197032xxxxx6,
                    "create_time":1532394113,
                    "custom_check_url":"",
                    "email_need_auth":"",
                    "internation_code":"",
                    "isAccepted":false,
                    "isTrust":true,
                    "is_corp_verify":false,
                    "is_init_moduser":false,
                    "is_overseas_corp":false,
                    "join_need_verify":false,
                    "language":1,
                    "mail":"",
                    "mem_appli_time":0,
                    "mem_create_time":0,
                    "mobile_need_auth":"",
                    "moduser_info":{
                        "name":"",
                        "vid":0
                    },
                    "ownername":"anme",
                    "personal_work_info":"",
                    "personal_work_type":0,
                    "pstn_main_number":"",
                    "pstn_officephone_state":0,
                    "qyh_info":"",
                    "scorp_id":"wwfd561047d79e1a2d",
                    "staff_info":{
                        "attr":0,
                        "corp_mail":"",
                        "corp_mail_active":false,
                        "corp_position":"",
                        "corp_rank":"",
                        "custom_check_status":0,
                        "english_name":"",
                        "head_image":"http:\/\/wework.qpic.cn\/bizmail\/W9Sqc7EPicJeeR77ibdaMesvkicibwMdjCxxxxw\/0", // 头像
                        "internation_code":"86",
                        "mail":"yiyxxa@lxxx.onexmail.com",
                        "name":"一一xxx",
                        "phone":"",
                        "pstn_extension_number":"",
                        "real_name":""
                    },
                    "staffnum":0,
                    "status":0,
                    "unreadNum":0,
                    "v_init_domain_name":"",
                    "v_superadmin_name":"",
                    "v_superadmin_vid":0,
                    "verify_msg":"",
                    "verify_submit_time":0,
                    "vid":16888505xxxxxx,
                    "virtual_can_change_full_name":false,
                    "virtual_corp_claiming_name":"",
                    "work_card_back_url":"",
                    "work_card_face_url":""
                },
                "flag":0,
                "item_type":1,
                "name":"",
                "openid":"orFrbsuSYHirGxxxxxx",  // 添加为客户时要用到
                "relation":1,
                "search_status":1,
                "wx_ticket":"6001221957E20E5D29D1E733EE712415FBE17551E97981837EFAE6FFE7C22D989C2C64ABFEFC22FB07A801B91A132985C1A360FCDEAA389547xxxDxxxxF" // 添加为客户时要用到
            }],
        "error_code":0,
        "error_message":"",
        "flag":0,
        "keyword":"151xxxxxxxx",  // 搜索的手机号
        "name":"",
        "relation":1,
        "search_status":1
    },
    "type":11052
}

5、添加搜索的微信用户
请求

{
    "type":11053,
    "data":{
        "user_id":"78812998xxxxxx",
        "openid":"orFrbsuSYHirGzN1xxxxx",
        "wx_ticket":"6001221957E20E5D29D1E733EE712415FBE17551E97981837EFAE6FFE7C22D989C2C64ABFEFC22FB07A801B91A132985C1A360FCDEAA38954704EE6FD5894AE59725xxxxxxF",
        "verify":"你好"
    }
}
user_id 在查询结果中取,json路径是:data.datalist[0].contact_info_wx.uin
openid 在查询结果中取,json路径是:data.datalist[0].openid
wx_ticket 在查询结果中取,json路径是:data.datalist[0].wx_ticket
verify 为验证消息
返回

{
    "data":{
        "error_code":0,
        "error_message":"ok"
    },
    "type":11053
}

6、添加搜索的企微用户
请求

 {
    "type":11088,
    "data":{
        "user_id":"1688850xxx63",
        "corp_id":"19703250xxx86",
        "ticket": "xxxxxxxxxxxxxxxxxxxx",
        "verify":"你好"
    }
}
user_id 在查询结果中取,json路径是 data.datalist[0].contact_info.uin
corp_id 在查询结果中取, json路径是 data.datalist[0].contact_info.corpid
ticket 在查询结果中取 wx_ticket
verify 验证消息

响应

{
    "data":{
        "error_code":0,   // 负值是请求错误
         "error_message":""
    },
    "type":11088
}

7、添加名片为联系人
请求

{
    "type":11121,
    "data":{
        "user_id":"78812998xxxxxx",
        "corp_id":"0",
        "from_user_id":"7881299524xxxx",
        "verify":"你好"
    }
}
user_id 在接收名片消息中取,user_id
corp_id 在接收名片消息中取, corp_id
from_user_id 是接收名片消息中的sender
verify 验证消息

返回

{
    "data":{
        "error_code":0,
        "error_message":"ok"
    },
    "type":11121
}

8、添加删除的联系人
请求

{
    "type":11152,
    "data":{
        "user_id":"78812998549xxxxx",
        "corp_id":"0",
        "verify":"你好"
    }
}
返回

{
    "data":{
        "error_code":0,
        "error_message":"ok"
    },
    "type":11152
}

9、修改好友备注
请求

{
    "type":11054,
    "data":{
        "user_id":"788130228391xxxx",
        "remark":"备注"
    }
}
返回

{
    "data":{
        "error_code":0,
        "error_message":"ok"
    },
    "type":11054
}

10、修改好友描述
请求

 {
  "type": 11055,
  "data": {
    "user_id": "7881302283xxxxx",
    "desc": "描述"
  }
}
返回

{
    "data":{
        "error_code":0,
        "error_message":"ok"
    },
    "type":11055
}

11、修改外部联系人手机号
请求

 {
  "type": 11056,
  "data": {
    "phone_list": [
      "15688888888"
    ],
    "user_id": "7881302283xxxxxxx"
  }
}
返回

{
    "data":{
        "error_code":0,
        "error_message":"ok"
    },
    "type":11056
}

12、修改外部联系人公司名称
请求

{
    "type":11057,
    "data":{
        "user_id":"78813022839xxxxx",
        "company":"anme的公司"
    }
}
返回

{
    "data":{
        "error_code":0,
        "error_message":"ok"
    },
    "type":11057
}

13、删除联系人
请求

 {
    "type":11111,
    "data":{
        "user_id":"7881302283xxxxx",
        "corp_id":"0"
    }
}
返回

{
    "data":{
        "error_code":0,
        "error_message":"ok"
    },
    "type":11111
}

14、接受好友申请
请求

{
    "type":11064,
    "data":{
        "user_id":"7881302283xxx",
        "corp_id":"1970325134xxx"
    }
}
从接收到好友请求信息中user_id和corp_id

返回

{
    "data":{
        "error_code":0,
        "error_message":"ok"
    },
    "type":11064
}

2、群聊操作

复制代码
1、获取群聊列表
请求

page_num 是第几页,从1开始
page_size 是每页获取多少数据

 {
  "type": 11038,
  "data": {
    "page_num": 1,
    "page_size": 10
  }
}
返回

{
    "data":{
        "page_num":1, // 当前页
        "page_size":10,  // 每页多少
        "total":26,       // 一共多少条数据
        "total_page":3,  // 共多少页
        "room_list":[{
            "conversation_id":"R:10696xxxx434",
            "create_time":1603705235,
            "create_user_id":"16888xxxx0534",
            "is_external":1,   // 外部群 1, 内部群0
            "nickname":"测试大群1",
            "is_admin" : 0, // 是否为管理员
            "is_creator" : 0, // 是否为创建者
            "total":79   //群成员 
        },{
            "conversation_id":"R:106960xxx1496",
            "create_time":1585103478,
            "create_user_id":"1688851xxx83530",
            "is_external":1,
            "is_admin" : 0, // 是否为管理员
            "is_creator" : 0, // 是否为创建者
            "nickname":"xxxx进阶玩法",
            "total":305
        }]},
    "type":11038
}

2、获取群成员列表
请求

page_num 是第几页,从1开始
page_size 是每页获取多少数据

 {
  "type": 11040,
  "data": {
    "conversation_id": "R:38450xxxx72",
    "page_num":1,
    "page_size":10
  }
}
返回

{
    "data":{
        "page_num":1, // 当前页
        "page_size":10,  // 每页多少
        "total":26,       // 一共多少条数据
        "total_page":3,  // 共多少页
        "conversation_id":"R:3845043072",
        "member_list":[{
                "acctid":"GuanxxxxxiQiRen",
                "avatar":"http:\/\/wework.qpic.cn\/bizmail\/Y4WrW34pibbTAR9d9gibZBxib4fD0MmgyjYWyhicxxxxQA\/0",
                "corp_id":"1970325032041886",
                "mobile":"",
                "nickname":"",
                "position":"",
                "realname":"xxxx利",
                "remark":"xxx",
                "sex":1,
                "unionid":"ozynqssGkZxxxxhwG82oV8g",
                "user_id":"16888505xxx6662",
                "username":"xxxx利",
                "invite_user_id": "168xxxxxx", // 邀请人id
                "is_admin" : 0, // 是否为管理员
                "room_nickname": "群内昵称",
                "join_scene" : 3, // 来源类型
                "join_time" : 1580138164 // 加入时间
            }]
    },
    "type":11040
}

3、创建群
请求

 {
  "type": 11058,
  "data": [
    "788130071xxx93",
    "78813028xxx8803"
  ]
}
返回

{
    "data":{
        "createruin":168885053xx82,  //创建者user_id
        "createtime":1639322040,   // 创建时间 
        "error_code":0,
        "error_message":"", 
        "failmem":[{
                "type":0,
                "vid":0
            }],
        "msgid":109xx35,
        "msgseq":8513xxx,
        "roomid":1069605293xxx1944,  // 群id
        "roomname":"",
        "sessionid":"Nm5GdS10TURTd3lGdEZ1aQ==",
        "success_add_vidlist":[{
                "success_add_vidlist":7881300xxx2093  // 添加成功的成员用户id
            }]
    },
    "type":11058
}

4、创建空外部群
请求

{
    "type":11125,
    "data":{
    }
}
返回

{
    "data":{
        "content":"5L6v5bCR6L6J5Zyo5LyB5Lia5b6u5L+h5Lit6YKA6K+35L2g5Yqg5YWl576k6IGK77yM55So5q2j5byP55qE5ZCN54mH6Ixxxxx2c",
        "h5url":"aHR0cHM6Ly93b3JrLndlaXhpbi5xcS5jb20vd2V3b3JrX2FkbWluL3Jvb20vam9pbi93eD9pbnZpdGVfc291cmNlPTE0NiZ2Y29kZT0yNjRhYxxxxxWE1MWQ0YjkzN2RjMzAzZTM4OWMyYg==",
        "image_url":"aHR0cDovL3Jlc2Nkbi5xcW1haWwuY29tL25vZGUvd3cvd3dtbmcvc3R5bGUvaW1hZ2VzL2luZGVwZW5kZW50L0RlZmF1bHRHcm91cEF2YxxxxxhhZTljNi5wbmc=", //  // 群头像base64
        "info":{
            "auto_reply_type":0,
            "createtime":1639322223,  // 创建时间 
            "createuin":16888505xxxx82,  // 创建user_id
            "customer_room_type":2,
            "ex_owner":0,
            "flag":0,
            "is_wwwx_room_admin":false,
            "needreadmode_vid":0,
            "needreadmodetime":0,
            "new_flag":4,
            "notice":"",
            "person_room_image":"",
            "person_room_type":0,
            "room_tools":null,
            "room_welcome_msg":"",
            "roomid":10696052xxx094,  // 群id
            "roomname":"",
            "school_room_info":null,
            "sessionid":"WVBFUTByRFxxx6Xw==",
            "team_room_type":0,
            "update_topmsg_time":0
        },
        "is_first_wx_room":false,
        "room_qrcode":"",
        "roomid":10696052939032094,
        "title":"6YKA6K+35L2g5Yqg5YWl5LyB5Lia5b6u5L+h576k6IGK"  // 群标题base64
    },
    "type":11125
}

5、修改群名
请求

{
    "type":11059,
    "data":{
        "conversation_id":"R:10696049xxxx368",
        "name":"新群名"
    }
}
返回

{
    "data":{
        "createruin":0,
        "createtime":0,
        "error_code":0,
        "error_message":"",
        "msgid":1098651,
        "msgseq":8513844,
        "roomid":0,
        "roomname":"",
        "sessionid":""
    },
    "type":11059
}

6、批量邀请好友入群
请求

 {
  "type": 11060,
  "data": {
    "user_list": [
      "7881302872xx115"
    ],
    "conversation_id": "R:10696051780xxx71"
  }
}
返回

是否邀请成功,请看success_add_vidlist是否有值并且failmem不为null,如果没有就是失败

{
    "data":{
        "error_code":0,
        "error_message":"",
        "failmem":[null],
        "msgid":1098658,
        "msgseq":8513848,
        "success_add_vidlist":[{
                "success_add_vidlist":7881302872xxx115
            }]
    },
    "type":11060
}
当fillmem为null,没有success_add_vidlist,这种情况是群成员大于40人,需要对方确认才能入群

{
    "data":{
        "error_code":0,
        "error_message":"",
        "failmem":[null],
        "msgid":0,
        "msgseq":0
    },
    "type":11060
}
下面是添加失败的返回failmem为null

{
    "data":{
        "error_code":0,
        "error_message":"",
        "failmem":[{
                "type":0,
                "vid":0
            }],
        "msgid":0,
        "msgseq":0
    },
    "type":11060
}

7、批量踢群成员
请求

 {
  "type": 11061,
  "data": {
    "user_list": [
      "7881302872xxxx15"
    ],
    "conversation_id": "R:106960517xxx"
  }
}
返回

{
    "data":{
        "error_code":0,
        "error_message":"",
        "msgid":1098665,
        "msgseq":8513852
    },
    "type":11061
}

8、添加群成员为好友
请求

{
    "type":11071,
    "data":{
        "room_conversation_id":"R:10696049576014434",  // 所在群
        "user_id":"1688850321512612",    // 群成员id
        "corp_id":"1970324972075112",   // 成员公司id
        "verify":"你好"   // 验证消息
    }
}
返回

{
    "data":{
        "error_code":0,
        "error_message":"ok"
    },
    "type":11071
}

9、发布群公告
请求

 {
    "type":11082,
    "data":{
        "room_conversation_id":"R:106960517xxxxx",
        "notice":"新群公告"
    }
}
返回

{
    "data":{
        "createruin":0,
        "createtime":0,
        "error_code":0,
        "error_message":"",
        "msgid":0,
        "msgseq":0,
        "roomid":0,
        "roomname":"",
        "sessionid":""
    },
    "type":11082
}

10、转让群主
请求

{
    "type":11090,
    "data":{
        "room_conversation_id":"R:10696051xxx71",
        "user_id":"16888505xx3"  // 新群主
    }
}
返回

{
    "data":{
        "createruin":0,
        "createtime":0,
        "error_code":0,
        "error_message":"",
        "msgid":0,
        "msgseq":0,
        "roomid":0,
        "roomname":"",
        "sessionid":""
    },
    "type":11090
}

11、开启/关闭群邀请确认
请求

{
    "type":11089,
    "data":{
        "room_conversation_id":"R:10696052725027504",
        "status":1   // 1开启, 0关闭
    }
}
返回

{
    "data":{
        "createruin":0,
        "createtime":0,
        "error_code":0,
        "error_message":"",
        "msgid":0,
        "msgseq":0,
        "roomid":0,
        "roomname":"",
        "sessionid":""
    },
    "type":11089
}

12、开启/关闭禁止修改群名
请求

{
    "type":11108,
    "data":{
        "room_conversation_id":"R:10696052725xxx4",
        "status":1  // 1开启 0关闭
    }
}
返回

{
    "data":{
        "createruin":0,
        "createtime":0,
        "error_code":0,
        "error_message":"",
        "msgid":0,
        "msgseq":0,
        "roomid":0,
        "roomname":"",
        "sessionid":""
    },
    "type":11108
}

13、退出群聊
请求

{
    "type":11105,
    "data":{
        "room_conversation_id":"R:1069605045xxx2"
    }
}
返回

{
    "data":{
        "error_code":0,
        "error_message":"",
        "msgid":1098700,
        "msgseq":8513871
    },
    "type":11105
}

14、解散群
请求

 {
    "type":11130,
    "data":{
        "room_conversation_id":"R:10696xx27504"
    }
}
返回

{
    "data":{
        "createruin":0,
        "createtime":0,
        "error_code":0,
        "error_message":"",
        "msgid":0,
        "msgseq":0,
        "roomid":0,
        "roomname":"",
        "sessionid":""
    },
    "type":11130
}

3、发送消息

复制代码
1、发送文本
接口说明:

发送文本接口
JSON示例


  {
    "data": {
        "conversation_id": "xxxxxxx",
        "content": "你好,世界"    
    },
    "type": 11029
  }

2、发送群@
接口说明:

发送群@消息接口
JSON示例


  {
    "data": {
        "conversation_id": "xxxxxxx",
        "content": "你好,世界",
        "at_list": ["168888xxxxxx", "1688xxxxxxxxx"]
    },
    "type": 11069
  }

3、发送图片
接口说明:

发送图片消息接口

JSON示例

  {
    "data": {
        "conversation_id": "xxxxxxxx",
        "file": "c:\\User\\ssx\\x\\x.jpg"
    },
    "type": 11030
  }

4、发送文件
接口说明:

发送文件消息接口

JSON示例

  {
    "data": {
        "conversation_id": "xxxxxxxx",
        "file": "c:\\User\\ssx\\x\\x.jpg"
    },
    "type": 11031
  }

5、发送动图-表情
接口说明:

发送动图(gif)消息接口

JSON示例

  {
    "data": {
        "conversation_id": "xxxxxxxx",
        "file": "c:\\User\\ssx\\x\\x.gif"
    },
    "type": 11070
  }

6、发送小程序
请求

 {
    "type":11162,
    "data":{
        "conversation_id":"S:168885xxx28682_788130xxxx912998",

        "username":"gh_52b46203a658@app",
        "appid":"wx35f2a3937c9df889",
        "appname":"博鸟绘本",
        "appicon":"http:\/\/wx.qlogo.cn\/mmhead\/Q3auHgzwzM42Aa6BAq7rguLCx66IVTm7Qibr6paWic3rl9bfalX7gQLw\/96",
        "title":"博鸟绘本,最新最全的儿童绘本租赁平台~",
        "page_path":"pages\/shouye\/shouye.html",


        // cdn参数为小程序封面,可以从cdn上传图片处获得
        "file_id":"3069020102046230600201000204283cabaa02030f424102043c986eb4020461967039042431376332326538612d656533342d346537642d623531332d37393762376436336531663702010002030ec8700410059b34e084cf19a38a92a677177863d20201010201000400",
        "aes_key":"61393132623366353662313133653735",
        "md5":"059b34e084cf19a38a92a677177863d2",
        "size": 11122
    }
}
返回

{
    "data":{
        "is_svr_fail":false,
        "msg_data":{
            "appinfo":"Q0FVUWhNRGFqUVlZNEthRWk5c3ZJQWM9",
            "asid":0,
            "content":"2gaMBAoTZ2hfNTJiNDYyMDNhNjU4QGFwcBISd3gzNWYyYTM5MzdjOWRmODg5GhhwYWdlcy9zaG91eWUvc2hvdXllLmh0bWwgAigAMlVodHRwOi8vd3gucWxvZ28uY24vbW1oZWFkL1EzYXVIZ3p3ek00MkFhNkJBcTdyZ3VMQ3g2NklWVG03UWlicjZwYVdpYzNybDliZmFsWDdnUUx3Lzk2OjfljZrpuJ\/nu5jmnKzvvIzmnIDmlrDmnIDlhajnmoTlhL\/nq6Xnu5jmnKznp5\/otYHlubPlj7B+UgzljZrpuJ\/nu5jmnKxi1gEzMDY5MDIwMTAyMDQ2MjMwNjAwMjAxMDAwMjA0MjgzY2FiYWEwMjAzMGY0MjQxMDIwNDNjOTg2ZWI0MDIwNDYxOTY3MDM5MDQyNDMxMzc2MzMyMzI2NTM4NjEyZDY1NjUzMzM0MmQzNDY1Mzc2NDJkNjIzNTMxMzMyZDM3MzkzNzYyMzc2NDM2MzM2NTMxNjYzNzAyMDEwMDAyMDMwZWM4NzAwNDEwMDU5YjM0ZTA4NGNmMTlhMzhhOTJhNjc3MTc3ODYzZDIwMjAxMDEwMjAxMDAwNDAwaiA2MTM5MzEzMjYyMzM2NjM1MzY2MjMxMzEzMzY1MzczNXIgMDU5YjM0ZTA4NGNmMTlhMzhhOTJhNjc3MTc3ODYzZDJ4AKgBrAKwAfAB",
            "contenttype":78,
            "custom_service":"",
            "devinfo":65537,
            "extra_content":"",
            "flag":16777216,
            "id":1098787,
            "image_url":"",
            "innerkf_vid":0,
            "messagetype":0,
            "readuinscount":0,
            "receiver":7881302xxx12998,
            "referid":0,
            "roomid":0,
            "sender":1688850xxxxx28682,
            "sendername":"5bCP6YKq",
            "sendtime":1639358470,
            "seq":8513912
        }
    },
    "type":11162
}

7、发送视频号
请求

 {
    "data":{
        "conversation_id":"S:16888xxx28682_78812xxxx868",    "avatar":"http:\/\/wx.qlogo.cn\/finderhead\/Q3auHgzwzM5Wj8x4cMI7ekwXmT6CsibOjOm0s2KrZTRARGJ8U75EQ6g\/0",
        "cover_url":"http:\/\/wxapp.tc.qq.com\/251\/20350\/stodownload?encfilekey=Cvvj5Ix3eexKX1zo1IZZBrQomawdVfSQH1uu2U31EqEuJ6IyhFbn25faARlVjhSU56eqicuRvibvzQMU6zdpaPxYvicbKtnGKM4GcrrtlqgquRHMAColyRQBVskcYeRibwRPleP0VZFn1nTv1IDAuU01eo6SAzDFcqtJ3ibp8gzQYtgc&adaptivelytrans=0&bizid=1023&dotrans=0&hy=SH&idx=1&m=55167cbd3bbc01dba90b11a7ba140eba&token=x5Y29zUxcibAdrJ0wInbe5ZApHYU5taw6oaQcfrTmmrt2pyiaUc5tQs299icQZLE2LpDelYwZwEDYM&finder_expire_time=1639977779&finder_eid=export%2FUzFfAgtgekIEAQAAAAAA_dwkh7T7YgAAAAstQy6ubaLX4KHWvLEZgBPEnqM0Rnp6Fbr9zNPgMIBto29WMBq6Nqr4vQ-BQGWh",
        "desc":"这是我见过最会讲话的父亲#婚礼",
        "feed_type":4,
        "nickname":"婚礼策划主持董永",
        "thumb_url":"http:\/\/wxapp.tc.qq.com\/251\/20350\/stodownload?encfilekey=Cvvj5Ix3eexKX1zo1IZZBrQomawdVfSQH1uu2U31EqEuJ6IyhFbn25faARlVjhSU56eqicuRvibvzQMU6zdpaPxYvicbKtnGKM4GcrrtlqgquRHMAColyRQBVskcYeRibwRPleP0VZFn1nTv1IDAuU01eo6SAzDFcqtJ3ibp8gzQYtgc&adaptivelytrans=0&bizid=1023&dotrans=0&hy=SH&idx=1&m=55167cbd3bbc01dba90b11a7ba140eba&token=x5Y29zUxcibAdrJ0wInbe5ZApHYU5taw6oaQcfrTmmrt2pyiaUc5tQs299icQZLE2LpDelYwZwEDYM&finder_expire_time=1639977779&finder_eid=export%2FUzFfAgtgekIEAQAAAAAA_dwkh7T7YgAAAAstQy6ubaLX4KHWvLEZgBPEnqM0Rnp6Fbr9zNPgMIBto29WMBq6Nqr4vQ-BQGWh",
        "url":"https:\/\/channels.weixin.qq.com\/web\/pages\/feed?eid=export%2FUzFfAgtgekIEAQAAAAAA_dwkh7T7YgAAAAstQy6ubaLX4KHWvLEZgBPEnqM0Rnp6Fbr9zNPgMIBto29WMBq6Nqr4vQ-BQGWh",
        "extras":"CAEQACKBKwAE9OmXBAAAAQAAAAAAIe3D78dQLXN5JLPYtmEgAAAAaeq5SzX7s7sPwaz04zCEwYwyALHFYGIb\/l1etP1AtP01Y6hI8AMWYclAsxaJhKSmJ9JiBV7xxxx"
    },
    "type":11172
}
返回

{
    "data":{
        "is_svr_fail":false,
        "msg_data":{
            "appinfo":"Q0FVUXBPWGFqUVlZMUtXbmpkc3ZJQWs9",
            "asid":0,
            "content":"ChdodHRwczovL3d3dy5kb3V5aW4uY29tLxI1aHR0cHM6Ly9iLnpvbC1pbWcuY29tLmNuL3NvZnQvNy85MDcvY2VDNEh0ZlFxa2lnYy5qcGcaCeaKlumfs0FQUCIn55So56eR5oqA6K6p5aSN5p2C55qE5LiW55WM5pu0566A5Y2V77yB",
            "contenttype":13,
            "custom_service":"",
            "devinfo":65537,
            "extra_content":"",
            "flag":16777216,
            "id":1098795,
            "image_url":"",
            "innerkf_vid":0,
            "messagetype":0,
            "readuinscount":0,
            "receiver":7881302xxx98,
            "referid":0,
            "roomid":0,
            "sender":168885053xxx82,
            "sendername":"5bCP6YKq",
            "sendtime":1639363237,
            "seq":8513915
        }
    },
    "type":11172
}

8、发送卡片
请求

{
    "type":11159,
    "data":{
        "conversation_id":"S:168885xxx328682_7881xx2998",
        "url":"https:\/\/www.douyin.com\/",
        "image_url":"https:\/\/b.zol-img.com.cn\/soft\/7\/907\/ceC4HtfQqkigc.jpg",
        "title":"抖音APP",
        "desc":"用科技让复杂的世界更简单!"
    }
}
url 链接地址
image_url 图标地址
title 标题
desc 描述

返回

{
    "data":{
        "is_svr_fail":false,
        "msg_data":{
            "appinfo":"Q0FVUXBPWGFqUVlZMUtXbmpkc3ZJQWs9",
            "asid":0,
            "content":"ChdodHRwczovL3d3dy5kb3V5aW4uY29tLxI1aHR0cHM6Ly9iLnpvbC1pbWcuY29tLmNuL3NvZnQvNy85MDcvY2VDNEh0ZlFxa2lnYy5qcGcaCeaKlumfs0FQUCIn55So56eR5oqA6K6p5aSN5p2C55qE5LiW55WM5pu0566A5Y2V77yB",
            "contenttype":13,
            "custom_service":"",
            "devinfo":65537,
            "extra_content":"",
            "flag":16777216,
            "id":1098795,
            "image_url":"",
            "innerkf_vid":0,
            "messagetype":0,
            "readuinscount":0,
            "receiver":7881302xxx98,
            "referid":0,
            "roomid":0,
            "sender":168885053xxx82,
            "sendername":"5bCP6YKq",
            "sendtime":1639363237,
            "seq":8513915
        }
    },
    "type":11159
}

9、发视频
接口说明:

发送视频消息

JSON示例

  {
    "data": {
        "conversation_id": "xxxxxxxx",
        "file": "c:\\User\\ssx\\x\\x.mp4"
    },
    "type": 11067
  }

10、发送名片
请求

 {
    "type":11161,
    "data":{
        "conversation_id":"S:168885xxxx82_78813022xxx998",
        "share_user_id":"7881300xxx093"
    }
}
share_user_id 要分享的好友id
返回

{
    "data":{
        "is_svr_fail":false,
        "msg_data":{
            "appinfo":"Q0FVUW51amFqUVlZK2JHK2pkc3ZJQTA9",
            "asid":0,
            "content":"CN3y64uFgIAOEgAaACIA",
            "contenttype":41,
            "custom_service":"",
            "devinfo":65537,
            "extra_content":"",
            "flag":16777216,
            "id":1098799,
            "image_url":"",
            "innerkf_vid":0,
            "messagetype":0,
            "readuinscount":0,
            "receiver":7881302xxx2998,
            "referid":0,
            "roomid":0,
            "sender":1688850xx28682,
            "sendername":"5bCP6YKq",
            "sendtime":1639363616,
            "seq":8513917
        }
    },
    "type":11161
}

11、发送视频号直播
请求

 {
  "data": {
      "conversation_id": "S:7881300714912093_1688850535328682",
     "avatar": "http://wx.qlogo.cn/finderhead/ver_1/uKX9myKKepcU56XhO5XM6YxvSyD6TV3ZAJnqUMzV3kXAibmtcZ0882EOU8rUCibD5NibCyAy0TL5GIevM0owSrTx2FXZwIe4ORb0QecRAXmXos/0",
    "cover_url": "http://wxapp.tc.qq.com/251/20350/stodownload?encfilekey=oibeqyX228riaCwo9STVsGLIBn9G5YG8ZnJujjw3bicy2C6VG5mQPSicDYVCVOhia6jbuX6P7RFZLzkVV2FiaOWgVXWd7MGM4tYFicBEmb781ZJicfOxUEN56wmOJvg7MdhONhYMkzC06To9PVM&adaptivelytrans=0&bizid=1023&dotrans=0&hy=SZ&idx=1&m=8d80177b490d9d27c78d3ef4d6e80ef3&token=x5Y29zUxcibB90eQl2iao3wM9KWnEdVy6khUsCxbwS6xG9OQnXMU4Snahdia1hjibCIB9x0CDPG7dibY&finder_expire_time=1657090220&finder_eid=export%2FUzFfAgtgekIEAQAAAAAAE-Ixm2BRsAAAAAstQy6ubaLX4KHWvLEZgBPExYM4dVgyZY6DzNPgMIAUe9mrgQQscNXyDyQgHbOX",
    "desc": "下午好",
    "extras": "",
    "feed_type": 9,
    "nickname": "星子Stella",
    "object_id": "13895574026529675281",
    "object_nonce_id": "13435211891441762521_0_0_0_0",
    "thumb_url": "http://wxapp.tc.qq.com/251/20350/stodownload?encfilekey=oibeqyX228riaCwo9STVsGLIBn9G5YG8ZnJujjw3bicy2C6VG5mQPSicDYVCVOhia6jbuX6P7RFZLzkVV2FiaOWgVXWd7MGM4tYFicBEmb781ZJicfOxUEN56wmOJvg7MdhONhYMkzC06To9PVM&adaptivelytrans=0&bizid=1023&dotrans=0&hy=SZ&idx=1&m=8d80177b490d9d27c78d3ef4d6e80ef3&token=x5Y29zUxcibB90eQl2iao3wM9KWnEdVy6khUsCxbwS6xG9OQnXMU4Snahdia1hjibCIB9x0CDPG7dibY&finder_expire_time=1657090220&finder_eid=export%2FUzFfAgtgekIEAQAAAAAAE-Ixm2BRsAAAAAstQy6ubaLX4KHWvLEZgBPExYM4dVgyZY6DzNPgMIAUe9mrgQQscNXyDyQgHbOX",
    "url": "https://channels.weixin.qq.com/web/pages/live?eid=export%2FUzFfAgtgekIEAQAAAAAAE-Ixm2BRsAAAAAstQy6ubaLX4KHWvLEZgBPExYM4dVgyZY6DzNPgMIAUe9mrgQQscNXyDyQgHbOX"
  },
  "type": 11196
}
返回

{
    "data":{
        "is_svr_fail":false,
        "msg_data":{
            "appinfo":"Q0FVUXBPWGFqUVlZMUtXbmpkc3ZJQWs9",
            "asid":0,
            "content":"ChdodHRwczovL3d3dy5kb3V5aW4uY29tLxI1aHR0cHM6Ly9iLnpvbC1pbWcuY29tLmNuL3NvZnQvNy85MDcvY2VDNEh0ZlFxa2lnYy5qcGcaCeaKlumfs0FQUCIn55So56eR5oqA6K6p5aSN5p2C55qE5LiW55WM5pu0566A5Y2V77yB",
            "contenttype":13,
            "custom_service":"",
            "devinfo":65537,
            "extra_content":"",
            "flag":16777216,
            "id":1098795,
            "image_url":"",
            "innerkf_vid":0,
            "messagetype":0,
            "readuinscount":0,
            "receiver":7881302xxx98,
            "referid":0,
            "roomid":0,
            "sender":168885053xxx82,
            "sendername":"5bCP6YKq",
            "sendtime":1639363237,
            "seq":8513915
        }
    },
    "type":11196
}

4、CDN操作相关

复制代码
1、CDN上传
请求

当file_type为1时, 可以上传图片(包括gif动图格式)

 {
    "type":11115,
    "data":{
        "file_path":"c:\\Users\\evilbeast\\Pictures\\750x1250-1.jpg",
        "file_type":1
    }
}
返回

{
    "data":{
        "error_code":0,  // 为0是上传成功 
        "file_aes_key":"39373437333363346461613761633761", // cdn文件密钥
        "file_id":"3052020102044b30490201000204283cabaa02030f424102049cd366b4020461b698dc040d3136333933353636333438383602010002030ec8700410059b34e084cf19a38a92a677177863d20201010201000400", // cdn文件id
        "file_key":"1639356634886", // file_key
        "file_md5":"059b34e084cf19a38a92a677177863d2", // 文件md5
        "file_path":"c:\\Users\\evilbeast\\Pictures\\750x1250-1.jpg",
        "file_size":968802,   // 图片大小
        "file_type":1,
        "image_height":1250,  // 图片高
        "image_width":750    // 图片宽
    },
    "type":11115
}

2、CDN下载2
当接收到的消息中cdn_type为2时,使用Cdn下载

请求

{
    "type":11170,
    "data":{
        "aes_key":"61316639333163346262363730326261",
        "file_id":"3052020102044b30490201000204283cabaa02030f4241020436c16eb4020461b453fb040d3136333932303739323932303602010002030ec8700410059b34e084cf19a38a92a677177863d20201010201000400",
        "save_path":"e:\\cdn\\1.jpg",
        "file_size":968802,
        "file_type":1
    }
}
file_type值如下:

值 说明
1 原图
2 中图
3 缩略图
4 视频
5 文件

返回

 {
  "data": {
    "error_code": 0,
    "file_id": "3052020102044b30490201000204283cabaa02030f4241020436c16eb4020461b453fb040d3136333932303739323932303602010002030ec8700410059b34e084cf19a38a92a677177863d20201010201000400",
    "save_path": "e:\\cdn\\1.jpg"
  },
  "type": 11170
}

3、CDN下载1
当接收到的消息中cdn_type为1时,使用WxCdn下载

请求

 {
    "type":11171,
    "data":{
        "url":"https:\/\/imunion.weixin.qq.com\/cgi-bin\/mmae-bin\/tpdownloadmedia?param=v1_84d696afdc73fbf997931c6eb898facc4830ae5cb891060fdd5cca540beccd2de56cbc84207058d80f2af266f925e458ca19263f710bc0905881589f0b816c5def9bb2a039e0127bb680b6f3c8db2f93abf477d369374598cea92a001adf3f5977ba47cfa347643a36b05f96c4fa54ebc7f4f00767a0ba2a859ac82b6c0e9efacd07eb5c15c098837f4a19f27a0a897a890394f88ae7dd215f75e4199ac4c5e9c893358e5aee215a07ac0882aad2e72e249cacaaf0e2929ebf15dc147fceb386f8560923cba106cea3f5c0548ace640455df853ab7606f6e88acf48cdcb9593d7873c487536327e8988d969a360da527c09d7765dfc382ed98071720c3b3ba108cc2c3504907d095575676333a64ae6a2fdf9a2af2138e1c0d953a56d6a3c281348a7e71fd10f7b80220e4b4a4c1473ac5f00e07d132ad000289d96bd8abc40a",
        "auth_key":"v1_84d696afdc73fbf997931c6eb898facc4830ae5cb891060fdd5cca540beccd2d2d7fa866eb7f785638f4c69ac9c904a43685d48a39b7162bbab469dc884dd1e8",
        "aes_key":"9385a744af20cba0e59a52d51e3cacd1",
        "size":16504,
        "save_path":"e:\\cdn\\3.jpg"
    }
}
返回

{
    "data":{
        "error_code":0,
        "save_path":"e:\\cdn\\3.jpg"
    },
    "type":11171
}

5、通知回调相关

四、配置部署环境

1、需要PYTHON 32位、微信4.1.38

设置企微自动更新关闭

2、配置后运行操作

【1】先安装32 PYTHON SDK

【2】py -3-32 -m pip install flask requests

【3】py -3-32 app.py

五、JAVA核心实现代码

复制代码
package com.black.step;

import com.black.util.Constants;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.util.HashMap;
import java.util.Map;

public class Step4_SendText {
    public static void main(String[] args) {
        doWorkSend("7881299875322892", "你好呀");
    }

    public static String doWorkSend(String conversationId, String sendContent) {
        try {
            int clientId = 1;
            Map<String, Object> result = Step4_SendText.sendTextMessage(clientId, conversationId, sendContent);
            System.out.println("发送结果: " + result);
            return result.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return "发送文本发生错误";
        }
    }

    private static final String API_URL = "http://127.0.0.1:5001/api/send_text";
    private static final ObjectMapper objectMapper = new ObjectMapper();

    public static Map<String, Object> sendTextMessage(int clientId, String conversationId, String content) throws Exception {
        try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
            HttpPost httpPost = new HttpPost(API_URL);

            // 构建请求体
            Map<String, Object> requestBody = new HashMap<>();
            requestBody.put("client_id", clientId);
            if (!conversationId.contains("R:")) {
                // 请求Controller,换取conversation_id
                conversationId = UserIdChangeConversationId.getConversationIdByUserId(conversationId);
            }
            requestBody.put("conversation_id", conversationId);
            requestBody.put("content", content);

            System.err.println(requestBody);

            // 设置请求体和头信息
            String jsonBody = objectMapper.writeValueAsString(requestBody);
            StringEntity entity = new StringEntity(jsonBody, "UTF-8");
            entity.setContentType("application/json");
            httpPost.setEntity(entity);

            // 发送请求
            try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
                String responseBody = EntityUtils.toString(response.getEntity(), "UTF-8");
                return objectMapper.readValue(responseBody, Map.class);
            }
        }
    }
}

package com.black.step;

import com.black.util.Constants;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.util.HashMap;
import java.util.Map;

public class Step5_SendImage {
    public static void main(String[] args) {
        doWorkSend("7881299875322892", "C:\\Users\\xlliu24\\Desktop\\IT01\\black\\src\\main\\resources\\download\\1761026088267");
    }

    public static String doWorkSend(String conversationId, String filePath) {
        try {
            int clientId = 1;
            Map<String, Object> result = Step5_SendImage.sendImageMessage(clientId, conversationId, filePath);
            System.out.println("发送结果: " + result);
            return result.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return "发送图片发生错误";
        }
    }

    private static final String API_URL = "http://127.0.0.1:5001/api/send_image";
    private static final ObjectMapper objectMapper = new ObjectMapper();

    public static Map<String, Object> sendImageMessage(int clientId, String conversationId, String filePath) throws Exception {
        try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
            HttpPost httpPost = new HttpPost(API_URL);

            // 构建请求体
            Map<String, Object> requestBody = new HashMap<>();
            requestBody.put("client_id", clientId);
            if (!conversationId.contains("R:")) {
                // 请求Controller,换取conversation_id
                conversationId = UserIdChangeConversationId.getConversationIdByUserId(conversationId);
            }
            requestBody.put("conversation_id", conversationId);
            requestBody.put("file", filePath);

            System.err.println(requestBody);

            // 设置请求体和头信息
            String jsonBody = objectMapper.writeValueAsString(requestBody);
            StringEntity entity = new StringEntity(jsonBody, "UTF-8");
            entity.setContentType("application/json");
            httpPost.setEntity(entity);

            // 发送请求
            try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
                String responseBody = EntityUtils.toString(response.getEntity(), "UTF-8");
                return objectMapper.readValue(responseBody, Map.class);
            }
        }
    }
}

package com.black.step;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.util.HashMap;
import java.util.Map;

public class Step6_SendGif {
    public static void main(String[] args) {
        doWorkSend("7881299875322892", "C:\\Users\\xlliu24\\Desktop\\IT01\\black\\src\\main\\resources\\download\\1761026088267");
    }

    public static String doWorkSend(String conversationId, String filePath) {
        try {
            int clientId = 1;
            Map<String, Object> result = Step6_SendGif.sendImageMessage(clientId, conversationId, filePath);
            System.out.println("发送结果: " + result);
            return result.toString();
        } catch (Exception e) {
            e.printStackTrace();
            return "发送图片发生错误";
        }
    }

    private static final String API_URL = "http://127.0.0.1:5001/api/send_gif";
    private static final ObjectMapper objectMapper = new ObjectMapper();

    public static Map<String, Object> sendImageMessage(int clientId, String conversationId, String filePath) throws Exception {
        try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
            HttpPost httpPost = new HttpPost(API_URL);

            // 构建请求体
            Map<String, Object> requestBody = new HashMap<>();
            requestBody.put("client_id", clientId);
            if (!conversationId.contains("R:")) {
                // 请求Controller,换取conversation_id
                conversationId = UserIdChangeConversationId.getConversationIdByUserId(conversationId);
            }
            requestBody.put("conversation_id", conversationId);
            requestBody.put("file", filePath);

            System.err.println(requestBody);

            // 设置请求体和头信息
            String jsonBody = objectMapper.writeValueAsString(requestBody);
            StringEntity entity = new StringEntity(jsonBody, "UTF-8");
            entity.setContentType("application/json");
            httpPost.setEntity(entity);

            // 发送请求
            try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
                String responseBody = EntityUtils.toString(response.getEntity(), "UTF-8");
                return objectMapper.readValue(responseBody, Map.class);
            }
        }
    }
}

package com.black.step;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;

public class UserIdChangeConversationId {
    public static void main(String[] args) throws IOException {
        String conversationId = getConversationIdByUserId("1688856572828981");
        System.out.println(conversationId);
    }

    public static String getConversationIdByUserId(String userId) throws IOException {
        String url = "http://localhost:5000/big/from_user_id_change_to_conversation_id";

        // 创建JSON请求体
        String jsonInputString = "{\"userId\":\"" + userId + "\"}";

        HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type", "application/json");
        connection.setRequestProperty("Accept", "application/json");
        connection.setDoOutput(true);

        // 发送请求
        try (OutputStream os = connection.getOutputStream()) {
            byte[] input = jsonInputString.getBytes("utf-8");
            os.write(input, 0, input.length);
        }

        // 读取响应
        int responseCode = connection.getResponseCode();
        if (responseCode == HttpURLConnection.HTTP_OK) {
            try (BufferedReader br = new BufferedReader(
                    new InputStreamReader(connection.getInputStream(), "utf-8"))) {
                StringBuilder response = new StringBuilder();
                String responseLine;
                while ((responseLine = br.readLine()) != null) {
                    response.append(responseLine.trim());
                }
                return response.toString();
            }
        } else {
            throw new RuntimeException("HTTP请求失败: " + responseCode);
        }
    }
}

六、实现效果

1、拉取内外部好友信息

2、拉取所有群信息

3、实现发送文本、图片、表情功能

相关推荐
YongCheng_Liang4 小时前
从零开始学虚拟化:性能优化全指南(资源分配 + 存储网络 + 监控)
运维·云计算
lcx_defender4 小时前
【Docker】Docker部署运行Kibana
运维·docker·容器
心语星光4 小时前
用python语言的pyautogui库实现伪批量将xdf文件打印为pdf文件
开发语言·python·pdf·自动化
roamingcode4 小时前
Cursor-memory-cli 自动化记忆提取的完整实现
运维·自动化·agent·memory·cursor·持久化记忆
YongCheng_Liang4 小时前
从零开始学虚拟化:高可用与灾备技术全解析(集群 + 备份 + 异地灾备)
运维·云计算
ℳ₯㎕ddzོꦿ࿐4 小时前
实战:构建基于 Docker-Compose 的HLS (m3u8) 实时转 FLV,基于 ZLMediaKit 的低延迟方案
运维·docker·容器
济6174 小时前
linux 系统移植(第二十八期)---- 运用MfgTool 工具烧写自制的烧写自制的系统系统---- Ubuntu20.04
linux·运维·服务器
太理摆烂哥4 小时前
Linux基础指令
linux·运维·服务器
昨夜见军贴06164 小时前
合规性管理的现代化实践:IACheck的AI审核如何系统提升生产型检测报告的合规水平
大数据·运维·人工智能