search
HomeBackend DevelopmentPHP TutorialPHP WeChat Public Development Notes (8)_PHP Tutorial

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:

PHP WeChat Public Development Notes (8)_PHP TutorialvcHLy/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.

www.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...
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software