Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the Development of message Interface of Wechat Public platform with PHP

Shulou Source: shulou.com Published: 2022-06-03 07:50:05 11月15日 Update

This article introduces the knowledge of "how to implement the development of message interface between PHP and Wechat public platform". In the operation of practical cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

First, write a good interface program

Upload an interface program file on your server, such as http://www.yourdomain.com/weixin.php:

The copy code is as follows:

2. Configure Wechat public platform reply interface

Set the reply API and enter URL and Token (the http://www.yourdomain.com/weixin.php token specified above must be the same as the Token defined in the above program for url)

Third, verify the interface

Use your personal Wechat to follow your public account, send a message to the account, receive the original message back, that is, the verification is successful.

4. Start customizing responses

Comment out $wechatObj- > valid (); this line, and also remove / / $wechatObj- > responseMsg (); comment on this line.

You can modify the code in the responseMsg function to reply to the user's different content according to the user's message type ('text','image','location') and message content.

The message interface can be used. Why don't you try sending a message?

1. Encapsulated weixin.class.php

As the communication of Wechat public platform uses XML data in a specific format, each acceptance and reply has to do a lot of data processing.

We are considering to do a package on this basis, weixin.class.php, the code is as follows:

The copy code is as follows:

two。 Call weixin.class.php

In the main interface file of your Wechat public platform (such as http://www.yourdomain.com/weixin.php defined earlier), modify the code as follows:

The copy code is as follows:

3. Query code

You also need to format the query results in the database into a specific form.

The copy code is as follows:

This is the end of the content of "how to implement PHP docking Wechat public platform message interface development". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Message code user interface public content platform data query processing array text article program account information format later type development Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information macOS Redmi Docker Shulou Technology