Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report