微信小程序> 微信公众号推文,微信小程序中如何打开公众号文章node版

微信公众号推文,微信小程序中如何打开公众号文章node版

浏览量:1102 时间: 来源:qingfouyun
1.技术要求
微信开发经验+小程序开发经验+会一点node
2.思路
在6月份的一次更新,webview组件增加新的能力,webview指向网页的链接。可打开关联的公众号的文章,其它网页需登录配置业务域名。所以我们可以利用微信提供的"https://api.weixin.qq.com/cgi-bin/material/batchget_material“接口获取所有的素材列表,我们可以将这些文章存入数据库,方便使用,在将web-view中的src替换为获取到的素材文章的永久链接,即可
3.源码demo
1.获取微信中的素材列表
//使用了request这个库用于服务端请求
consttoken_url="https://api.weixin.qq.com/cgi-bin/token";
consturl="https://api.weixin.qq.com/cgi-bin/material/batchget_material";
constappid="自己的appid";
constappsecret="自己的APPsecret";
consttype="news";
constoffset="0";
constcount="20";
//获取token
lettoken_info=awaitnewPromise(function(resolve,reject){
request.get(`${token_url}?grant_type=client_credential&appid=${appid}&secret=${appsecret}`,function(error,response,body){
if(!error&&response.statusCode==200){
resolve(body);
}
reject(error);
});
})
token_info=JSON.parse(token_info);
constaccess_token=token_info.access_token;
letdata={
"type":type,
"offset":offset,
"count":count
};
//获取素材列表
constres=awaitnewPromise(function(resolve,reject){
request.post({url:`${url}?access_token=${access_token}`,form:JSON.stringify(data)},function(error,response,body){
console.log("body--",body);
if(!error&&response.statusCode==200){
resolve(body);
}
reject(error);
})
});
console.log("res--",res);
2.小程序端
//src中填入获取到的永久链接
web-viewsrc="http://mp.weixin.qq.com/s?__biz=MzI3MjM1MTUzNA==&mid=100000180&idx=1&sn=069844e709fdbe0aaa4129c97977b335&chksm=6b32a9f55c4520e3c7d9ec18b6e79a02689ea23ae01006ff7dc47677588b8b22a8c1e531661b#rd"/web-view
3.结果

koahub

版权声明

即速应用倡导尊重与保护知识产权。如发现本站文章存在版权问题,烦请提供版权疑问、身份证明、版权证明、联系方式等发邮件至197452366@qq.com ,我们将及时处理。本站文章仅作分享交流用途,作者观点不等同于即速应用观点。用户与作者的任何交易与本站无关,请知悉。

产品经理

手机 : 13312967497

擅长 : 小程序流量变现

扫码领取礼包

热门模板

  • 头条
  • 搜狐
  • 微博
  • 百家
  • 一点资讯
  • 知乎