Home CMS Tutorial WordPress How to add WeChat public account function to WordPress plug-in

How to add WeChat public account function to WordPress plug-in

Sep 05, 2023 am 09:12 AM
WeChat public account wordpress plugin Add functionality

How to add WeChat public account function to WordPress plug-in

How to add WeChat public account function to WordPress plug-in

With the rapid development of mobile Internet, WeChat public account has become one of the important tools for marketing and promotion of many enterprises and individuals. one. For users who use WordPress as a website building platform, how to add the WeChat public account function to their plug-ins has become a common requirement. This article will teach you how to add the WeChat public account function to the WordPress plug-in and provide corresponding code examples.

1. Register a WeChat public account developer account

Before you start, you need to register a WeChat public account developer account. Open the official website of the WeChat public platform (https://mp.weixin.qq.com/), click the registration button, fill in the relevant information according to the guidelines and complete the account registration.

2. Obtain the WeChat public account developer certificate

After successful registration, enter the WeChat public account platform developer center and click "Developer Tools" in the left menu to enter. On the "Official Account Settings" page, find the two important credentials "Developer ID" and "Developer Password".

3. Install WordPress plug-in

Install a plug-in that can use custom code functions on your WordPress website, such as the Custom JavaScript plug-in. After installation, go to the "Settings" menu to find the plug-in and click "New Code Snippet".

4. Add the WeChat public account interface code

On the "New Code Snippet" page, enter the code in Code Example 1. Among them, you need to replace [APPID] with the developer ID of your WeChat official account, and replace [APPSECRET] with the developer password of your WeChat official account.

Code Example 1:

function get_wechat_access_token() {
    $appid = '【APPID】';
    $appsecret = '【APPSECRET】';
    $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$appsecret;
    $response = wp_remote_get( $url );
    $body = wp_remote_retrieve_body( $response );
    $data = json_decode( $body );
    return $data->access_token;
}

function get_wechat_qrcode() {
    $access_token = get_wechat_access_token();
    $url = 'https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token='.$access_token;
    $body = '{
        "action_name": "QR_LIMIT_STR_SCENE",
        "action_info": {
            "scene": {
                "scene_str": "wechat"
            }
        }
    }';
    $response = wp_remote_post( $url, array(
        'body' => $body
    ) );
    $body = wp_remote_retrieve_body( $response );
    $data = json_decode( $body );
    $ticket = $data->ticket;
    $qrcode_url = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket='.urlencode( $ticket );
    return $qrcode_url;
}
Copy after login

The two functions in Code Example 1 are used to obtain the access_token of the WeChat official account and to generate the permanent QR code link of the WeChat official account. You can modify the code according to actual needs.

5. Call the WeChat official account interface

In the page or article where the WeChat official account QR code needs to be displayed, use the following code to call the WeChat official account interface and display the QR code.

Code example two:

<img  src="<?php echo get_wechat_qrcode(); ? alt="How to add WeChat public account function to WordPress plug-in" >" alt="微信公众号二维码">
Copy after login

Insert the above code into the position where you need to display the WeChat official account QR code.

Summary:

Through the code examples provided in this article, you can easily add the WeChat public account function to your WordPress plug-in. Of course, if you have a certain understanding of PHP and WordPress development, you can also expand and optimize the code according to actual needs. I wish you good results in your WordPress plugin development!

The above is the detailed content of How to add WeChat public account function to WordPress plug-in. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Scrapy implements crawling and analysis of WeChat public account articles Scrapy implements crawling and analysis of WeChat public account articles Jun 22, 2023 am 09:41 AM

Scrapy implements article crawling and analysis of WeChat public accounts. WeChat is a popular social media application in recent years, and the public accounts operated in it also play a very important role. As we all know, WeChat public accounts are an ocean of information and knowledge, because each public account can publish articles, graphic messages and other information. This information can be widely used in many fields, such as media reports, academic research, etc. So, this article will introduce how to use the Scrapy framework to crawl and analyze WeChat public account articles. Scr

