当前位置:网站首页>Small program cloud development -- wechat official account article collection
Small program cloud development -- wechat official account article collection
2022-07-01 02:13:00 【Gods】
Small program cloud development – Wechat official account article collection
I believe many friends have thought about making their own small programs , And suffer from no server and filed domain name 、 Website ssl Certificates, etc , Wechat applet acts as front end There are many back ends, such as Spring Family bucket When the applet can receive the value returned by the back end, it needs to add a legal domain name in the applet ( Domain name filing and https agreement )
Here directly into teaching
There is a special interface in the official account ( There are also special documents ) So how to collect articles of applets to do For my own use ?
First step : obtain access_token
You can see from the documentation that Want to get this access_token The following three parameters are required

among grant_type The value of is client_credential Used to get access_token
appid and secret It can be found in the official account

After completing the above configuration, you can collect articles ,
We can access it manually token perhaps postman etc.

With token Then it is very convenient to collect articles Let's start
From the official documents, we can see that there are many interfaces provided

Take the draft box as a demonstration here Other images 、 Video and other materials are collected in the same way

first token We already have it, and the next step is offset and count 了 The last parameter can be omitted
Get article data
After obtaining the material Print the results

It means that there are three pieces of data in my draft box There are really only three 
Article data processing
We need to get the parameters we need and add them to the database
Be careful ️ The problem here is that if this article has been collected, we will skip , If all the data exists, print The article already exists
Finally, put the data that the database does not have into the database
Here are the test results

If all the data exists

Blog applet : Wanshen resource Inn
Put some code :
/** * Get the article information of official account * @param {*} accessToken */
async function getWechatPosts(accessToken, offset, count) {
let url = `https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=${
accessToken}`
var options = {
method: 'POST',
json: true,
uri: url,
body: {
"type": "news",
"offset": offset,
"count": count
}
}
const result = await rp(options)
let rbody = (typeof result === 'object') ? result : JSON.parse(result);
return rbody;
}
/** * Sync the article's applet code */
async function syncPostQrCode() {
let configData = await getConfigInfo("syncPostQrCode");
if (configData == null) {
console.info(" The corresponding configuration was not obtained ")
return;
}
console.info(configData)
let page = parseInt(configData.value.currentOffset);
let maxCount = parseInt(configData.value.maxSyncCount);
let isContinue = true;
while (isContinue) {
let posts = await db.collection('mini_posts')
.orderBy('timestamp', 'asc')
.skip(page * 10)
.limit(10)
.field({
_id: true,
qrCode: true,
timestamp: true
}).get()
console.info(posts)
if (posts.data.length == 0) {
isContinue = false;
break;
}
for (var index in posts.data) {
if (posts.data[index].qrCode != null) {
continue
}
let scene = 'timestamp=' + posts.data[index].timestamp;
let result = await cloud.openapi.wxacode.getUnlimited({
scene: scene,
page: 'pages/detail/detail'
})
if (result.errCode === 0) {
const upload = await cloud.uploadFile({
cloudPath: posts.data[index]._id + '.png',
fileContent: result.buffer,
})
await db.collection("mini_posts").doc(posts.data[index]._id).update({
data: {
qrCode: upload.fileID
}
});
}
}
if ((page - parseInt(configData.value.currentOffset)) * 10 > maxCount) {
isContinue = false;
}
else {
page++
}
}
let data = {
currentOffset: page - 1, maxSyncCount: 100 }
await db.collection("mini_config").doc(configData._id).update({
data: {
value: data
}
});
}
That's all Please pay more attention to me ~

边栏推荐
- 计算特殊奖金
- SWT/ANR问题--Dump时间过长导致的SWT
- (translation) use eyebrow shaped text to improve Title click through rate
- P6773 [NOI2020] 命运(dp、线段树合并)
- There is no future to be expected. It is just the last fantasy of a migrant worker before he dies
- nacos配置中心使用教程
- Fix names in the table (first character uppercase, other lowercase)
- QT web development - VIDEO - Notes
- Calculate special bonus
- FL studio20.9 fruit software advanced Chinese edition electronic music arrangement
猜你喜欢

如何在智汀中实现智能锁与灯、智能窗帘电机场景联动?

What is project management?

机器学习10-信念贝叶斯分类器

(translation) reasons why real-time inline verification is easier for users to make mistakes

修复表中的名字(首字符大写,其他小写)
2022年最新csdn涨薪技术栈-app自动化测试概述

Ernie-gram, 显式、完备的 n-gram 掩码语言模型,实现了显式的 n-gram 语义单元知识建模。

Rocketqa: cross batch negatives, de noised hard negative sampling and data augmentation

PMP是什么?

CentOS installs multiple versions of PHP and switches
随机推荐
2022年最新csdn涨薪技术栈-app自动化测试概述
Electron pit Addon
MySQL insert \ pre update + judgment condition
Laravel event & subscription
(translation) use eyebrow shaped text to improve Title click through rate
The latest CSDN salary increase technology stack in 2022 overview of APP automated testing
Check the disk usage of MySQL database
Winodws 快速添加开机启动项
Template: globally balanced binary tree
如何学习和阅读代码
CorelDRAW 2022中文精简64位直装版下载
Video tutorial | Chang'an chain launched a series of video tutorial collections (Introduction)
Alphabet rearrange inator 3000 (dictionary tree custom sorting)
What is the difference between port number and process number?
运算符重载的初识
数学知识:满足条件的01序列—求组合数
What are the applications of SMS in enterprises?
手机edge浏览器无法打开三方应用
SWT / anr problem - SWT caused by long execution time of native method
What are the preferential activities for stock account opening? In addition, is it safe to open a mobile account?