微信公众号开发之新增永久其他(图片、声音、视频)素材(九)
<p><span style="font-family: 黑体">对于常用的素材,开发者可通过本接口上传到微信服务器,永久使用。新增的永久素材也可以在公众平台官网素材管理模块中查询管理。</span></p><p><span style="font-family: 黑体">请注意:</span></p>
<p><span style="font-family: 黑体">1、<strong>最近更新:永久图片素材新增后,将带有URL返回给开发者,开发者可以在腾讯系域名内使用(腾讯系域名外使用,图片将被屏蔽)。</strong></span></p>
<p><span style="font-family: 黑体">2、公众号的素材库保存总数量有上限:图文消息素材、图片素材上限为100000,其他类型为1000。</span></p>
<p><span style="font-family: 黑体">3、素材的格式大小等要求与公众平台官网一致:</span></p>
<p><span style="font-family: 黑体">图片(image): 2M,支持bmp/png/jpeg/jpg/gif格式</span></p>
<p><span style="font-family: 黑体">语音(voice):2M,播放长度不超过60s,mp3/wma/wav/amr格式</span></p>
<p><span style="font-family: 黑体">视频(video):10MB,支持MP4格式</span></p>
<p><span style="font-family: 黑体">缩略图(thumb):64KB,支持JPG格式</span></p>
<p><span style="font-family: 黑体">4、图文消息的具体内容中,微信后台将过滤外部的图片链接,图片url需通过"上传图文消息内的图片获取URL"接口上传图片获取。</span></p>
<p><span style="font-family: 黑体">5、"上传图文消息内的图片获取URL"接口所上传的图片,不占用公众号的素材库中图片数量的100000个的限制,图片仅支持jpg/png格式,大小必须在1MB以下。</span></p>
<p><span style="font-family: 黑体">6、图文消息支持正文中插入自己帐号和其他公众号已群发文章链接的能力。</span></p>
<h3><span style="font-family: 黑体"><strong>一、新增其他类型永久素材</strong></span></h3>
<p><span style="font-family: 黑体"><strong>接口调用请求说明</strong></span></p>
<p><span style="font-family: 黑体">通过POST表单来调用接口,表单id为media,包含需要上传的素材内容,有filename、filelength、content-type等信息。请注意:图片素材将进入公众平台官网素材管理模块中的默认分组。</span></p>
<p><span style="font-family: 黑体">http请求方式: POST,需使用https https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=ACCESS_TOKEN&type=TYPE 调用示例(使用curl命令,用FORM表单方式新增一个其他类型的永久素材,curl命令的使用请自行查阅资料)</span></p>
<p><span style="font-family: 黑体"><strong>参数说明</strong></span></p>
<table class=" cke_show_border">
<thead>
<tr><th><span style="font-family: 黑体">参数</span></th><th><span style="font-family: 黑体">是否必须</span></th><th><span style="font-family: 黑体">说明</span></th></tr>
</thead>
<tbody>
<tr>
<td><span style="font-family: 黑体">access_token</span></td>
<td><span style="font-family: 黑体">是</span></td>
<td><span style="font-family: 黑体">调用接口凭证</span></td>
</tr>
<tr>
<td><span style="font-family: 黑体">type</span></td>
<td><span style="font-family: 黑体">是</span></td>
<td><span style="font-family: 黑体">媒体文件类型,分别有图片(image)、语音(voice)、视频(video)和缩略图(thumb)</span></td>
</tr>
<tr>
<td><span style="font-family: 黑体">media</span></td>
<td><span style="font-family: 黑体">是</span></td>
<td><span style="font-family: 黑体">form-data中媒体文件标识,有filename、filelength、content-type等信息</span></td>
</tr>
</tbody>
</table>
<p><span style="font-family: 黑体">新增永久视频素材需特别注意</span></p>
<p><span style="font-family: 黑体">在上传视频素材时需要POST另一个表单,id为description,包含素材的描述信息,内容格式为JSON,格式如下: </span></p>
<div class="cke_widget_wrapper cke_widget_block cke_widget_codeSnippet cke_widget_wrapper_has cke_widget_selected" data-cke-widget-wrapper="1" data-cke-filter="off" data-cke-display-name="代码段" data-cke-widget-id="18">
<pre class="has cke_widget_element" data-cke-widget-data="{&quot;code&quot;:&quot;{\n \&quot;title\&quot;:VIDEO_TITLE,\n \&quot;introduction\&quot;:INTRODUCTION\n}&quot;,&quot;classes&quot;:{&quot;has&quot;:1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="codeSnippet"><span style="font-family: 黑体"><code class="hljs">{
"title":VIDEO_TITLE,
"introduction":INTRODUCTION
}</code></span></pre>
<span class="cke_reset cke_widget_drag_handler_container" style="font-family: 黑体"><img src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw=="></span></div>
<p><span style="font-family: 黑体">新建一个MaterialUtil在其中新增一个addMaterialFilePath方法用作上传永久素材,包括四个参数</span></p>
<p><span class="cke_widget_wrapper cke_widget_inline cke_widget_image cke_image_nocaption cke_widget_selected" style="font-family: 黑体" data-cke-widget-wrapper="1" data-cke-filter="off" data-cke-display-name="图像" data-cke-widget-id="17"><img class="has cke_widget_element lazyload" alt="" width="1200" height="635" src="https://img-blog.csdnimg.cn/20200109144029210.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70" data-cke-widget-data="{&quot;hasCaption&quot;:false,&quot;src&quot;:&quot;https://img-blog.csdnimg.cn/20200109144029210.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70&quot;,&quot;alt&quot;:&quot;&quot;,&quot;width&quot;:&quot;1200&quot;,&quot;height&quot;:&quot;635&quot;,&quot;lock&quot;:true,&quot;align&quot;:&quot;none&quot;,&quot;classes&quot;:{&quot;has&quot;:1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="image" data-src="https://img-blog.csdnimg.cn/20200109144029210.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70"><span class="cke_reset cke_widget_drag_handler_container"><img class="cke_reset cke_widget_drag_handler lazyload" title="点击并拖拽以移动" alt="" width="15" height="15" data-cke-widget-drag-handler="1" data-src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw=="><span class="cke_image_resizer" title="点击并拖拽以改变尺寸"></span></span></span></p>
<div class="cke_widget_wrapper cke_widget_block cke_widget_codeSnippet cke_widget_wrapper_has cke_widget_selected" data-cke-widget-wrapper="1" data-cke-filter="off" data-cke-display-name="代码段" data-cke-widget-id="16">
<pre class="has cke_widget_element" data-cke-widget-data="{&quot;code&quot;:&quot;/**\n * 添加永久素菜\n * 新增永久视频素材需特别注意,在上传视频素材时需要POST另一个表单,包含素材的描述信息,内容格式为JSON\n */\n public String addMaterialFilePath(String filePath, String type,\n String title, String introduction) {\n\n String accessToken = accessTokenUtil.getAccessToken();\n if (accessToken != null) {\n String url = URIConstant.ADD_MATERIAL_URL.replace(\&quot;ACCESS_TOKEN\&quot;, accessToken)\n .replace(\&quot;TYPE\&quot;, type);\n log.info(\&quot;ADD_MATERIAL_URL:{}\&quot;,url);\n\n //设置请求体,注意是LinkedMultiValueMap\n MultiValueMap&lt;String, Object&gt; data = new LinkedMultiValueMap&lt;&gt;();\n if(\&quot;vedio\&quot;.equalsIgnoreCase(type)){\n if(!StringUtils.isEmpty(title) &amp;&amp; !StringUtils.isEmpty(introduction)){\n data.add(\&quot;title\&quot;, title);\n data.add(\&quot;introduction\&quot;, introduction);\n }\n }\n\n //设置上传文件\n FileSystemResource fileSystemResource = new FileSystemResource(filePath);\n data.add(\&quot;media\&quot;, fileSystemResource);\n\n //上传文件,设置请求头\n HttpHeaders httpHeaders = new HttpHeaders();\n httpHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);\n httpHeaders.setContentLength(fileSystemResource.getFile().length());\n\n HttpEntity&lt;MultiValueMap&lt;String, Object&gt;&gt; requestEntity = new HttpEntity&lt;MultiValueMap&lt;String, Object&gt;&gt;(data,\n httpHeaders);\n try{\n //这里RestTemplate请求返回的字符串直接转换成JSONObject会报异常,后续深入找一下原因\n String resultString = restTemplate.postForObject(url, requestEntity, String.class);\n log.info(\&quot;上传返回的信息是:{}\&quot;,resultString);\n return resultString;\n }catch (Exception e){\n log.error(e.getMessage());\n }\n }\n return null;\n\n }&quot;,&quot;classes&quot;:{&quot;has&quot;:1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="codeSnippet"><span style="font-family: 黑体"><code class="hljs">/**
* 添加永久素菜
* 新增永久视频素材需特别注意,在上传视频素材时需要POST另一个表单,包含素材的描述信息,内容格式为JSON
*/
public String addMaterialFilePath(String filePath, String type,
String title, String introduction) {
String accessToken = accessTokenUtil.getAccessToken();
if (accessToken != null) {
String url = URIConstant.ADD_MATERIAL_URL.replace("ACCESS_TOKEN", accessToken)
.replace("TYPE", type);
log.info("ADD_MATERIAL_URL:{}",url);
//设置请求体,注意是LinkedMultiValueMap
MultiValueMap<String, Object> data = new LinkedMultiValueMap<>();
if("vedio".equalsIgnoreCase(type)){
if(!StringUtils.isEmpty(title) && !StringUtils.isEmpty(introduction)){
data.add("title", title);
data.add("introduction", introduction);
}
}
//设置上传文件
FileSystemResource fileSystemResource = new FileSystemResource(filePath);
data.add("media", fileSystemResource);
//上传文件,设置请求头
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
httpHeaders.setContentLength(fileSystemResource.getFile().length());
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<MultiValueMap<String, Object>>(data,
httpHeaders);
try{
//这里RestTemplate请求返回的字符串直接转换成JSONObject会报异常,后续深入找一下原因
String resultString = restTemplate.postForObject(url, requestEntity, String.class);
log.info("上传返回的信息是:{}",resultString);
return resultString;
}catch (Exception e){
log.error(e.getMessage());
}
}
return null;
}</code></span></pre>
<span class="cke_reset cke_widget_drag_handler_container" style="font-family: 黑体"><img class="cke_reset cke_widget_drag_handler lazyload" title="点击并拖拽以移动" alt="" width="15" height="15" data-cke-widget-drag-handler="1" data-src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw=="></span></div>
<p><span style="font-family: 黑体"> </span></p>
<p><span style="font-family: 黑体">我们编写一个Controller,在里面写一个方法用在swagger里测试一下</span></p>
<p><span class="cke_widget_wrapper cke_widget_inline cke_widget_image cke_image_nocaption cke_widget_selected" style="font-family: 黑体" data-cke-widget-wrapper="1" data-cke-filter="off" data-cke-display-name="图像" data-cke-widget-id="15"><img class="has cke_widget_element lazyload" alt="" width="1200" height="766" src="https://img-blog.csdnimg.cn/20200109144508671.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70" data-cke-widget-data="{&quot;hasCaption&quot;:false,&quot;src&quot;:&quot;https://img-blog.csdnimg.cn/20200109144508671.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70&quot;,&quot;alt&quot;:&quot;&quot;,&quot;width&quot;:&quot;1200&quot;,&quot;height&quot;:&quot;766&quot;,&quot;lock&quot;:true,&quot;align&quot;:&quot;none&quot;,&quot;classes&quot;:{&quot;has&quot;:1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="image" data-src="https://img-blog.csdnimg.cn/20200109144508671.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70"><span class="cke_reset cke_widget_drag_handler_container"><img class="cke_reset cke_widget_drag_handler lazyload" title="点击并拖拽以移动" alt="" width="15" height="15" data-cke-widget-drag-handler="1" data-src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw=="><span class="cke_image_resizer" title="点击并拖拽以改变尺寸"></span></span></span></p>
<div class="cke_widget_wrapper cke_widget_block cke_widget_codeSnippet cke_widget_wrapper_has cke_widget_selected" data-cke-widget-wrapper="1" data-cke-filter="off" data-cke-display-name="代码段" data-cke-widget-id="14">
<pre class="has cke_widget_element" data-cke-widget-data="{&quot;code&quot;:&quot; /**\n * 添加永久素材列表\n */\n @ApiOperation(value = \&quot;添加永久素材FilePath\&quot;)\n @RequestMapping(value = \&quot;/addMaterialFilePath\&quot;, method = RequestMethod.POST)\n @ApiImplicitParams({\n @ApiImplicitParam(name=\&quot;filePath\&quot;,value=\&quot;文件路径\&quot;, paramType=\&quot;query\&quot;,dataType=\&quot;String\&quot;),\n @ApiImplicitParam(name=\&quot;title\&quot;,value=\&quot;视频素材的标题\&quot;, paramType=\&quot;query\&quot;,dataType=\&quot;String\&quot;),\n @ApiImplicitParam(name=\&quot;introduction\&quot;,value=\&quot;视频素材的描述\&quot;, paramType=\&quot;query\&quot;,dataType=\&quot;String\&quot;),\n @ApiImplicitParam(name=\&quot;type\&quot;,value=\&quot;素材的类型,图片(image)、视频(video)、语音 (voice)、图文(news)\&quot;, paramType=\&quot;query\&quot;,dataType=\&quot;String\&quot;)\n })\n public Object addMaterialFilePath(String filePath, String type,\n String title, String introduction) {\n\n String tempString = materialUtil.addMaterialFilePath(filePath, type, title, introduction);\n return tempString;\n\n }&quot;,&quot;classes&quot;:{&quot;has&quot;:1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="codeSnippet"><span style="font-family: 黑体"><code class="hljs"> /**
* 添加永久素材列表
*/
@ApiOperation(value = "添加永久素材FilePath")
@RequestMapping(value = "/addMaterialFilePath", method = RequestMethod.POST)
@ApiImplicitParams({
@ApiImplicitParam(name="filePath",value="文件路径", paramType="query",dataType="String"),
@ApiImplicitParam(name="title",value="视频素材的标题", paramType="query",dataType="String"),
@ApiImplicitParam(name="introduction",value="视频素材的描述", paramType="query",dataType="String"),
@ApiImplicitParam(name="type",value="素材的类型,图片(image)、视频(video)、语音 (voice)、图文(news)", paramType="query",dataType="String")
})
public Object addMaterialFilePath(String filePath, String type,
String title, String introduction) {
String tempString = materialUtil.addMaterialFilePath(filePath, type, title, introduction);
return tempString;
}</code></span></pre>
<span class="cke_reset cke_widget_drag_handler_container" style="font-family: 黑体"><img class="cke_reset cke_widget_drag_handler lazyload" title="点击并拖拽以移动" alt="" width="15" height="15" data-cke-widget-drag-handler="1" data-src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw=="></span></div>
<p><span style="font-family: 黑体">在swagger中提交一个图片,测试一下</span></p>
<p><span class="cke_widget_wrapper cke_widget_inline cke_widget_image cke_image_nocaption cke_widget_selected" style="font-family: 黑体" data-cke-widget-wrapper="1" data-cke-filter="off" data-cke-display-name="图像" data-cke-widget-id="13"><img class="has cke_widget_element lazyload" alt="" width="1200" height="923" src="https://img-blog.csdnimg.cn/20200109144821814.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70" data-cke-widget-data="{&quot;hasCaption&quot;:false,&quot;src&quot;:&quot;https://img-blog.csdnimg.cn/20200109144821814.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70&quot;,&quot;alt&quot;:&quot;&quot;,&quot;width&quot;:&quot;1200&quot;,&quot;height&quot;:&quot;923&quot;,&quot;lock&quot;:true,&quot;align&quot;:&quot;none&quot;,&quot;classes&quot;:{&quot;has&quot;:1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="image" data-src="https://img-blog.csdnimg.cn/20200109144821814.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70"><span class="cke_reset cke_widget_drag_handler_container"><img class="cke_reset cke_widget_drag_handler lazyload" title="点击并拖拽以移动" alt="" width="15" height="15" data-cke-widget-drag-handler="1" data-src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw=="><span class="cke_image_resizer" title="点击并拖拽以改变尺寸"></span></span></span></p>
<p><span style="font-family: 黑体"> 可以看到,我们成功获取到了上传素材文件的media_id</span></p>
<p><span class="cke_widget_wrapper cke_widget_inline cke_widget_image cke_image_nocaption cke_widget_selected" style="font-family: 黑体" data-cke-widget-wrapper="1" data-cke-filter="off" data-cke-display-name="图像" data-cke-widget-id="12"><img class="has cke_widget_element lazyload" alt="" width="1200" height="635" src="https://img-blog.csdnimg.cn/20200109144905833.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70" data-cke-widget-data="{&quot;hasCaption&quot;:false,&quot;src&quot;:&quot;https://img-blog.csdnimg.cn/20200109144905833.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70&quot;,&quot;alt&quot;:&quot;&quot;,&quot;width&quot;:&quot;1200&quot;,&quot;height&quot;:&quot;635&quot;,&quot;lock&quot;:true,&quot;align&quot;:&quot;none&quot;,&quot;classes&quot;:{&quot;has&quot;:1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="image" data-src="https://img-blog.csdnimg.cn/20200109144905833.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70"><span class="cke_reset cke_widget_drag_handler_container"><img class="cke_reset cke_widget_drag_handler lazyload" title="点击并拖拽以移动" alt="" width="15" height="15" data-cke-widget-drag-handler="1" data-src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw=="><span class="cke_image_resizer" title="点击并拖拽以改变尺寸"></span></span></span></p>
<h3><span style="font-family: 黑体">二、获取(下载) 永久素材</span></h3>
<p><span style="font-family: 黑体">再写一个获取(下载)永久素材的方法downloadMaterialImage</span></p>
<p><span class="cke_widget_wrapper cke_widget_inline cke_widget_image cke_image_nocaption cke_widget_selected" style="font-family: 黑体" data-cke-widget-wrapper="1" data-cke-filter="off" data-cke-display-name="图像" data-cke-widget-id="11"><img class="has cke_widget_element lazyload" alt="" width="1200" height="724" src="https://img-blog.csdnimg.cn/20200109151123712.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70" data-cke-widget-data="{&quot;hasCaption&quot;:false,&quot;src&quot;:&quot;https://img-blog.csdnimg.cn/20200109151123712.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70&quot;,&quot;alt&quot;:&quot;&quot;,&quot;width&quot;:&quot;1200&quot;,&quot;height&quot;:&quot;724&quot;,&quot;lock&quot;:true,&quot;align&quot;:&quot;none&quot;,&quot;classes&quot;:{&quot;has&quot;:1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="image" data-src="https://img-blog.csdnimg.cn/20200109151123712.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70"><span class="cke_reset cke_widget_drag_handler_container"><img class="cke_reset cke_widget_drag_handler lazyload" title="点击并拖拽以移动" alt="" width="15" height="15" data-cke-widget-drag-handler="1" data-src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw=="><span class="cke_image_resizer" title="点击并拖拽以改变尺寸"></span></span></span></p>
<div class="cke_widget_wrapper cke_widget_block cke_widget_codeSnippet cke_widget_wrapper_has cke_widget_selected" data-cke-widget-wrapper="1" data-cke-filter="off" data-cke-display-name="代码段" data-cke-widget-id="10">
<pre class="has cke_widget_element" data-cke-widget-data="{&quot;code&quot;:&quot;/**\n * 根据mediaId获取永久素菜\n */\n public ResponseEntity&lt;byte[]&gt; downloadMaterialImage(String mediaId){\n\n String accessToken = accessTokenUtil.getAccessToken();\n if(accessToken != null) {\n String url = URIConstant.GET_MATERIAL_URL.replace(\&quot;ACCESS_TOKEN\&quot;, accessToken);\n log.info(\&quot;GET_MATERIAL_URL:{}\&quot;, url);\n\n String fileName = mediaId+ \&quot;.jpg\&quot;;\n JSONObject data = new JSONObject();\n data.put(\&quot;media_id\&quot;, mediaId);\n\n HttpHeaders headers = new HttpHeaders();\n headers.setContentType(MediaType.MULTIPART_FORM_DATA);\n\n try {\n fileName = new String(fileName.getBytes(\&quot;GBK\&quot;), \&quot;ISO-8859-1\&quot;);\n } catch (UnsupportedEncodingException e) {\n e.printStackTrace();\n }\n headers.setContentDispositionFormData(\&quot;attachment\&quot;, fileName);// 文件名称\n ResponseEntity&lt;byte[]&gt; responseEntity = restTemplate.postForEntity(url, data, byte[].class);\n return responseEntity;\n }\n return null;\n }&quot;,&quot;classes&quot;:{&quot;has&quot;:1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="codeSnippet"><span style="font-family: 黑体"><code class="hljs">/**
* 根据mediaId获取永久素菜
*/
public ResponseEntity<byte[]> downloadMaterialImage(String mediaId){
String accessToken = accessTokenUtil.getAccessToken();
if(accessToken != null) {
String url = URIConstant.GET_MATERIAL_URL.replace("ACCESS_TOKEN", accessToken);
log.info("GET_MATERIAL_URL:{}", url);
String fileName = mediaId+ ".jpg";
JSONObject data = new JSONObject();
data.put("media_id", mediaId);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
try {
fileName = new String(fileName.getBytes("GBK"), "ISO-8859-1");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
headers.setContentDispositionFormData("attachment", fileName);// 文件名称
ResponseEntity<byte[]> responseEntity = restTemplate.postForEntity(url, data, byte[].class);
return responseEntity;
}
return null;
}</code></span></pre>
<span class="cke_reset cke_widget_drag_handler_container" style="font-family: 黑体"><img class="cke_reset cke_widget_drag_handler lazyload" title="点击并拖拽以移动" alt="" width="15" height="15" data-cke-widget-drag-handler="1" data-src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw=="></span></div>
<p><span style="font-family: 黑体"> </span></p>
<p><span style="font-family: 黑体">我们在swagger里再写一个获取(下载)永久素材的方法</span></p>
<p><span class="cke_widget_wrapper cke_widget_inline cke_widget_image cke_image_nocaption cke_widget_selected" style="font-family: 黑体" data-cke-widget-wrapper="1" data-cke-filter="off" data-cke-display-name="图像" data-cke-widget-id="9"><img class="has cke_widget_element lazyload" alt="" width="1200" height="512" src="https://img-blog.csdnimg.cn/20200109150237123.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70" data-cke-widget-data="{&quot;hasCaption&quot;:false,&quot;src&quot;:&quot;https://img-blog.csdnimg.cn/20200109150237123.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70&quot;,&quot;alt&quot;:&quot;&quot;,&quot;width&quot;:&quot;1200&quot;,&quot;height&quot;:&quot;512&quot;,&quot;lock&quot;:true,&quot;align&quot;:&quot;none&quot;,&quot;classes&quot;:{&quot;has&quot;:1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="image" data-src="https://img-blog.csdnimg.cn/20200109150237123.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70"><span class="cke_reset cke_widget_drag_handler_container"><img class="cke_reset cke_widget_drag_handler lazyload" title="点击并拖拽以移动" alt="" width="15" height="15" data-cke-widget-drag-handler="1" data-src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw=="><span class="cke_image_resizer" title="点击并拖拽以改变尺寸"></span></span></span></p>
<p><span style="font-family: 黑体">在swagger中测试我们的获取(下载)永久素材</span></p>
<p><span class="cke_widget_wrapper cke_widget_inline cke_widget_image cke_image_nocaption cke_widget_selected" style="font-family: 黑体" data-cke-widget-wrapper="1" data-cke-filter="off" data-cke-display-name="图像" data-cke-widget-id="8"><img class="has cke_widget_element lazyload" alt="" width="1200" height="813" src="https://img-blog.csdnimg.cn/20200109151414885.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70" data-cke-widget-data="{&quot;hasCaption&quot;:false,&quot;src&quot;:&quot;https://img-blog.csdnimg.cn/20200109151414885.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70&quot;,&quot;alt&quot;:&quot;&quot;,&quot;width&quot;:&quot;1200&quot;,&quot;height&quot;:&quot;813&quot;,&quot;lock&quot;:true,&quot;align&quot;:&quot;none&quot;,&quot;classes&quot;:{&quot;has&quot;:1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="image" data-src="https://img-blog.csdnimg.cn/20200109151414885.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70"><span class="cke_reset cke_widget_drag_handler_container"><img class="cke_reset cke_widget_drag_handler lazyload" title="点击并拖拽以移动" alt="" width="15" height="15" data-cke-widget-drag-handler="1" data-src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw=="><span class="cke_image_resizer" title="点击并拖拽以改变尺寸"></span></span></span></p>
<p><span class="cke_widget_wrapper cke_widget_inline cke_widget_image cke_image_nocaption cke_widget_selected" style="font-family: 黑体" data-cke-widget-wrapper="1" data-cke-filter="off" data-cke-display-name="图像" data-cke-widget-id="7"><img class="has cke_widget_element lazyload" alt="" width="1200" height="719" src="https://img-blog.csdnimg.cn/2020010915145268.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70" data-cke-widget-data="{&quot;hasCaption&quot;:false,&quot;src&quot;:&quot;https://img-blog.csdnimg.cn/2020010915145268.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70&quot;,&quot;alt&quot;:&quot;&quot;,&quot;width&quot;:&quot;1200&quot;,&quot;height&quot;:&quot;719&quot;,&quot;lock&quot;:true,&quot;align&quot;:&quot;none&quot;,&quot;classes&quot;:{&quot;has&quot;:1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="image" data-src="https://img-blog.csdnimg.cn/2020010915145268.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70"><span class="cke_reset cke_widget_drag_handler_container"><img class="cke_reset cke_widget_drag_handler lazyload" title="点击并拖拽以移动" alt="" width="15" height="15" data-cke-widget-drag-handler="1" data-src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw=="><span class="cke_image_resizer" title="点击并拖拽以改变尺寸"></span></span></span></p>
<p><span style="font-family: 黑体">点击Download file下载文件</span></p>
<p><span class="cke_widget_wrapper cke_widget_inline cke_widget_image cke_image_nocaption cke_widget_selected" style="font-family: 黑体" data-cke-widget-wrapper="1" data-cke-filter="off" data-cke-display-name="图像" data-cke-widget-id="6"><img class="has cke_widget_element lazyload" alt="" width="1200" height="784" src="https://img-blog.csdnimg.cn/20200109151627376.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70" data-cke-widget-data="{&quot;hasCaption&quot;:false,&quot;src&quot;:&quot;https://img-blog.csdnimg.cn/20200109151627376.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70&quot;,&quot;alt&quot;:&quot;&quot;,&quot;width&quot;:&quot;1200&quot;,&quot;height&quot;:&quot;784&quot;,&quot;lock&quot;:true,&quot;align&quot;:&quot;none&quot;,&quot;classes&quot;:{&quot;has&quot;:1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="image" data-src="https://img-blog.csdnimg.cn/20200109151627376.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70"><span class="cke_reset cke_widget_drag_handler_container"><img class="cke_reset cke_widget_drag_handler lazyload" title="点击并拖拽以移动" alt="" width="15" height="15" data-cke-widget-drag-handler="1" data-src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw=="><span class="cke_image_resizer" title="点击并拖拽以改变尺寸"></span></span></span></p>
<p><span style="font-family: 黑体">打开这个文件看看,确认是我们上传的永久素材图片</span></p>
<p><span class="cke_widget_wrapper cke_widget_inline cke_widget_image cke_image_nocaption cke_widget_selected" style="font-family: 黑体" data-cke-widget-wrapper="1" data-cke-filter="off" data-cke-display-name="图像" data-cke-widget-id="5"><img class="has cke_widget_element lazyload" alt="" width="1200" height="1009" src="https://img-blog.csdnimg.cn/20200109151712836.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70" data-cke-widget-data="{&quot;hasCaption&quot;:false,&quot;src&quot;:&quot;https://img-blog.csdnimg.cn/20200109151712836.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70&quot;,&quot;alt&quot;:&quot;&quot;,&quot;width&quot;:&quot;1200&quot;,&quot;height&quot;:&quot;1009&quot;,&quot;lock&quot;:true,&quot;align&quot;:&quot;none&quot;,&quot;classes&quot;:{&quot;has&quot;:1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="image" data-src="https://img-blog.csdnimg.cn/20200109151712836.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70"><span class="cke_reset cke_widget_drag_handler_container"><img class="cke_reset cke_widget_drag_handler lazyload" title="点击并拖拽以移动" alt="" width="15" height="15" data-cke-widget-drag-handler="1" data-src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw=="><span class="cke_image_resizer" title="点击并拖拽以改变尺寸"></span></span></span></p>
<p><span style="font-family: 黑体">另外,我们还有几个接口,比如</span></p>
<div class="cke_widget_wrapper cke_widget_block cke_widget_codeSnippet cke_widget_wrapper_has cke_widget_selected" data-cke-widget-wrapper="1" data-cke-filter="off" data-cke-display-name="代码段" data-cke-widget-id="4">
<pre class="cke_widget_element has" data-cke-widget-data="{&quot;lang&quot;:&quot;html&quot;,&quot;code&quot;:&quot;1、getMaterialcount【统计每种永久素材的数量】&quot;,&quot;classes&quot;:[]}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="codeSnippet"><span style="font-family: 黑体"><code class="language-html hljs">1、getMaterialcount【统计每种永久素材的数量】</code></span></pre>
<span class="cke_reset cke_widget_drag_handler_container" style="font-family: 黑体"><img class="cke_reset cke_widget_drag_handler lazyload" title="点击并拖拽以移动" alt="" width="15" height="15" data-cke-widget-drag-handler="1" data-src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw=="></span></div>
<p><span class="cke_widget_wrapper cke_widget_inline cke_widget_image cke_image_nocaption cke_widget_selected" style="font-family: 黑体" data-cke-widget-wrapper="1" data-cke-filter="off" data-cke-display-name="图像" data-cke-widget-id="3"><img class="has cke_widget_element lazyload" alt="" width="1200" height="458" src="https://img-blog.csdnimg.cn/20200109152534140.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70" data-cke-widget-data="{&quot;hasCaption&quot;:false,&quot;src&quot;:&quot;https://img-blog.csdnimg.cn/20200109152534140.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70&quot;,&quot;alt&quot;:&quot;&quot;,&quot;width&quot;:&quot;1200&quot;,&quot;height&quot;:&quot;458&quot;,&quot;lock&quot;:true,&quot;align&quot;:&quot;none&quot;,&quot;classes&quot;:{&quot;has&quot;:1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="image" data-src="https://img-blog.csdnimg.cn/20200109152534140.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70"><span class="cke_reset cke_widget_drag_handler_container"><img class="cke_reset cke_widget_drag_handler lazyload" title="点击并拖拽以移动" alt="" width="15" height="15" data-cke-widget-drag-handler="1" data-src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw=="><span class="cke_image_resizer" title="点击并拖拽以改变尺寸"></span></span></span></p>
<p><span style="font-family: 黑体"> </span></p>
<div class="cke_widget_wrapper cke_widget_block cke_widget_codeSnippet cke_widget_wrapper_has cke_widget_selected" data-cke-widget-wrapper="1" data-cke-filter="off" data-cke-display-name="代码段" data-cke-widget-id="2">
<pre class="cke_widget_element has" data-cke-widget-data="{&quot;lang&quot;:&quot;html&quot;,&quot;code&quot;:&quot;/**\n * 获取素菜数量\n * @return\n */\npublic String getMaterialcount(){\n\n String accessToken = accessTokenUtil.getAccessToken();\n if(accessToken != null){\n String url = URIConstant.GET_MATERIALCOUNT_URL.replace(\&quot;ACCESS_TOKEN\&quot;, accessToken);\n //发起GET请求\n String resultString = restTemplate.getForObject(url, String.class);\n return resultString;\n }\n return null;\n}&quot;,&quot;classes&quot;:[]}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="codeSnippet"><span style="font-family: 黑体"><code class="language-html hljs">/**
* 获取素菜数量
* @return
*/
public String getMaterialcount(){
String accessToken = accessTokenUtil.getAccessToken();
if(accessToken != null){
String url = URIConstant.GET_MATERIALCOUNT_URL.replace("ACCESS_TOKEN", accessToken);
//发起GET请求
String resultString = restTemplate.getForObject(url, String.class);
return resultString;
}
return null;
}</code></span></pre>
<span class="cke_reset cke_widget_drag_handler_container" style="font-family: 黑体"><img class="cke_reset cke_widget_drag_handler lazyload" title="点击并拖拽以移动" alt="" width="15" height="15" data-cke-widget-drag-handler="1" data-src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw=="></span></div>
<p><span style="font-family: 黑体">2、batchgetMaterial(String type, Integer offset, Integer count)【获取素菜列表】</span></p>
<p><span class="cke_widget_wrapper cke_widget_inline cke_widget_image cke_image_nocaption cke_widget_selected" style="font-family: 黑体" data-cke-widget-wrapper="1" data-cke-filter="off" data-cke-display-name="图像" data-cke-widget-id="1"><img class="has cke_widget_element lazyload" alt="" width="1200" height="752" src="https://img-blog.csdnimg.cn/20200109152741728.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70" data-cke-widget-data="{&quot;hasCaption&quot;:false,&quot;src&quot;:&quot;https://img-blog.csdnimg.cn/20200109152741728.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70&quot;,&quot;alt&quot;:&quot;&quot;,&quot;width&quot;:&quot;1200&quot;,&quot;height&quot;:&quot;752&quot;,&quot;lock&quot;:true,&quot;align&quot;:&quot;none&quot;,&quot;classes&quot;:{&quot;has&quot;:1}}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="image" data-src="https://img-blog.csdnimg.cn/20200109152741728.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM1MjEyMjA=,size_16,color_FFFFFF,t_70"><span class="cke_reset cke_widget_drag_handler_container"><img class="cke_reset cke_widget_drag_handler lazyload" title="点击并拖拽以移动" alt="" width="15" height="15" data-cke-widget-drag-handler="1" data-src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw=="><span class="cke_image_resizer" title="点击并拖拽以改变尺寸"></span></span></span></p>
<div class="cke_widget_wrapper cke_widget_block cke_widget_codeSnippet cke_widget_wrapper_has cke_widget_selected" data-cke-widget-wrapper="1" data-cke-filter="off" data-cke-display-name="代码段" data-cke-widget-id="0">
<pre class="cke_widget_element has" data-cke-widget-data="{&quot;lang&quot;:&quot;html&quot;,&quot;code&quot;:&quot;/**\n * 获取素菜列表\n * @return\n */\npublic String batchgetMaterial(String type, Integer offset, Integer count){\n\n String accessToken = accessTokenUtil.getAccessToken();\n if(accessToken != null){\n String url = URIConstant.BATCHGET_MATERIAL_URL.replace(\&quot;ACCESS_TOKEN\&quot;, accessToken);\n log.info(\&quot;BATCHGET_MATERIAL_URL:{}\&quot;,url);\n\n JSONObject jsonObject = new JSONObject();\n //素材的类型,图片(image)、视频(video)、语音 (voice)、图文(news)\n jsonObject.put(\&quot;type\&quot;, type);\n //从全部素材的该偏移位置开始返回,0表示从第一个素材 返回\n jsonObject.put(\&quot;offset\&quot;, offset);\n //返回素材的数量,取值在1到20之间\n jsonObject.put(\&quot;count\&quot;, count);\n\n //发起POST请求\n String resultString = restTemplate.postForObject(url, jsonObject.toJSONString(),String.class);\n return resultString;\n }\n return null;\n}&quot;,&quot;classes&quot;:[]}" data-cke-widget-upcasted="1" data-cke-widget-keep-attr="0" data-widget="codeSnippet"><span style="font-family: 黑体"><code class="language-html hljs">/**
* 获取素菜列表
* @return
*/
public String batchgetMaterial(String type, Integer offset, Integer count){
String accessToken = accessTokenUtil.getAccessToken();
if(accessToken != null){
String url = URIConstant.BATCHGET_MATERIAL_URL.replace("ACCESS_TOKEN", accessToken);
log.info("BATCHGET_MATERIAL_URL:{}",url);
JSONObject jsonObject = new JSONObject();
//素材的类型,图片(image)、视频(video)、语音 (voice)、图文(news)
jsonObject.put("type", type);
//从全部素材的该偏移位置开始返回,0表示从第一个素材 返回
jsonObject.put("offset", offset);
//返回素材的数量,取值在1到20之间
jsonObject.put("count", count);
//发起POST请求
String resultString = restTemplate.postForObject(url, jsonObject.toJSONString(),String.class);
return resultString;
}
return null;
}</code></span></pre>
<span class="cke_reset cke_widget_drag_handler_container" style="font-family: 黑体"><img class="cke_reset cke_widget_drag_handler lazyload" title="点击并拖拽以移动" alt="" width="15" height="15" data-cke-widget-drag-handler="1" data-src="data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw=="></span></div>
<p><span style="font-family: 黑体"> </span></p>
<p><span style="font-family: 黑体">本篇先到这里,我们下回再见!</span></p>
<p> </p>
<h3>如果您觉得此文有帮助,可以小小打赏一下,持续更新更有动力哟!</h3>
<p> </p>
<p><img alt="" width="218" height="274" data-src="https://img2020.cnblogs.com/blog/1501920/202004/1501920-20200402133129576-79870337.png"><img src="https://img2020.cnblogs.com/blog/1501920/202004/1501920-20200402133221455-2112921293.png"></p>
<p> </p><br><br>
来源:https://www.cnblogs.com/xulijun137/p/12213643.html
頁:
[1]