当前位置:网站首页>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 ~

边栏推荐
- 【JS】【掘金】获取关注了里不在关注者里的人
- Int and bit group turn to each other
- SWT/ANR问题--Dump时间过长导致的SWT
- Mathematical knowledge: 01 sequence satisfying conditions - find combinatorial number
- VirtualBox 安装增强功能
- Alphabet-Rearrange-Inator 3000(字典树自定义排序)
- 项目管理是什么?
- The image variables in the Halcon variable window are not displayed, and it is useless to restart the software and the computer
- Mathematical knowledge: finding combinatorial number III - finding combinatorial number
- How does the property send a text message to the owner?
猜你喜欢
随机推荐
AS400 大廠面試
The image variables in the Halcon variable window are not displayed, and it is useless to restart the software and the computer
What is PMP?
Pytorch —— 基礎指北_貳 高中生都能看懂的[反向傳播和梯度下降]
AS400 entretien d'usine
[content of content type request header]
Leetcode(524)——通过删除字母匹配到字典里最长单词
CentOS installs multiple versions of PHP and switches
我的PMP学习考试心得
PMP是什麼?
Template: globally balanced binary tree
URLs and URIs
RocketQA:通过跨批次负采样(cross-batch negatives)、去噪的强负例采样(denoised hard negative sampling)与数据增强(data augment
【毕业季·进击的技术er】--毕业到工作小结
URL和URI
AS400 large factory interview
[graduation season · advanced technology Er] - summary from graduation to work
项目管理是什么?
There is no future to be expected. It is just the last fantasy of a migrant worker before he dies
Leetcode (524) -- match the longest word in the dictionary by deleting letters








