PHP uses the WeChat development mode to search for sent text and matched keyword replies,

Source: Internet
Author: User

PHP uses the development mode to search for sent text and matched keyword replies,

This example describes how PHP uses the development mode to search for sent text and matched keyword responses. We will share this with you for your reference. The details are as follows:

The user sends a keyword and searches for the corresponding text to reply.

Simulate login without saying anything

Right-click the source code of the "sent" image page and choose json format.
Copy codeThe Code is as follows: {"msg_item": [{"id": 80630, "type": 9, "fakeid": "2397007301", "nick_name ": "Learn psychology every day", "date_time": 1403445168, "content": "", "source": "mass", "msg_status": 2, "title ": "(Issue 1) | I have read an article with positive energy to warm you up.", "desc": "It is said that all creatures in the world can cultivate to be immortal, the cat is naturally in it. Every 20 years of practice, the cat will grow an extra tail and wait until there is... "," content_url ":" http: \/mp.weixin.qq.com \/s? _ Biz = MjM5NzAwNzMwMQ ==& mid = 201393381 & idx = 1 & sn = # 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 \/Jun \/0", "title": "(Issue 1) | I have read an article with positive energy, warm up for you "," digest ":" It is said that everything in the world is You can cultivate them into immortals, and cats are naturally in them. Every 20 years of practice, the cat will grow an extra tail and wait until there is... "," content_url ":" http: \/mp.weixin.qq.com \/s? _ Biz = MjM5NzAwNzMwMQ ==& mid = 201393381 & idx = 1 & sn = # 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": "Psychology everyday", "date_time": 1403358199, "source": "mass", "msg_status": 2, "comment_url ":"", "has_reply": 0, "refuse_reaso N ":" "," multi_item ": []," to_uin ": 0," send_stat ":{" total ": 1631," succ ": 1631," fail ": 0 }},{ "id": 80222, "type": 9, "fakeid": "2397007301", "nick_name": "learn psychology every day", "date_time ": 1403272191, "content": "", "source": "mass", "msg_status": 2, "title": "(stage 1) | super power you want, let's have a vote for entertainment ~ "," Desc ":" Although there is nothing remarkable, you still want this super power... ----------- END ----------- click "," content_url ":" http: \/mp.weixin.qq.com \/s in the upper right corner? _ Biz = MjM5NzAwNzMwMQ ==& mid = 201376620 & idx = 1 & sn = # rd "," show_type ": 1," file_id ": 201370866," app_sub_type ": 3, "comment_url": "", "has_reply": 0, "refuse_reason": "", "multi_item": [{"seq": 0, "cover ": "https: \ // mmbiz.qlogo.cn \/mmbiz \/strong \/0", "title": "(stage 1) | super power you want. Come and have a vote for entertainment ~ "," Digest ":" Although there is nothing remarkable, you still want this super power... ----------- END ----------- click "," content_url ":" http: \/mp.weixin.qq.com \/s in the upper right corner? _ Biz = MjM5NzAwNzMwMQ ==& mid = 201376620 & idx = 1 & sn = # rd "," file_id ": 201370866," content ":" "," source_url ": "", "author": "", "show_cover_pic": 0, "vote_id": [45050] },{ "seq": 1, "cover": "https: \ // mmbiz.qlogo.cn \/mmbiz \/Hangzhou \/0 "," title ":" [文] | lingering helplessness "," digest ":" lying in bed, past scenes swept through your mind. Four years of persistence, or seven years of dream, when it is shattered, just smile, how easy? Actually, "," content_url ":" http: \/mp.weixin.qq.com \/s? _ Biz = MjM5NzAwNzMwMQ ==& mid = 201376620 & idx = 2 & sn = # rd "," file_id ": 201371031," content ":" "," source_url ": "", "author": "", "show_cover_pic": 1, "vote_id": [] },{ "seq": 2, "cover": "https: \ // mmbiz.qlogo.cn \/mmbiz \/success \/0 "," title ":" [illustration] | not all wounds can be self-healed "," digest ": "May every girl who believes in love be able to become a warrior in love. No one is better than you, because there will be no second one in the world. Less dependent on "," content_url ":" http: \/mp.weixin.qq.com \/s? _ Biz = MjM5NzAwNzMwMQ ==& mid = 201376620 & idx = 3 & sn = ca0a2122e1c5d8f848fd6412ea0000664 # 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 psychology every day", "date_time": 1403185708, "content": "Dear friends, you can take a rest today. If you don't want to send a message, you can take a rest early 〜\/: <L> "," source ":" mass "," msg_status ": 2," co Mment_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": "Psychology everyday", "date_time": 1403098674, "content": "", "source": "mass", "msg_status ": 2, "title": "(Issue 1) | why did a child steal?", "desc": "It is a very serious behavior for a child to steal things, but it seems that many children are stealing things during their growth. How should their parents educate them? Why does the child "," content_url ":" http: \/mp.weixin.qq.com \/s? _ Biz = MjM5NzAwNzMwMQ ==& mid = 201345041 & idx = 1 & sn = # 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 \/other \/0", "title": "(stage 1) | why did the child steal", "digest ": "stealing a child is a very serious behavior, But it seems that many children are stealing things during their growth. How should their parents educate them? Why does the child "," content_url ":" http: \/mp.weixin.qq.com \/s? _ Biz = MjM5NzAwNzMwMQ ==& mid = 201345041 & idx = 1 & sn = b2ef53dcfd93db2737240f932a0297d5 # rd "," file_id ": 201240144," content ":" "," source_url ": "", "author": "worms", "show_cover_pic": 1, "vote_id": [] },{ "seq": 1, "cover": "https: \ // mmbiz.qlogo.cn \/mmbiz \/picture \/0 "," title ":" eight pictures let you understand a lot "," digest ":" small pictures, big truth. ----------- END ----------- click "share to circle of friends" in the upper right corner 』. No.: m "," content_url ":" http: \/mp.weixin.qq.com \/s? _ Biz = MjM5NzAwNzMwMQ ==& mid = 201345041 & idx = 2 & sn = # rd "," file_id ": 201240187," content ":" "," source_url ": "", "author": "worms", "show_cover_pic": 0, "vote_id": []}], "to_uin": 0, "send_stat ": {"total": 1568, "succ": 1568, "fail": 0}]}
Parse json directly.

<? Php $ wechatObj = new wechatappmsg (); $ wechatObj-> getappmsg ('here is json'); class wechatappmsg {function getappmsg ($ content) {// require_once 'db. php '; $ jsonstr = $ content; // $ jsonstr =' {"msg_item": [{"id": 79544, "type": 9 }, {}]} '; $ jsonstr = iconv ('gbk', 'utf-8', $ jsonstr); $ result = json_decode ($ jsonstr ); $ name = $ result-> msg_item; // var_dump ($ name); // echo '<br/> json :'. $ result; $ size = count ($ name); echo '<br/> s Ize :'. $ 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; // sending time // echo '<br/> app_id :'. $ app_id; $ create_time = date ("Y-m-d H: I: s", $ create_time); // time conversion echo '<br/> create_time :'. $ create_time; for ($ j = 0; $ j <$ size2; $ j ++) {$ title = $ multi_item [$ j]-> title; // Title $ pic_url = $ multi_item [$ j]-> cover; // picture Address $ digest = $ multi_item [$ j]-> digest; // brief $ content_url = $ multi_item [$ j]-> content_url; // image and text address $ t = iconv ('utf-8', 'gbk', $ title); echo '<br/> title :'. $ t; echo '<br/> Link :'. $ content_url; preg_match ("/mid = ([0-9] +) &/", $ content_url, $ string); $ app_mid = $ string [1]; // multiple texts sent at a time. The ID value can be used to determine whether the two texts are sent at the same time. '<br/> app_mid :'. $ app_mid; // You can import data directly here. // $ x = saveappmsg ($ pic_url, $ title, $ digest, $ content_url, $ create_time, $ app _ Mid); sleep (3);} echo '<br/> -------------------------------------' ;}}?>

Database:

The user replies with keywords, and then queries and replies the corresponding text information.

1. query by period:

Select app_id from table where title like '% stage 162%' limit 1; select * from table where app_id = XXXXX;

2 According to keywords:

Select * from table where title like '% story %' limit 10;

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.