PHP WeChat Public Development Notes (8)
PHP WeChat public development notes series
Date: 2014.9.6
The main things to do today are: establishing a keyword database, timeout mechanism, optimized keyword matching, and expression information database
Note: PHP does not return after echo? Will it continue to be implemented? ?
2014.9.11 Organizing notes:
When I wrote this note, I was working on a feature, so I simply jotted down a few notes about my work at that time. Now that the feature is almost developed, I’m going to sort out the previous notes. At that time, I simply recorded the above sentences.
It's Saturday, so I'm resting in the rented house since I don't have to work overtime. Since the Mid-Autumn Festival is coming up, my sister in Shenzhen will come to my place to celebrate the festival, so I don’t have much time to write functions today. I get up early in the morning and go for a run, and then I start working on it when I come back (thinking about it now, maybe I will become a workaholic in the future). The function we did today was to create a keyword data table and expression information data table in the database, add a timeout mechanism, and optimize keyword matching.
1. Keyword data table
The information stored in this data table is mainly some keywords that I used when doing keyword filtering and capturing before. Because I want to facilitate management, I thought about putting these in the database, and then writing a function to retrieve this information, and then do the matching. This way I don’t need to write all the information in the code, which will be more flexible. point. After having this idea, I started to organize this data table.
There is nothing special to mention about the operation of the database. Here we mainly record the operations in the code:
1. First, get all the keywords:
This is very simple, just get the entire data of the keyword data table in the database:
select * from xxx Select the information of data table xxx;
Then store the obtained information into a two-dimensional array:
vcHLy/nT0LXEudi8/LTK0MXPosHLoaM8YnI+CjKhorXDtb3By7nYvPy0ysr9vt2x7bXE0MXPotauuvOjrL7NysfX9rnYvPy0yrXExqXF5MHLo7o8YnI+CjxwPsrXz8jO0tDo0 qq1w7W9xqXF5LW9tcTV4tK70NDK/b7d0MXPoqOsyLu689TZ1/bPwtK7sr21xLmk1/eho9L yzqrV4sDvtcS52Lz8tMrKx72r1u7I57XY1rehorXnu7ChosDPvNLWrsDgtcS05tTayv2+3 b/io6y2+NPDu6e3osvNuf3AtLXEv8nE3MrHWFi157uwoaJYWMDPvNKjrMv50tTU2tXiwO/F0LbPsrvKx9aux7DTw7XExMe49mluX2FycmF5LLb4ysfKudPDtcRzdHJzdHIoKbqvyv3AtNf2xdC2z7 XEo7o8L3A+CjxwPjxpbWcgc3JjPQ=="http://www.2cto.com/uploadfile/Collfiles/20140912/ 2014091209032020.png" alt="">
The specific code is as shown in the picture above, so that I can get the data row of this keyword in the data table, and then I will do the next step according to its type (the data table contains keywords and keyword types) fields, with these two pieces of information I can perform corresponding operations based on the keyword type):
The subsequent operation is to use the previous code directly. I just sorted out the structure here. The mentioned optimized keywords
2. Expression database
You can reply with emoticons when replying to messages. Here I am not using emoji expressions, but the most common ones. For example, "smile" is represented by "/::)". The emoticon data table I created is Use smile as the keyword, "/::)" as the value, and then add an expression type, a total of these three fields. When using it, just input the smile directly, then get its value and then reply, then you can use it. It only involves database operations, so I won’t go into details here.
3. Timeout mechanism
Because the official account uses $_SESSION to store information such as verifying user identity, as well as the selected menu type. I feel it is necessary to clean these regularly. For example, if the user selects a menu and then does not use it for a long time, then it is best not to be in the menu the next time he uses it, but to exit. With such a consideration in mind, I checked the relevant information on the Internet: either clear all $_SESSION regularly, or clear a single $_SESSION regularly. To do it regularly, you need to know the time. Combined with what I used in my previous mobile game projects, if you want to do it regularly, you just need to remember the time when it is turned on, and then make a judgment every time you use it.
In terms of implementation, first I record the time when a certain $_SESSION is stored, such as the time to verify the user's identity:
The psa_time() shown in the above picture is just a wrapper for the time() function provided by the system. In this way, I get the time of identity verification, and then I get the current time every time the user operates, to compare with the recorded time:
This implements what I call the timeout mechanism.
PHP learning record:
Will the function still be executed after echo? Before, my reply to messages was not under unified control. Maybe I would reply directly to some modules. But I found that even if I use echo to reply to the message, the code segment after the echo will still be executed. I don’t know what is going on.
http://www.bkjia.com/PHPjc/879185.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/879185.htmlTechArticlePHP WeChat Public Development Notes (8) PHP WeChat Public Development Notes Series Date: 2014.9.6 Main things to do today: Establish keyword database, timeout mechanism, optimized keyword matching, emoticon messages...