Skip to content

转发小程序 ​

用收到的小程序消息 XML 转发小程序卡片。按参数新发一张卡片用发送小程序。

接口地址: POST /sendApplet

说明与注意 ​

  • imgUrl 要是公网能直接访问的图片。
  • XML 里的缩略图过期了,先调CDN 图片上传,再替换 XML 里的缩略图字段。

请求参数 ​

参数名必选类型说明
wId是string登录实例标识
wcId是string接收方微信 ID/群 ID
imgUrl是string小程序封面图,PNG/JPG 格式,50KB 以内
content是string小程序 XML 内容;通常从消息回调中获取并截取 appmsg 节点,可按需自定义跳转参数、缩略图等字段

请求示例 ​

http
POST {BASE_URL}/sendApplet
Authorization: Bearer <你的调用凭证>
Content-Type: application/json

{
 "wId": "0000016f-78bd-21c8-0001-29c4d004ae46",
 "wcId": "jack_623555049",
 "imgUrl":"http://photocdn.sohu.com/20120323/Img338614056.jpg",
 "content": "<appmsg appid=\"\" sdkver=\"0\">\n\t\t<title>云铺海购</title>\n\t\t<des>云铺海购</des>\n\t\t<type>33</type>\n\t\t<url>https://mp.weixin.qq.com/mp/waerrpage?appid=wx07af7e375d21a08c&amp;type=upgrade&amp;upgradetype=3#wechat_redirect</url>\n\t\t<appattach>\n\t\t\t<cdnthumburl>3057020100044b30490201000204502c9b9f02032f55f902040ed15eda0204632dc841042461316335306262662d393337322d343361332d383631312d6166613731306362643764300204011400030201000405004c51e500</cdnthumburl>\n\t\t\t<cdnthumbmd5>e1c43f713ebc389dc8f89690aeb7ecb4</cdnthumbmd5>\n\t\t\t<cdnthumblength>58598</cdnthumblength>\n\t\t\t<cdnthumbwidth>720</cdnthumbwidth>\n\t\t\t<cdnthumbheight>576</cdnthumbheight>\n\t\t\t<cdnthumbaeskey>125805800e40722f240220286e3ef74d</cdnthumbaeskey>\n\t\t\t<aeskey>125805800e40722f240220286e3ef74d</aeskey>\n\t\t\t<encryver>0</encryver>\n\t\t\t<filekey>wxid_ctqh94e1ahe722_26_1663944768</filekey>\n\t\t</appattach>\n\t\t<sourceusername>gh_12566478d436@app</sourceusername>\n\t\t<sourcedisplayname>云铺海购</sourcedisplayname>\n\t\t<md5>e1c43f713ebc389dc8f89690aeb7ecb4</md5>\n\t\t<recorditem><![CDATA[(null)]]></recorditem>\n\t\t<weappinfo>\n\t\t\t<username><![CDATA[gh_12566478d436@app]]></username>\n\t\t\t<appid><![CDATA[wx07af7e375d21a08c]]></appid>\n\t\t\t<type>2</type>\n\t\t\t<version>14</version>\n\t\t\t<weappiconurl><![CDATA[http://mmbiz.qpic.cn/mmbiz_png/uLxzSQcibsGzibyibBMLZhib1ick4RhO4ic203iaKMMSL35riafKicdyy8OX0ibjeDrs4Vka2KwTibiaPiaeXBKDQ24pblJO6mg/640?wx_fmt=png&wxfrom=200]]></weappiconurl>\n\t\t\t<pagepath><![CDATA[pages/home/dashboard/index.html?shopAutoEnter=1&is_share=1&share_cmpt=native_wechat&kdt_id=109702811&from_uuid=FgPTe5LTPr00dw21663912217667]]></pagepath>\n\t\t\t<shareId><![CDATA[0_wx07af7e375d21a08c_5a36c4cc14fb8effefecbd92a1f291a6_1663944761_0]]></shareId>\n\t\t\t<appservicetype>0</appservicetype>\n\t\t\t<brandofficialflag>0</brandofficialflag>\n\t\t\t<showRelievedBuyFlag>0</showRelievedBuyFlag>\n\t\t\t<subType>0</subType>\n\t\t\t<isprivatemessage>0</isprivatemessage>\n\t\t</weappinfo>\n\t</appmsg>"
}
bash
curl -X POST '{BASE_URL}/sendApplet' \
  -H 'Authorization: Bearer <你的调用凭证>' \
  -H 'Content-Type: application/json' \
  --data-raw '{
 "wId": "0000016f-78bd-21c8-0001-29c4d004ae46",
 "wcId": "jack_623555049",
 "imgUrl":"http://photocdn.sohu.com/20120323/Img338614056.jpg",
 "content": "<appmsg appid=\"\" sdkver=\"0\">\n\t\t<title>云铺海购</title>\n\t\t<des>云铺海购</des>\n\t\t<type>33</type>\n\t\t<url>https://mp.weixin.qq.com/mp/waerrpage?appid=wx07af7e375d21a08c&amp;type=upgrade&amp;upgradetype=3#wechat_redirect</url>\n\t\t<appattach>\n\t\t\t<cdnthumburl>3057020100044b30490201000204502c9b9f02032f55f902040ed15eda0204632dc841042461316335306262662d393337322d343361332d383631312d6166613731306362643764300204011400030201000405004c51e500</cdnthumburl>\n\t\t\t<cdnthumbmd5>e1c43f713ebc389dc8f89690aeb7ecb4</cdnthumbmd5>\n\t\t\t<cdnthumblength>58598</cdnthumblength>\n\t\t\t<cdnthumbwidth>720</cdnthumbwidth>\n\t\t\t<cdnthumbheight>576</cdnthumbheight>\n\t\t\t<cdnthumbaeskey>125805800e40722f240220286e3ef74d</cdnthumbaeskey>\n\t\t\t<aeskey>125805800e40722f240220286e3ef74d</aeskey>\n\t\t\t<encryver>0</encryver>\n\t\t\t<filekey>wxid_ctqh94e1ahe722_26_1663944768</filekey>\n\t\t</appattach>\n\t\t<sourceusername>gh_12566478d436@app</sourceusername>\n\t\t<sourcedisplayname>云铺海购</sourcedisplayname>\n\t\t<md5>e1c43f713ebc389dc8f89690aeb7ecb4</md5>\n\t\t<recorditem><![CDATA[(null)]]></recorditem>\n\t\t<weappinfo>\n\t\t\t<username><![CDATA[gh_12566478d436@app]]></username>\n\t\t\t<appid><![CDATA[wx07af7e375d21a08c]]></appid>\n\t\t\t<type>2</type>\n\t\t\t<version>14</version>\n\t\t\t<weappiconurl><![CDATA[http://mmbiz.qpic.cn/mmbiz_png/uLxzSQcibsGzibyibBMLZhib1ick4RhO4ic203iaKMMSL35riafKicdyy8OX0ibjeDrs4Vka2KwTibiaPiaeXBKDQ24pblJO6mg/640?wx_fmt=png&wxfrom=200]]></weappiconurl>\n\t\t\t<pagepath><![CDATA[pages/home/dashboard/index.html?shopAutoEnter=1&is_share=1&share_cmpt=native_wechat&kdt_id=109702811&from_uuid=FgPTe5LTPr00dw21663912217667]]></pagepath>\n\t\t\t<shareId><![CDATA[0_wx07af7e375d21a08c_5a36c4cc14fb8effefecbd92a1f291a6_1663944761_0]]></shareId>\n\t\t\t<appservicetype>0</appservicetype>\n\t\t\t<brandofficialflag>0</brandofficialflag>\n\t\t\t<showRelievedBuyFlag>0</showRelievedBuyFlag>\n\t\t\t<subType>0</subType>\n\t\t\t<isprivatemessage>0</isprivatemessage>\n\t\t</weappinfo>\n\t</appmsg>"
}'
python
import requests

