PHP WeChat public development notes (5) and php public development notes

Source: Internet
Author: User

PHP public development notes (5) and php public development notes
PHP public development notes series Date: 2014.9.3
Today, I completed the authentication function and improved the search function. In fact, the main thing is to organize the entire code structure. It can be said that it is a modular design.
Modular Design of our public account.Because our previously mentioned functional requirements include: 1. Menu-query function. Considering the extended functions in the future, I want to implement these modules: menu module (in this way, we need to add new menu functions in the future, which can be operated directly in this module, in this way, modification and maintenance are also simple, and there will be no conflicts between developers when there may be division of labor and collaboration in the future); 2. The database module (here it is mainly responsible for database-related work, such as adding, modifying, and querying); these are two functional requirements. Later, I thought about it. The public account is not only used for queries, so I have the following ideas: 3. What do I need to interact with in some cases, therefore, I use the "menu" command as the menu module entry, that is, the "menu" is sent to the menu module of the service number, and then the "query" command is sent, the specific query function is displayed. The menu module is exited when "exit" is sent. 4. After we exit the menu module, a module called keyword capture will be used to respond to user operations and capture specific user commands to interact with users.
5. Some operations, such as parsing the address information in the database, keyword reply tips and other general functions, should be encapsulated into an operation module.
Based on the above considerations and ideas, the directory structure of our public code is as follows:
Index. php as the entry file (as I mentioned earlier, it seems that this index. php file must be included in SAE ..); PSAWeChat. php is equivalent to the previous index. php file. The remaining folders are the directories of the modules I mentioned.

Let's talk about the various pitfalls we encountered today: 1. I use the PHP code written in the Sublime editor, and there is no error prompt (I don't know ), therefore, many syntax errors can only be detected after being uploaded to SAES by sending messages (Of course, this also means that I am very careless). It is often: either the function name is wrong, either the function parameter name is wrong, or the statement ends with a semicolon, or the variable is preceded by a $ symbol... A lot of such errors; 2. Database: During account information Authentication, I forgot to connect to the database first because the authentication was performed before I searched for the function. Then, when I perform authentication, because I want to find information in the database, but I am not connected to the database, I keep searching for errors... After a long time, this also exposes my inattentive problem; 3. Abuse of require/include/require_once/include_once. In PHP, it seems that the include and require files cannot be repeated, so there are require_once and include_once files. At that time, my understanding of the non-Repeated inclusion was that the same file could not be contained repeatedly (the function was always included multiple times). Later I realized that this was not the meaning. My current solution is to use the functions in tools. I only use the index. include in php, and then use require_once to operate functions in the module, because I may call functions between modules. If include is used, it is not guaranteed that the inclusion relationship can be handled properly.
Php development Public Code text how to wrap

I also used php to develop public numbers. \ n is used. You should enclose the text in double quotation marks instead of single quotation marks.
Example: $ msg = "XXXXXXXX: \ n XXXXXXXXXXXX \ n XXXXXX ";

How can php integrate the two functions of public platform development?

In fact, you only need to set a priority or set a keyword.
For example, when a user sends a message that contains the weather, "Shanghai weather" will include the weather class, and then tianqi () will do. When there is a translation, such as "" translation of the micro-hair network ", then include the translation class, and then fanyi.
You can use Baidu micro-hair's function to determine the weather, news, translation, books, navigation, and so on by using keywords.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.