Home php教程 php手册 PHP微信公众开发笔记(八)

PHP微信公众开发笔记(八)

Jun 21, 2016 am 08:47 AM
echo php session

PHP微信公众开发笔记系列
日期:2014.9.6

今天主要要做:建立关键词数据库、超时机制、优化的关键词匹配、表情信息数据库

要注意的:PHP echo之后并没有返回?还会继续执行??

2014.9.11整理笔记:
写这个笔记的时候,在赶功能,所以也就是简单的记几笔当时的工作内容,现在功能开发得差不多了,就来整理之前的笔记。当时就很简单的记录了上文的那几句。

这天是周六,不加班了在租的房子里歇着。因为要过中秋了,在深圳的姐这天会过来我这边过节,所以这天也没多少时间来写功能。早上早起去跑步,然后回来就开始折腾了(现在想想,没准以后自己真会成为一个工作狂了)。这天做的功能是在数据库中建立一个关键词数据表、表情信息数据表、加入了超时机制和优化了关键词匹配。

一、关键词数据表
这个数据表存储的信息主要是我之前做关键词过滤、捕获时用到的一些关键词。因为想方便管理,所以想一想将这些放到数据库中去,然后写一个函数调取这些信息,再去做匹配,这样我就不需要将所有的信息都写死在代码中,会更灵活点。有了这个想法之后,便开始整理这个数据表了。
关于数据库的操作没什么特意要提的,这里主要是记录下代码中的操作吧:
1、首先是获得所有的关键词:
这个很简单,就是将数据库中关键词数据表的整个数据都弄出来:
select * from xxx 选取数据表xxx的信息;

然后将得到的信息存储至一个二维数组中:

vcHLy/nT0LXEudi8/LTK0MXPosHLoaM8YnI+CjKhorXDtb3By7nYvPy0ysr9vt2x7bXE0MXPotauuvOjrL7NysfX9rnYvPy0yrXExqXF5MHLo7o8YnI+CjxwPsrXz8jO0tDo0qq1w7W9xqXF5LW9tcTV4tK70NDK/b7d0MXPoqOsyLu689TZ1/bPwtK7sr21xLmk1/eho9LyzqrV4sDvtcS52Lz8tMrKx72r1u7I57XY1rehorXnu7ChosDPvNLWrsDgtcS05tTayv2+3b/io6y2+NPDu6e3osvNuf3AtLXEv8nE3MrHWFi157uwoaJYWMDPvNKjrMv50tTU2tXiwO/F0LbPsrvKx9aux7DTw7XExMe49mluX2FycmF5LLb4ysfKudPDtcRzdHJzdHIoKbqvyv3AtNf2xdC2z7XEo7o8L3A+CjxwPjxpbWcgc3JjPQ=="/program/UploadPic/2014-9/201492512823654.png" alt="\">


具体代码如上图所示,这样我就得到了这个关键词在数据表中的数据行了,然后我根据其类型再做下一步工作(数据表中包含关键词、关键词类型这两个字段,有这两个信息我就可以根据关键词类型做相应的操作了):



后续的操作就是直接使用的之前的代码,我这里只是理了一下结构而已。提到的优化了关键词

二、表情数据库
回复信息是可以回复表情的,在这里我不是用的emoji表情,而是最普通的那种,比如说"微笑" 就用"/::)"这个来表示,我建立的表情数据表也就是以微笑作为关键词,以"/::)"为值,然后加上一个表情类型,总共这三个字段。使用的时候,使用直接输入微笑,然后得到其值再回复,就可以使用了。也只是涉及到数据库的操作,在这里就不多啰嗦了。

三、超时机制
因为公众号使用了$_SESSION来存储如验证用户身份等信息,还有选择的菜单类型。就感觉有必要定期清理这些,比如说用户选择了菜单,然后长时间没有用了,那么就最好是下一次再使用的时候没有在菜单里了,而应该是退出了。有这样一个考虑,我就在网上查阅了相关了资料:要么就是定期全部清理所有的$_SESSION,要么就是定期清除单个$_SESSION。要做到定期,那么就需要知道时间,结合我之前做手游项目时用到的东西,想做定期无非也就是记住开启的时间,然后在每次使用的时候做判断就可以了。

在实现上,首先我是记录存储某个$_SESSION的时间,比如说验证用户身份的时间:



上图出现的psa_time()也只是对系统提供的time()函数的一个包装而已。这样我就获得了验证身份的时间,然后我在每次用户操作的时候获得当前时间,用来跟记录的这个时间做对比:



这样就实现了我所谓的超时机制了。


PHP学习记录:
在echo 之后,函数还是会执行下去嘛?之前,我回复信息并不是统一控制,可能某些模块我会直接回复了。但是我发现,即使我用echo回复了消息了,还是会执行echo之后的代码段,这不知道是啥情况。



Statement of this Website
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

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

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

See all articles