url = "{BASE_URL}/sendApplet"
headers = {"Authorization": "Bearer <你的调用凭证>", "Content-Type": "application/json"}
body = r"""{
 "wId": "0000016f-78bd-21c8-0001-29c4d004ae46",
 "wcId": "jack_623555049",
 "imgUrl":"http://photocdn.sohu.com/20120323/Img338614056.jpg",
 "content": "<appmsg appid=\"\" sdkver=\"0\">\n\t\t<title>云铺海购</title>\n\t\t<des>云铺海购</des>\n\t\t<type>33</type>\n\t\t<url>https://mp.weixin.qq.com/mp/waerrpage?appid=wx07af7e375d21a08c&amp;type=upgrade&amp;upgradetype=3#wechat_redirect</url>\n\t\t<appattach>\n\t\t\t<cdnthumburl>3057020100044b30490201000204502c9b9f02032f55f902040ed15eda0204632dc841042461316335306262662d393337322d343361332d383631312d6166613731306362643764300204011400030201000405004c51e500</cdnthumburl>\n\t\t\t<cdnthumbmd5>e1c43f713ebc389dc8f89690aeb7ecb4</cdnthumbmd5>\n\t\t\t<cdnthumblength>58598</cdnthumblength>\n\t\t\t<cdnthumbwidth>720</cdnthumbwidth>\n\t\t\t<cdnthumbheight>576</cdnthumbheight>\n\t\t\t<cdnthumbaeskey>125805800e40722f240220286e3ef74d</cdnthumbaeskey>\n\t\t\t<aeskey>125805800e40722f240220286e3ef74d</aeskey>\n\t\t\t<encryver>0</encryver>\n\t\t\t<filekey>wxid_ctqh94e1ahe722_26_1663944768</filekey>\n\t\t</appattach>\n\t\t<sourceusername>gh_12566478d436@app</sourceusername>\n\t\t<sourcedisplayname>云铺海购</sourcedisplayname>\n\t\t<md5>e1c43f713ebc389dc8f89690aeb7ecb4</md5>\n\t\t<recorditem><![CDATA[(null)]]></recorditem>\n\t\t<weappinfo>\n\t\t\t<username><![CDATA[gh_12566478d436@app]]></username>\n\t\t\t<appid><![CDATA[wx07af7e375d21a08c]]></appid>\n\t\t\t<type>2</type>\n\t\t\t<version>14</version>\n\t\t\t<weappiconurl><![CDATA[http://mmbiz.qpic.cn/mmbiz_png/uLxzSQcibsGzibyibBMLZhib1ick4RhO4ic203iaKMMSL35riafKicdyy8OX0ibjeDrs4Vka2KwTibiaPiaeXBKDQ24pblJO6mg/640?wx_fmt=png&wxfrom=200]]></weappiconurl>\n\t\t\t<pagepath><![CDATA[pages/home/dashboard/index.html?shopAutoEnter=1&is_share=1&share_cmpt=native_wechat&kdt_id=109702811&from_uuid=FgPTe5LTPr00dw21663912217667]]></pagepath>\n\t\t\t<shareId><![CDATA[0_wx07af7e375d21a08c_5a36c4cc14fb8effefecbd92a1f291a6_1663944761_0]]></shareId>\n\t\t\t<appservicetype>0</appservicetype>\n\t\t\t<brandofficialflag>0</brandofficialflag>\n\t\t\t<showRelievedBuyFlag>0</showRelievedBuyFlag>\n\t\t\t<subType>0</subType>\n\t\t\t<isprivatemessage>0</isprivatemessage>\n\t\t</weappinfo>\n\t</appmsg>"
}"""

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}/sendApplet";
String body = "{\n" +
    " \"wId\": \"0000016f-78bd-21c8-0001-29c4d004ae46\",\n" +
    " \"wcId\": \"jack_623555049\",\n" +
    " \"imgUrl\":\"http://photocdn.sohu.com/20120323/Img338614056.jpg\",\n" +
    " \"content\": \"<appmsg appid=\\\"\\\" sdkver=\\\"0\\\">\\n\\t\\t<title>云铺海购</title>\\n\\t\\t<des>云铺海购</des>\\n\\t\\t<type>33</type>\\n\\t\\t<url>https://mp.weixin.qq.com/mp/waerrpage?appid=wx07af7e375d21a08c&amp;type=upgrade&amp;upgradetype=3#wechat_redirect</url>\\n\\t\\t<appattach>\\n\\t\\t\\t<cdnthumburl>3057020100044b30490201000204502c9b9f02032f55f902040ed15eda0204632dc841042461316335306262662d393337322d343361332d383631312d6166613731306362643764300204011400030201000405004c51e500</cdnthumburl>\\n\\t\\t\\t<cdnthumbmd5>e1c43f713ebc389dc8f89690aeb7ecb4</cdnthumbmd5>\\n\\t\\t\\t<cdnthumblength>58598</cdnthumblength>\\n\\t\\t\\t<cdnthumbwidth>720</cdnthumbwidth>\\n\\t\\t\\t<cdnthumbheight>576</cdnthumbheight>\\n\\t\\t\\t<cdnthumbaeskey>125805800e40722f240220286e3ef74d</cdnthumbaeskey>\\n\\t\\t\\t<aeskey>125805800e40722f240220286e3ef74d</aeskey>\\n\\t\\t\\t<encryver>0</encryver>\\n\\t\\t\\t<filekey>wxid_ctqh94e1ahe722_26_1663944768</filekey>\\n\\t\\t</appattach>\\n\\t\\t<sourceusername>gh_12566478d436@app</sourceusername>\\n\\t\\t<sourcedisplayname>云铺海购</sourcedisplayname>\\n\\t\\t<md5>e1c43f713ebc389dc8f89690aeb7ecb4</md5>\\n\\t\\t<recorditem><![CDATA[(null)]]></recorditem>\\n\\t\\t<weappinfo>\\n\\t\\t\\t<username><![CDATA[gh_12566478d436@app]]></username>\\n\\t\\t\\t<appid><![CDATA[wx07af7e375d21a08c]]></appid>\\n\\t\\t\\t<type>2</type>\\n\\t\\t\\t<version>14</version>\\n\\t\\t\\t<weappiconurl><![CDATA[http://mmbiz.qpic.cn/mmbiz_png/uLxzSQcibsGzibyibBMLZhib1ick4RhO4ic203iaKMMSL35riafKicdyy8OX0ibjeDrs4Vka2KwTibiaPiaeXBKDQ24pblJO6mg/640?wx_fmt=png&wxfrom=200]]></weappiconurl>\\n\\t\\t\\t<pagepath><![CDATA[pages/home/dashboard/index.html?shopAutoEnter=1&is_share=1&share_cmpt=native_wechat&kdt_id=109702811&from_uuid=FgPTe5LTPr00dw21663912217667]]></pagepath>\\n\\t\\t\\t<shareId><![CDATA[0_wx07af7e375d21a08c_5a36c4cc14fb8effefecbd92a1f291a6_1663944761_0]]></shareId>\\n\\t\\t\\t<appservicetype>0</appservicetype>\\n\\t\\t\\t<brandofficialflag>0</brandofficialflag>\\n\\t\\t\\t<showRelievedBuyFlag>0</showRelievedBuyFlag>\\n\\t\\t\\t<subType>0</subType>\\n\\t\\t\\t<isprivatemessage>0</isprivatemessage>\\n\\t\\t</weappinfo>\\n\\t</appmsg>\"\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}/sendApplet';
