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

边栏推荐
猜你喜欢
![[fundamentals of wireless communication-15]: illustrated mobile communication technology and application development-3-overview of digital communication 2G GSM, CDMA, 3G wdcma/cdma200/td-scdma, 4G LTE](/img/22/1efa444220131359b06005f597c9db.png)
[fundamentals of wireless communication-15]: illustrated mobile communication technology and application development-3-overview of digital communication 2G GSM, CDMA, 3G wdcma/cdma200/td-scdma, 4G LTE
![Pytorch —— 基础指北_贰 高中生都能看懂的[反向传播和梯度下降]](/img/6e/279dbb7a8d7a5ecd240de464c5b8b2.png)
Pytorch —— 基础指北_贰 高中生都能看懂的[反向传播和梯度下降]

The latest wechat iPad protocol code obtains official account authorization, etc

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

Analysis on user behavior loss of data exploration e-commerce platform

SWT / anr problem - binder stuck

(翻译)使用眉状文本提高标题点击率

With one-stop insight into industry hot spots, the new function "traffic market" of feigua data station B is launched!

Selenium classic interview question - multi window switching solution

7-2 punch in reward DP for puzzle a
随机推荐
With one-stop insight into industry hot spots, the new function "traffic market" of feigua data station B is launched!
[graduation season · advanced technology Er] - summary from graduation to work
聚焦绿色低碳,数据中心散热进入“智能冷却”新时代
Fix names in the table (first character uppercase, other lowercase)
SWT/ANR问题--AMS/WMS
SWT / anr problem - storagemanagerservice stuck
(translation) reasons why real-time inline verification is easier for users to make mistakes
十大券商有哪些?另外想问,现在在线开户安全么?
Fast understanding of forward proxy and reverse proxy
Analysis on user behavior loss of data exploration e-commerce platform
SWT / anr issues - ams/wms
零基础自学SQL课程 | 窗口函数
QML控件类型:ToolTip
FL studio20.9 fruit software advanced Chinese edition electronic music arrangement
electron之坑addon
(总结一)Halcon基础之寻找目标特征+转正
Mathematical knowledge: 01 sequence satisfying conditions - find combinatorial number
Mathematical knowledge: finding combinatorial number III - finding combinatorial number
数学知识:满足条件的01序列—求组合数
Check the disk usage of MySQL database