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

Source: Internet
Author: User

PHP public development notes (3) and php public development notes
PHP public development notes series: 2014.9.2
The main task today is to handle the cache information mentioned yesterday. I need to save some messages for secondary judgment.
First, record some PHP syntax knowledge. 1. Connection Syntax of strings in PHP: in lua, the connection between the two strings is very simple, and two strings "aaa"; "bbb"; need to be connected, only two periods are required .. you can: "aaa ".. "bbb"; note that there is a space between the string and the period. If there is no space, an error is returned. In PHP, the connection only requires a period: "aaa ". "bbb"; and do not need to use a space between the string and the period;
2. Get the time and convert it to the date format: Use the date function. Format: date ('Y-m-d H: I: s', time ()); it's quite simple. record it.
Progress of public platform development requirements. Now back to the task left yesterday: using the session cache to record information, we realized the concept of the menu: session usage in php, I am not very clear, so I 've been here for a long time, and I 've finally realized my functional needs. However, I still feel that there are some shortcomings, so I can leave them for later correction. As mentioned yesterday, the menu I want to implement is expected to remember the previous information. That is, the user is reminded to enter the query and enter the query menu. After the user sends "query", the next information should be transferred to the query menu, that is, I need to remember that the user has sent the "query" message. After du Niang spent a long time, he found that he used either the database or session, but he still did not use the database in PHP, then I felt like I would simply handle it and remember that the information should not be used by the database, so I used session. Use Session to meet our needs:
In php, we need to know more about how to use the session. Now we are just simple to use. When reading the materials, some netizens mentioned using the user's username as the unique id, so that the information stored for each user will be inconsistent (because we are sending messages to the server, each user sends a message, which does not affect the use of other users. The code is implemented as follows: session_id ($ postObj-> fromUsername ); // This is the username in the xml data packet sent from the server post. Use this as idsession_start (); // should this be the meaning of enabling session? However, it is not clear where I put these two lines of code. Now I have put this code in the responseMsg function. I don't know if it is like this. The subsequent tests are useful. After the session is enabled, the information is recorded: $ _ SESSION ['menu _ type'] = $ this-> getUserMenu ($ textWord ); // here, getusermenu is a function that is used to obtain the menu type based on user input. The $ _ SESSION variable is used for recording information, which is used as an array ?? After the information is recorded, the information is determined and isset ($ _ SESSION ['menu _ type']) is used. // use isset to determine whether this value is set, so that the user can determine whether a menu is selected and when we do not need to use it, use the following function to destroy this: unset ($ _ SESSION ['menu _ type'];
Make corresponding adjustments in the code to meet our needs. Then, when do I find it insufficient? When should I destroy the menu type selected by the saved user? If you select the "query" menu, we will respond to the user's query behavior. At least we should not destroy the saved menu type during the user query process. I feel that there are three situations for reasonable destruction: the user closes the dialog box (that is, the user exits the chat box with our public account, but the user does not know how to exit on the Internet ); the user does not perform the query operation for a long time (that is, the user does not perform the corresponding query operation after a specified period of time on the premise that the "query" menu is selected, in this case, it is automatically destroyed. The user selects to exit. If the record information is not destroyed, this problem occurs. After the user selects the "query" menu, the user exits chatting with the public account, and then enters the next time, it also saves the user-selected menu information of the record, which is unreasonable.
Aside from the problems mentioned above, at least the functions we need in this step are implemented. Let's fix the problems.
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.