search
HomeWeChat AppletMini Program DevelopmentWeChat applet template message push at regular intervals (pictures and texts)

The content of this article is about the regular push of WeChat applet template messages (pictures and texts). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

The module for creating push API interfaces has recently been updated, so if you want to create a function that regularly pushes WeChat applet template messages, you only need three simple steps!

1. Add application

First enter the vPush developer management console: https://dev.vpush.cloud
Then click Add application, according to the configuration Just add it.

WeChat applet template message push at regular intervals (pictures and texts)

#2. Create API

Then select the template message, click the [Create API] button, and perform simple settings.
Generally, default data is not needed because we can pass data override when requesting the push interface.
So we just set the keywords to be amplified:

WeChat applet template message push at regular intervals (pictures and texts)
Then click the create button to complete the creation.

3. Call the API interface

After creating the interface, you can see the interface information and code examples below:

WeChat applet template message push at regular intervals (pictures and texts)

So let’s start creating our own push script!

Taking a ONE applet as an example, we set it to obtain the day's graphic and text data at 9:10 every morning, then call the push API interface to create a push task, and finally push it to all users.

I wrote a simple script using the superagent module of nodejs:

/**
 * 一ONE小程序推送模块
 * 每天早上09:10获取更新,然后推送
 * https://github.com/safe-dog/one
 * https://vpush.cloud
 */var request = require('superagent');
 // 获取新数据request
  .post('https://api.hibai.cn/api/index/index')
  .send({
      'TransCode': '030112',    
      'OpenId': '123456789',    
      'Body': ''
  })
  .then(res => {    var { Body } = res.body;
    console.log('bodyL', Body)    
    // 获取第一条数据
    var _data = Body[0];    
    // 解析数据
    var data = {
      id: _data.id,
      title: _data.vol,
      img_url: _data.img_url,
      picture_author: _data.img_kind + ' | ' + _data.img_author,
      date: _data.date.split(' ')[0].replace(/-/g, ' / '),
      content: _data.word,
      text_authors: _data.word_from
    };    
    // 添加到任务
    request
      .post('https://vpush2.safedog.cc/api/functions/PUSH_API')
      .set({        
      'X-Parse-Application-Id': 'vpush2_safedog_cc',
      'Content-Type': 'application/json'
      })
      .send({
              "id": "API接口的ID",        
              "secret": "API接口的密钥",        
              "path": "pages/detail/index?id=" + data.id,        
              "data": [
          data.title,
          data.date,
          data.content
        ]
      })
      .end((err, res) => {
        console.log('[*] push result:', err, res)
      });
  })

The code is very simple! I directly joined the crontab list:

10  09  * * * /opt/node/bin/node /root/vpush/post_one.js

Okay, the script will be automatically executed at 09:10 every morning, and then the message will be automatically pushed to us!

Related recommendations:

WeChat template message calling

How to implement timely push messages on Weibo

Can the WeChat service account proactively push messages?

The above is the detailed content of WeChat applet template message push at regular intervals (pictures and texts). For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software