Appearance
发送小程序
按结构化参数发送小程序卡片消息。
接口地址: POST /sendApplets
前置条件
- 微信实例已登录,并已获得可用
wId。 - 接收方
wcId可以是好友微信 ID,也可以是群 ID。 - 小程序参数建议从已收到的小程序消息回调中提取,避免手工拼错。
iconUrl、thumbUrl建议使用稳定公网图片,格式为 PNG/JPG,大小控制在 50KB 以内。
请求参数
| 参数名 | 必选 | 类型 | 说明 |
|---|---|---|---|
| wId | 是 | string | 登录实例标识 |
| wcId | 是 | string | 接收方微信 ID/群 ID |
| displayName | 是 | string | 小程序名称,例如:京东 |
| iconUrl | 是 | string | 小程序卡片图标 URL,PNG/JPG 格式,50KB 以内 |
| appId | 是 | string | 小程序 appID,例如:wx7c544e9a8b12345 |
| pagePath | 是 | string | 点击小程序卡片后的跳转路径 |
| thumbUrl | 是 | string | 小程序卡片缩略图 URL,PNG/JPG 格式,50KB 以内 |
| title | 是 | string | 标题 |
| userName | 是 | string | 小程序原始 ID,例如:gh_88b080670a71@app |
响应参数
| 参数名 | 类型 | 说明 |
|---|---|---|
| code | string | 1000 成功;其他值都是失败,通常是 1001 |
| message | string | 反馈信息 |
| data.type | int | 类型 |
| data.msgId | long | 消息 ID |
| data.newMsgId | long | 新消息 ID |
| data.createTime | long | 发送时间戳(秒) |
| data.wcId | string | 接收方 ID |
说明
- 参数来源可以参考消息回调中的小程序消息字段,业务侧也可以按需自定义跳转参数。
请求示例
http
POST {BASE_URL}/sendApplets
Authorization: Bearer <你的调用凭证>
Content-Type: application/json
{
"wId": "0000016f-78bd-21c8-0001-29c4d004ae46",
"wcId": "filehelper",
"displayName": "云铺海购",
"iconUrl": "https://cdn.eyunapp.com/miniprogram/icon.png",
"appId": "wx07af7e375d21a08c",
"pagePath": "pages/home/dashboard/index.html?shopAutoEnter=1&is_share=1&share_cmpt=native_wechat&kdt_id=109702811&from_uuid=FgPTe5LTPr00dw21663912217667",
"thumbUrl": "https://pic3.zhimg.com/v2-f73763905eed23308466e441430a43be_r.jpg",
"title": "云铺海购",
"userName": "gh_12566478d436@app"
}bash
curl -X POST '{BASE_URL}/sendApplets' \
-H 'Authorization: Bearer <你的调用凭证>' \
-H 'Content-Type: application/json' \
--data-raw '{
"wId": "0000016f-78bd-21c8-0001-29c4d004ae46",
"wcId": "filehelper",
"displayName": "云铺海购",
"iconUrl": "https://cdn.eyunapp.com/miniprogram/icon.png",
"appId": "wx07af7e375d21a08c",
"pagePath": "pages/home/dashboard/index.html?shopAutoEnter=1&is_share=1&share_cmpt=native_wechat&kdt_id=109702811&from_uuid=FgPTe5LTPr00dw21663912217667",
"thumbUrl": "https://pic3.zhimg.com/v2-f73763905eed23308466e441430a43be_r.jpg",
"title": "云铺海购",
"userName": "gh_12566478d436@app"
}'python
import requests
url = "{BASE_URL}/sendApplets"
headers = {"Authorization": "Bearer <你的调用凭证>", "Content-Type": "application/json"}
body = """{
"wId": "0000016f-78bd-21c8-0001-29c4d004ae46",
"wcId": "filehelper",
"displayName": "云铺海购",
"iconUrl": "https://cdn.eyunapp.com/miniprogram/icon.png",
"appId": "wx07af7e375d21a08c",
"pagePath": "pages/home/dashboard/index.html?shopAutoEnter=1&is_share=1&share_cmpt=native_wechat&kdt_id=109702811&from_uuid=FgPTe5LTPr00dw21663912217667",
"thumbUrl": "https://pic3.zhimg.com/v2-f73763905eed23308466e441430a43be_r.jpg",
"title": "云铺海购",
"userName": "gh_12566478d436@app"
}"""
resp = requests.post(url, headers=headers, data=body.encode("utf-8"))
print(resp.text)java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
String url = "{BASE_URL}/sendApplets";
String body = "{\n" +
" \"wId\": \"0000016f-78bd-21c8-0001-29c4d004ae46\",\n" +
" \"wcId\": \"filehelper\",\n" +
" \"displayName\": \"云铺海购\",\n" +
" \"iconUrl\": \"https://cdn.eyunapp.com/miniprogram/icon.png\",\n" +
" \"appId\": \"wx07af7e375d21a08c\",\n" +
" \"pagePath\": \"pages/home/dashboard/index.html?shopAutoEnter=1&is_share=1&share_cmpt=native_wechat&kdt_id=109702811&from_uuid=FgPTe5LTPr00dw21663912217667\",\n" +
" \"thumbUrl\": \"https://pic3.zhimg.com/v2-f73763905eed23308466e441430a43be_r.jpg\",\n" +
" \"title\": \"云铺海购\",\n" +
" \"userName\": \"gh_12566478d436@app\"\n" +
"}";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(URI.create(url))
.header("Authorization", "Bearer <你的调用凭证>")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());php
<?php
$url = '{BASE_URL}/sendApplets';
$body = <<<'JSON'
{
"wId": "0000016f-78bd-21c8-0001-29c4d004ae46",
"wcId": "filehelper",
"displayName": "云铺海购",
"iconUrl": "https://cdn.eyunapp.com/miniprogram/icon.png",
"appId": "wx07af7e375d21a08c",
"pagePath": "pages/home/dashboard/index.html?shopAutoEnter=1&is_share=1&share_cmpt=native_wechat&kdt_id=109702811&from_uuid=FgPTe5LTPr00dw21663912217667",
"thumbUrl": "https://pic3.zhimg.com/v2-f73763905eed23308466e441430a43be_r.jpg",
"title": "云铺海购",
"userName": "gh_12566478d436@app"
}
JSON;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer <你的调用凭证>',
'Content-Type: application/json',
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;成功响应
json
{
"code": "1000",
"message": "发送小程序成功",
"data": {
"type": 0,
"msgId": 697760545,
"newMsgId": 7645748705605226305,
"createTime": 1641458149,
"wcId": "jack_623555049"
}
}错误响应
json
{
"message": "失败",
"code": "1001",
"data": null
}使用建议
- 优先使用本接口发送标准小程序卡片;只有必须复用完整 XML 时,再用转发小程序。
pagePath可携带业务参数,建议发送前做 URL 编码和长度校验。- 小程序封面图建议走稳定 CDN,避免临时图片过期导致卡片封面无法展示。