怎么发消息卡片
1. 获取应用信息
应用创建后,可以登录开发者后台查看应用的 AppID 和 SecretKey。

2. 申请接口权限
在开发者后台权限申请栏,申请相关接口权限。其中发送消息、更新消息需要申请“通过接口发送消息“和“企业通讯录”接口权限。

3. 配置回调地址
卡片消息支持回传交互,指用户操作交互组件后,向你的服务端提交用户操作数据的交互。你可以根据收到用户提交的信息,请求更新卡片内容,及时对用户的交互行为进行反馈。如果需要配置卡片回调,则需要在开发者后台 api 发送页配置卡片回调地址。

注意:配置后该地址无法删除,只能修改。目前并没有对地址进行合法性校验,接入方需自己保证地址可用。
回传方式:POST 方式,将内容放在 body 回传。回传请求会加上 WPS-4 签名认证
当接入方应用收到回传内容后,返回{"result":"ok"}代表成功。
4. 发送消息
申请接口权限并通过审核后,即可使用发送消息接口,发送消息。自建应用机器人可以给指定用户或者会话发送消息,支持文本、图片、图文混排、外链图文、Markdown、消息卡片等消息类型,满足丰富的业务场景需求。
发送消息接口
接口信息
[POST] 配置域名+/o/woa/api/v2/developer/app/messages
鉴权说明
参数说明
| 名称 | 参数位置 | 类型 | 是否必填 | 说明 | | :------------- | :------- | :------- | :-------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | --- | | company_token | query | string | 是 | company_token 获取企业授权 | | app_key | body | string | 是 | 指定当前使用的 AK。如无特殊情况,此处 AK 和验证签名的 AK 一样,这里主要为了给类似开放平台代理应用透传真正发消息的 AK | | to_users | body | object | to_users、to_depts、to_companies 三选一 | 发送给某个企业的部分人员 | | ∟ company_id | body | string | 否 | 企业 id | | ∟ company_uids | body | []string | 否 | 用户 ids | | to_depts | body | object | to_users、to_depts、to_companies 三选一 | 发送给对应部门 | | ∟ company_id | body | string | 否 | 企业 id | | ∟ dept_ids | body | string | 否 | 部门 ids | | to_companies | body | string | to_users、to_depts、to_companies 三选一 | 发送给对应公司 | | biz_type | body | string | 否 | 消息所属业务类型,并且尽量是当前 app_key 下唯一。主要用来区分具体业务,做一些业务特殊处理。对于卡片消息建议加上 | | ctx_id | body | string | 需要后续更新消息则必须 | 需要后续更新消息时则必须,卡片消息则最长不超过 36,用于更改消息和回调,不能重复。 | | company_uid | body | string | 需要后续更新消息则必须 | 需要后续更新消息时则必须,消息生产者 id | | company_id | body | string | 需要后续更新消息则必须 | 需要后续更新消息时则必须,消息生产者企业 id | | utype | body | int | 需要后续更新消息则必须 | 需要后续更新消息时则必须,后续消息更新方式,0 - 后续不更新,1-后续更新消息 | | msg_type | body | int | 是 | 表示消息类容格式类型。23-代表卡片消息 | | content | body | object | 是 | 消息内容 | | ∟ type | body | int | 是 | 消息类型,与外面 msg_type 一致 | | | ∟ content | body | object | 是 | 卡片消息 json 内容,具体 json 内容格式可参考 消息卡片总体结构 |
请求正文
{
"to_users":{
"company_id":"11111",
"company_uids":[
"11111"
]
},
"app_key":"WK202xxxx3141501",
"biz_type":"test",
"ctx_id":"11111",
"company_id":"11111",
"company_uid":"11111",
"utype":1,
"msg_type":23,
"content":{
"type":23,
"content":{
"header":{
"title":{
"tag":"text",
"content":{
"type":"plainText",
"text":"卡片标题"
}
}
},
"elements":[
{
"tag":"text",
"content":{
"type":"markdown",
"text":"卡片内容"
}
},
{
"tag":"action",
"actions":[
{
"tag":"button",
"content":{
"type":"plainText",
"text":"按钮"
},
"style":"secondary",
"href": {
"url_val": {
"url": "https://xz.wps.cn/",
"android_url": "https://xz.wps.cn/",
"ios_url": "https://xz.wps.cn/",
"pc_url": "https://xz.wps.cn/"
}
}
}
]
}
]
}
}
}效果展示
