本文实例讲述了PHP使用微信开发模式实现搜索已发送图文及匹配关键字回复的方法。分享给大家供大家参考,具体如下:
用户发送关键字,搜索相应的图文进行回复。
模拟登陆就不说了
右键看“已发送”图片页的源代码,图文部分是json格式的。
复制代码 代码如下:{"msg_item":[{"id":80630,"type":9,"fakeid":"2397007301","nick_name":"每天学点心理学","date_time":1403445168,"content":"","source":"mass","msg_status":2,"title":"(第167期)| 我读过的具有正能量的一篇文章,为你取暖","desc":"传说世间的一切生灵皆可修炼成仙,而猫自然在其中。每修炼二十年,猫就会多长出一条尾巴,等到有...","content_url":"http:\/\/mp.weixin.qq.com\/s","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":"(第167期)| 我读过的具有正能量的一篇文章,为你取暖","digest":"传说世间的一切生灵皆可修炼成仙,而猫自然在其中。每修炼二十年,猫就会多长出一条尾巴,等到有...","content_url":"http:\/\/mp.weixin.qq.com\/s","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":"每天学点心理学","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":"每天学点心理学","date_time":1403272191,"content":"","source":"mass","msg_status":2,"title":"(第166期)| 想要的超能力,来玩一个投票娱乐下吧~","desc":"虽然没啥了不起的,但还是想要的这种超能力…-----------END-----------可以点击右上角『","content_url":"http:\/\/mp.weixin.qq.com\/s","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\/jOtiajqZ1n62MibMmurxXEVsDbwZglIq1wSxian2K6cH8Du0l3fMgQ2GdmbovicAXpSmjslI9iaCXicCTJC5Mef8ggBA\/0","title":"(第166期)| 想要的超能力,来玩一个投票娱乐下吧~","digest":"虽然没啥了不起的,但还是想要的这种超能力…-----------END-----------可以点击右上角『","content_url":"http:\/\/mp.weixin.qq.com\/s","file_id":201370866,"content":"","source_url":"","author":"","show_cover_pic":0,"vote_id":[45050]},{"seq":1,"cover":"https:\/\/mmbiz.qlogo.cn\/mmbiz\/jOtiajqZ1n62MibMmurxXEVsDbwZglIq1w4hNsMaia4p6SXGIUU6NBwbyEbpFL2mESOJ0yuP5pJhzavHzgnyPMM1A\/0","title":"【美文】| 挥之不去的无奈","digest":"躺在床上,过往的一幕幕在脑海掠过。四年的坚持,抑或说是7年的梦想,当它破灭时,仅仅淡然一笑,谈何容易?其实行","content_url":"http:\/\/mp.weixin.qq.com\/s","file_id":201371031,"content":"","source_url":"","author":"","show_cover_pic":1,"vote_id":[]},{"seq":2,"cover":"https:\/\/mmbiz.qlogo.cn\/mmbiz\/jOtiajqZ1n62MibMmurxXEVsDbwZglIq1wNzqasiaEPYAGXQQdLnkaiaW56ueicHelZFJCjWUA3dg6ibWw15N1KQtEeQ\/0","title":"【插画】| 不是所有的伤口都能自我愈合","digest":"愿每一个相信爱的女生,都能成为爱里打不倒的战士。没有人比你更美好,因为这个世界上不会再有第二个你了。少一点依","content_url":"http:\/\/mp.weixin.qq.com\/s","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":"每天学点心理学","date_time":1403185708,"content":"朋友们,今天休息,不发咯,你们也早点休息哟","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":"每天学点心理学","date_time":1403098674,"content":"","source":"mass","msg_status":2,"title":"(第165期)| 孩子为什么会偷东西","desc":"小孩偷东西是一种很严重的行为,但好像是很多孩子在成长过程中都有偷东西一个阶段,父母该如何教育呢","content_url":"http:\/\/mp.weixin.qq.com\/s","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":"(第165期)| 孩子为什么会偷东西","digest":"小孩偷东西是一种很严重的行为,但好像是很多孩子在成长过程中都有偷东西一个阶段,父母该如何教育呢","content_url":"http:\/\/mp.weixin.qq.com\/s","file_id":201240144,"content":"","source_url":"","author":"虫子","show_cover_pic":1,"vote_id":[]},{"seq":1,"cover":"https:\/\/mmbiz.qlogo.cn\/mmbiz\/jOtiajqZ1n60ZFQ7comgKCEXlkibVZXmJfRPJl3P72Vh8l46B1m6EvZY4IWRnFB0AHkxrTSbghME9TxmFyibbxXdQ\/0","title":"八张图让你明白很多","digest":"小图片,大道理。-----------END-----------可以点击右上角『分享至朋友圈』。微信号:m","content_url":"http:\/\/mp.weixin.qq.com\/s","file_id":201240187,"content":"","source_url":"","author":"虫子","show_cover_pic":0,"vote_id":[]}],"to_uin":0,"send_stat":{"total":1568,"succ":1568,"fail":0}}]}
直接解析json即可。
<"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/>size:'.$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 '<br/>app_id:'.$app_id; $create_time=date ("Y-m-d H:i:s", $create_time);//时间转换 echo '<br/>create_time:'.$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('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];//一次发送的多个图文,这个ID值可以判断这两个图文是同一次发送的 echo '<br/>app_mid:'.$app_mid; //这里可以直接进行入库 //$x=saveappmsg($pic_url,$title,$digest,$content_url,$create_time,$app_mid); sleep(3); } echo '<br/>-------------------------------------'; } } } "" src="/UploadFiles/2021-04-02/2017913123219456.jpg">用户回复关键字,然后查询回复相应图文信息。
1》根据期数进行查询:
select app_id from table where title like '%162期%' limit 1; select * from table where app_id=XXXXX;2》根据关键字:
select * from table where title like '%故事%' limit 10;更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP微信开发技巧汇总》、《PHP编码与转码操作技巧汇总》、《PHP网络编程技巧总结》、《php字符串(string)用法总结》、《PHP中json格式数据操作技巧汇总》及《PHP针对XML文件操作技巧总结》
希望本文所述对大家PHP程序设计有所帮助。
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]