search
HomeBackend DevelopmentPHP TutorialPHP WeChat Development Tutorial: How to Search Sent Images and Texts and Reply by Matching Keywords

This article mainly introduces the method of using PHP to use WeChat development mode to search for sent images and text and match keyword replies. It involves PHP's analysis and regular matching of WeChat json format data. Friends who need it can refer to the following.

The example in this article describes the method of using PHP to use the WeChat development model to search for sent images and text and reply with matching keywords. Share it with everyone for your reference, the details are as follows:

Users send keywords and search for corresponding pictures and texts to reply.

I won’t talk about simulated login

Right-click to view the source code of the "Sent" image page. The image and text part is in json format.

Copy code The code is as follows:

{"msg_item":[{"id":80630,"type":9,"fakeid":"2397007301","nick_name":"Learn some psychology every day","date_time":1403445168,"content ":"","source":"mass","msg_status":2,"title":"(Issue 167) | A positive article I have read to keep you warm","desc" : "It is said that all creatures in the world can become immortals through cultivation, and cats are naturally among them. Every twenty years of cultivation, cats will grow an extra tail. When...","content_url":"http:\/ \/mp.weixin.qq.com\/s?__biz=MjM5NzAwNzMwMQ==&mid=201393381&idx=1&sn=5351cb8d440365c24a6abb709e4e0d8c#rd","show_type":1,"file_id":201393328,"app_sub_type" :3,"comment_url" :"","has_reply":0,"refuse_reason":"","multi_item":[{"seq":0,"cover":"https:\/\/mmbiz.qlogo.cn\/mmbiz\/ jOtiajqZ1n62uicM0XBZkqUB5BdJRdCMt0Y3CDIApNglh6Lj5zcmfm0mqN0YyGkNvekxP7j0uqs95AQejwZpTfCg\/0","title":"(Issue 167) | An article with positive energy that I have read to keep you warm","digest":"Everything in the world is legendary All living beings can cultivate and become immortals. And cats are naturally among them. Every twenty years of cultivation, cats will grow an extra tail. When...","content_url":"http:\/\/mp.weixin.qq.com\/s? __biz=MjM5NzAwNzMwMQ==&mid=201393381&idx=1&sn=5351cb8d440365c24a6abb709e4e0d8c#rd","file_id":201393328,"content":"","source_url":"","author":"","show_cover_pic" :0," vote_id":[]}],"to_uin":0,"send_stat":{"total":1656,"succ":1656,"fail":0}},{"id":80444,"type": 2,"fakeid":"2397007301","nick_name":"Learn some psychology every day","date_time":1403358199,"source":"mass","msg_status":2,"comment_url":""," has_reply":0,"refuse_reason":"","multi_item":[],"to_uin":0,"send_stat":{"total":1631,"succ":1631,"fail":0}}, {"id":80222,"type":9,"fakeid":"2397007301","nick_name":"Learn some psychology every day","date_time":1403272191,"content":"","source": "mass","msg_status":2,"title":"(Issue 166) | If you want the super power, let's play a voting entertainment~","desc":"Although it's nothing amazing, it's still The kind of super power you want...-----------END-----------You can click on the upper right corner "","content_url":"http:\/\/mp .weixin.qq.com\/s?__biz=MjM5NzAwNzMwMQ==&mid=201376620&idx=1&sn=a9ccae0826f5aa74476dc5936cec51f2#rd","show_type":1,"file_id":201370866,"app_sub_type":3,"com ment_url":"" ,"has_reply":0,"refuse_reason":"","multi_item":[{"seq":0,"cover":"https:\/\/mmbiz.qlogo.cn\/mmbiz\/jOtiajqZ1n62MibMmurxXEVsDbwZglIq1wSxian2K6cH8Du0l3fMgQ2GdmbovicAXpSmjsl I9iaCXicCTJC5Mef8ggBA\/ 0","title":"(Issue 166)| Let's play a voting entertainment for the super power you want~","digest":"Although it's nothing extraordinary, I still want this super power. ...-----------END-----------You can click "","content_url":"http:\/\/mp.weixin.qq.com\ in the upper right corner /s?__biz=MjM5NzAwNzMwMQ==&mid=201376620&idx=1&sn=a9ccae0826f5aa74476dc5936cec51f2#rd","file_id":201370866,"content":"","source_url":"","author":"","show_cover_pic": 0,"vote_id":[45050]},{"seq":1,"cover":"https:\/\/mmbiz.qlogo.cn\/mmbiz\/jOtiajqZ1n62MibMmurxXEVsDbwZglIq1w4hNsMaia4p6SXGIUU6NBwbyEbpFL2mESOJ0yuP5pJhzavHzgnyPMM 1A\/0","title":" [Art] | The lingering helplessness","digest":"Lying on the bed, scenes from the past passed through my mind.Four years of persistence, or seven years of dreaming, when it is shattered, just smile indifferently, how easy is it? Its implementation","content_url":"http:\/\/mp.weixin.qq.com\/s?__biz=MjM5NzAwNzMwMQ==&mid=201376620&idx=2&sn=21a7f8715f4b2ecc2f484fd3b04ca554#rd","file_id":201371031, "content ":"","source_url":"","author":"","show_cover_pic":1,"vote_id":[]},{"seq":2,"cover":"https:\/\ + I hope every girl who believes in love will Become an unbeatable warrior in love. No one is better than you, because there will never be another you in this world. Less dependent","content_url":"http:\/\/mp.weixin.qq.com\/s?__biz=MjM5NzAwNzMwMQ==&mid=201376620&idx=3&sn=ca0a2122e1c5d8f848fd6412ea347664#rd","file_id":201374122 ," content":"","source_url":"","author":"","show_cover_pic":0,"vote_id":[]}],"to_uin":0,"send_stat":{"total": 1610,"succ":1610,"fail":0}},{"id":79872,"type":1,"fakeid":"2397007301","nick_name":"Learn some psychology every day"," date_time":1403185708,"content":"Friends, we have a day off today, no posts, you should go to bed early~\/:","source":"mass","msg_status":2," comment_url":"","has_reply":0,"refuse_reason":"","multi_item":[],"to_uin":0,"send_stat":{"total":1584,"succ":1584," fail":0}},{"id":79544,"type":9,"fakeid":"2397007301","nick_name":"Learn some psychology every day","date_time":1403098674,"content": "","source":"mass","msg_status":2,"title":"(Issue 165) | Why do children steal things","desc":"Children stealing things is a very serious behavior , but it seems that many children have a stage of stealing things when they grow up. How should parents educate them? Why do children","content_url":"http:\/\/mp.weixin.qq.com\/s? __biz=MjM5NzAwNzMwMQ==&mid=201345041&idx=1&sn=b2ef53dcfd93db2737240f932a0297d5#rd","show_type":1,"file_id":201240144,"app_sub_type":3,"comment_url":""," has_reply":0,"refuse_reason" :"","multi_item":[{"seq":0,"cover":"https:\/\/mmbiz.qlogo.cn\/mmbiz\/jOtiajqZ1n60ZFQ7comgKCEXlkibVZXmJf1PqAs4czgl0AiakwonBibD5DT2ytE6tA8VJdBVibuS92XgWXbuMibKmicRg\/ 0","title":"(No. Issue 165) | Why do children steal?","digest":"Child stealing is a very serious behavior, but it seems that many children have a stage of stealing during their growth. How should parents educate their children? Why?","content_url":"http:\/\/mp.weixin.qq.com\/s?__biz=MjM5NzAwNzMwMQ==&mid=201345041&idx=1&sn=b2ef53dcfd93db2737240f932a0297d5#rd","file_id":201240144,"content ":"","source_url":"","author":"bug","show_cover_pic":1,"vote_id":[]},{"seq":1,"cover":"https:\/ \/mmbiz.qlogo.cn\/mmbiz\/jOtiajqZ1n60ZFQ7comgKCEXlkibVZXmJfRPJl3P72Vh8l46B1m6EvZY4IWRnFB0AHkxrTSbghME9TxmFyibbxXdQ\/0","title":"Eight pictures make you understand a lot","digest":"Small pictures, big ideas. -----------END-----------You can click "Share to Moments" in the upper right corner. WeChat ID: m","content_url":"http:\/\/mp.weixin.qq.com\/s?__biz=MjM5NzAwNzMwMQ==&mid=201345041&idx=2&sn=63ae37b620566f2dc80d4b229b98a5f4#rd","file_id":20124018 7, "content":"","source_url":"","author":"bug","show_cover_pic":0,"vote_id":[]}],"to_uin":0,"send_stat":{"total ":1568,"succ":1568,"fail":0}}]}


Just parse json directly.


<?php
$wechatObj = new wechatappmsg();
$wechatObj->getappmsg(&#39;这里是json&#39;);
class wechatappmsg{
  function getappmsg($content){
    //require_once &#39;db.php&#39;;
    $jsonstr=$content;
    //   $jsonstr=&#39;{"msg_item":[{"id":79544,"type":9},{}]}&#39;;
    $jsonstr = iconv(&#39;gbk&#39;, &#39;utf-8&#39;, $jsonstr);
    $result = json_decode($jsonstr);
    $name=$result->msg_item;
    // var_dump($name);
    //   echo &#39;<br/>json:&#39;.$result;
    $size=count($name);
    echo &#39;<br/>size:&#39;.$size;
    //  exit;
    for($i=0;$i<$size;$i++){
      $multi_item=$name[$i]->multi_item;
      $size2=count($multi_item);
      $app_id=$name[$i]->app_id;
      $create_time=$name[$i]->date_time;//发送时间
      //  echo &#39;<br/>app_id:&#39;.$app_id;
      $create_time=date ("Y-m-d H:i:s", $create_time);//时间转换
      echo &#39;<br/>create_time:&#39;.$create_time;
      for($j=0;$j<$size2;$j++){
        $title=$multi_item[$j]->title;//标题
        $pic_url=$multi_item[$j]->cover;//图片地址
        $digest=$multi_item[$j]->digest;//简要
        $content_url=$multi_item[$j]->content_url;//图文地址
        $t = iconv(&#39;utf-8&#39;, &#39;gbk&#39;, $title);
        echo &#39;<br/>title:&#39;.$t;
        echo &#39;<br/>Link:&#39;.$content_url;
        preg_match("/mid=([0-9]+)&/",$content_url,$string);
        $app_mid=$string[1];//一次发送的多个图文,这个ID值可以判断这两个图文是同一次发送的
        echo &#39;<br/>app_mid:&#39;.$app_mid;
        //这里可以直接进行入库
//$x=saveappmsg($pic_url,$title,$digest,$content_url,$create_time,$app_mid);
 sleep(3);
      }
      echo &#39;<br/>-------------------------------------&#39;;
    }
  }
}
?>

Database:

The user replies with the keyword, and then queries and replies with the corresponding graphic information

1》Query based on the issue number:

.

select app_id from table where title like &#39;%162期%&#39; limit 1;
select * from table where app_id=XXXXX;

2》Based on keywords:


select * from table where title like &#39;%故事%&#39; limit 10;

The above is the detailed content of PHP WeChat Development Tutorial: How to Search Sent Images and Texts and Reply by Matching Keywords. For more information, please follow other related articles on the PHP Chinese website!

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
php怎么把负数转为正整数php怎么把负数转为正整数Apr 19, 2022 pm 08:59 PM

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

php怎么实现几秒后执行一个函数php怎么实现几秒后执行一个函数Apr 24, 2022 pm 01:12 PM

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php怎么除以100保留两位小数php怎么除以100保留两位小数Apr 22, 2022 pm 06:23 PM

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

php字符串有没有下标php字符串有没有下标Apr 24, 2022 am 11:49 AM

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php怎么根据年月日判断是一年的第几天php怎么根据年月日判断是一年的第几天Apr 22, 2022 pm 05:02 PM

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

php怎么读取字符串后几个字符php怎么读取字符串后几个字符Apr 22, 2022 pm 08:31 PM

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

php怎么替换nbsp空格符php怎么替换nbsp空格符Apr 24, 2022 pm 02:55 PM

方法:1、用“str_replace("&nbsp;","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\&nbsp\;||\xc2\xa0)/","其他字符",$str)”语句。

php怎么判断有没有小数点php怎么判断有没有小数点Apr 20, 2022 pm 08:12 PM

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),