How to add online payment functionality to WordPress plugin How to add online payment functionality to WordPress plugin Sep 05, 2023 pm 04:19 PM

How to Add Online Payment Function to WordPress Plugin With the rapid development of the e-commerce industry, adding online payment function to the website has become a critical need. For those who use WordPress as a website development platform, there are many ready-made plugins that can help them achieve this goal. This article will introduce how to add online payment functionality to WordPress plug-in and provide code samples for reference. Determine the payment interface Before adding the online payment function, you must first determine the payment interface to use. current city

What are the differences between WeChat official account certification and non-certification? What are the differences between WeChat official account certification and non-certification? Sep 19, 2023 pm 02:15 PM

The difference between WeChat public account authentication and non-authentication lies in the authentication logo, function permissions, push frequency, interface permissions and user trust. Detailed introduction: 1. Certification logo. Certified public accounts will obtain the official certification logo, which is the blue V logo. This logo can increase the credibility and authority of the public account and make it easier for users to identify the real official public account; 2. Function permissions. Certified public accounts have more functions and permissions than uncertified public accounts. For example, certified public accounts can apply to activate the WeChat payment function to achieve online payment and commercial operations, etc.

How to use WordPress plug-in to implement email subscription function How to use WordPress plug-in to implement email subscription function Sep 05, 2023 pm 06:37 PM

How to use WordPress plug-in to implement email subscription function In today’s Internet age, email subscription function has become an indispensable part of website operation. Through the email subscription function, we can push the latest news, activities, offers and other information to users in a timely manner to enhance user stickiness and interactivity. In the WordPress website, we can implement the email subscription function by using plug-ins. The following will introduce how to use the WordPress plug-in to implement the email subscription function. Step 1: Choose the right plugin

How to develop a feature that automatically updates a WordPress plugin How to develop a feature that automatically updates a WordPress plugin Sep 05, 2023 am 10:40 AM

How to Develop an Auto-Updating WordPress Plugin WordPress is a very popular open source content management system (CMS) with a rich plugin market to extend its functionality. To ensure that plugins are always up to date and secure, developers need to implement automatic updates. In this article, we’ll walk you through how to develop an auto-updating WordPress plugin and provide code examples to help you get started quickly. Preparation Before starting development, you need to prepare the following key steps: Create

How to develop a WordPress plugin that automatically generates project progress How to develop a WordPress plugin that automatically generates project progress Sep 05, 2023 am 08:48 AM

How to develop a WordPress plug-in that automatically generates project progress. In the process of project management, it is very important to understand the project progress. For users who use WordPress to build websites, being able to directly view project progress in the WordPress backend will greatly improve work efficiency. Therefore, it is very beneficial to develop a WordPress plugin that automatically generates project progress. This article describes how to develop such a plug-in and provides code examples. Plugin Overview The main functions of this plugin are

How to use WordPress plug-in to implement instant query function How to use WordPress plug-in to implement instant query function Sep 06, 2023 pm 12:39 PM

How to use WordPress plug-ins to achieve instant query function WordPress is a powerful blog and website building platform. Using WordPress plug-ins can further expand the functions of the website. In many cases, users need to perform real-time queries to obtain the latest data. Next, we will introduce how to use WordPress plug-ins to implement instant query functions and provide some code samples for reference. First, we need to choose a suitable WordPress plug-in to achieve instant query

How to avoid Chinese garbled characters in WordPress How to avoid Chinese garbled characters in WordPress Mar 05, 2024 pm 09:36 PM

How to avoid Chinese garbled characters in WordPress requires specific code examples. In the process of using WordPress websites, many users will encounter the problem of Chinese garbled characters. Garbled Chinese characters will cause trouble for users when reading and browsing the website, and may also affect the user experience and search engine optimization of the website. In this article, we will introduce some methods to solve the Chinese garbled problem in WordPress and provide specific code examples. Set the database character set: First, make sure the database character set is set correctly to support the

See all articles