$body = <<<'JSON'
{
 "wId": "0000016f-78bd-21c8-0001-29c4d004ae46",
 "wcId": "jack_623555049",
 "imgUrl":"http://photocdn.sohu.com/20120323/Img338614056.jpg",
 "content": "<appmsg appid=\"\" sdkver=\"0\">\n\t\t<title>云铺海购</title>\n\t\t<des>云铺海购</des>\n\t\t<type>33</type>\n\t\t<url>https://mp.weixin.qq.com/mp/waerrpage?appid=wx07af7e375d21a08c&amp;type=upgrade&amp;upgradetype=3#wechat_redirect</url>\n\t\t<appattach>\n\t\t\t<cdnthumburl>3057020100044b30490201000204502c9b9f02032f55f902040ed15eda0204632dc841042461316335306262662d393337322d343361332d383631312d6166613731306362643764300204011400030201000405004c51e500</cdnthumburl>\n\t\t\t<cdnthumbmd5>e1c43f713ebc389dc8f89690aeb7ecb4</cdnthumbmd5>\n\t\t\t<cdnthumblength>58598</cdnthumblength>\n\t\t\t<cdnthumbwidth>720</cdnthumbwidth>\n\t\t\t<cdnthumbheight>576</cdnthumbheight>\n\t\t\t<cdnthumbaeskey>125805800e40722f240220286e3ef74d</cdnthumbaeskey>\n\t\t\t<aeskey>125805800e40722f240220286e3ef74d</aeskey>\n\t\t\t<encryver>0</encryver>\n\t\t\t<filekey>wxid_ctqh94e1ahe722_26_1663944768</filekey>\n\t\t</appattach>\n\t\t<sourceusername>gh_12566478d436@app</sourceusername>\n\t\t<sourcedisplayname>云铺海购</sourcedisplayname>\n\t\t<md5>e1c43f713ebc389dc8f89690aeb7ecb4</md5>\n\t\t<recorditem><![CDATA[(null)]]></recorditem>\n\t\t<weappinfo>\n\t\t\t<username><![CDATA[gh_12566478d436@app]]></username>\n\t\t\t<appid><![CDATA[wx07af7e375d21a08c]]></appid>\n\t\t\t<type>2</type>\n\t\t\t<version>14</version>\n\t\t\t<weappiconurl><![CDATA[http://mmbiz.qpic.cn/mmbiz_png/uLxzSQcibsGzibyibBMLZhib1ick4RhO4ic203iaKMMSL35riafKicdyy8OX0ibjeDrs4Vka2KwTibiaPiaeXBKDQ24pblJO6mg/640?wx_fmt=png&wxfrom=200]]></weappiconurl>\n\t\t\t<pagepath><![CDATA[pages/home/dashboard/index.html?shopAutoEnter=1&is_share=1&share_cmpt=native_wechat&kdt_id=109702811&from_uuid=FgPTe5LTPr00dw21663912217667]]></pagepath>\n\t\t\t<shareId><![CDATA[0_wx07af7e375d21a08c_5a36c4cc14fb8effefecbd92a1f291a6_1663944761_0]]></shareId>\n\t\t\t<appservicetype>0</appservicetype>\n\t\t\t<brandofficialflag>0</brandofficialflag>\n\t\t\t<showRelievedBuyFlag>0</showRelievedBuyFlag>\n\t\t\t<subType>0</subType>\n\t\t\t<isprivatemessage>0</isprivatemessage>\n\t\t</weappinfo>\n\t</appmsg>"
}
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
}

响应参数 ​

参数名类型说明
codestring1000 成功;其他值都是失败,通常是 1001
messagestring反馈信息
data.typeint类型
data.msgIdlong消息 ID
data.newMsgIdlong新消息 ID
data.createTimelong发送时间戳(秒)
data.wcIdstring接收方 ID