微信公众号发多个消息php,微擎系统微信公众号关键字触发回复多条消息实现
1 private functionmsg_respond() {2 $rids = !is_array($this->rule) ? explode(‘,‘, $this->rule) : $this->rule;3 //數據庫中獲取發送文字的信息
4 $reply = table(‘basic_reply‘)->where(array(‘rid IN‘ => $rids))->orderby(‘id‘)->getAll();5 //圖片
6 $img_reply = table(‘images_reply‘)->where(array(‘rid IN‘ => $rids))->orderby(‘id‘)->getAll();7 //圖文8 //$news_reply = table(‘news_reply‘)->where(array(‘rid IN‘ => $rids,‘parent_id ==‘ => -1))->orderby(‘id‘)->getAll();
9 $news_reply = table(‘news_reply‘)->where(array(‘rid IN‘ => $rids))->orderby(‘id‘)->getAll();10 //音樂
11 $music_reply = table(‘music_reply‘)->where(array(‘rid IN‘ => $rids))->orderby(‘id‘)->getAll();12 //語音
13 $voice_reply = table(‘voice_reply‘)->where(array(‘rid IN‘ => $rids))->orderby(‘id‘)->getAll();14 //視頻
15 $video_reply = table(‘video_reply‘)->where(array(‘rid IN‘ => $rids))->orderby(‘id‘)->getAll();16 //父級找子級
17 /*foreach ($news_reply as &$value){18 //if ($value[‘parent‘] != -1) {19 $value[‘parent_data‘] = table(‘news_reply‘)->where([‘parent_id‘ => $value[‘id‘]])->orderby(‘id‘)->getAll();20 //}21 }*/
22
23 //判斷是否為空,如果都為空返回false
24 if (empty($reply)&&empty($img_reply)&&empty($news_reply)&&empty($music_reply)&&empty($voice_reply)&&empty($video_reply)) {25 return false;26 }27 $access_token=$this->getToken();28 $postStr=file_get_contents(‘php://input‘);29 $postObj = simplexml_load_string($postStr, ‘SimpleXMLElement‘,LIBXML_NOCDATA);30 if (count($reply)+count($img_reply)+count($news_reply)+count($music_reply)+count($voice_reply)+count($video_reply)==1){31 if($reply!=null){32 $reply[0][‘content‘] = htmlspecialchars_decode($reply[0][‘content‘]);33 $reply[0][‘content‘] = str_replace(array(‘
‘, ‘?‘), array("\n", ‘ ‘), $reply[0][‘content‘]);34 $reply[0][‘content‘] = strip_tags($reply[0][‘content‘], ‘‘);35 return $reply[0][‘content‘];36 }elseif ($img_reply!=null){37 for ($y=0;$yimageReply($postObj->FromUserName,$access_token,$img_reply[$y][‘mediaid‘]);39 }40 }elseif ($news_reply!=null){41 //$this->judgeType(‘news‘);
42 for ($j=0;$j
44 //$this->newsReply($postObj->FromUserName,$access_token,$news_reply[$j][‘url‘],$news_reply[$j][‘thumb‘],$news_reply[$j][‘title‘],$news_reply[$j][‘description‘],$news_reply[$j][‘parent_data‘]);
45 $this->newsReply($postObj->FromUserName,$access_token,$news_reply[$j][‘url‘],$news_reply[$j][‘thumb‘],$news_reply[$j][‘title‘],$news_reply[$j][‘description‘],$news_reply[$j][‘media_id‘]);46 }47 }elseif ($music_reply!=null){48 $result = $this->music_respond();49 return $this->respMusic(array(50 ‘Title‘ => $result[‘title‘],
51 ‘Description‘ => $result[‘description‘],
52 ‘MusicUrl‘ => $result[‘url‘],
53 ‘HQMusicUrl‘ => $result[‘hqurl‘],
54 ));55 }elseif ($voice_reply!=null){56 for ($s=0;$svoiceReply($postObj->FromUserName,$access_token,$voice_reply[$s][‘mediaid‘]);58 }59 }elseif ($video_reply!=null){60 for ($d=0;$dvideoReply($postObj->FromUserName,$access_token,$video_reply[$d][‘mediaid‘],$video_reply[$d][‘title‘],$video_reply[$d][‘description‘]);62 }63 }else{64 return "數據錯誤!!!";65 }66 }else{67 //循環發送圖片
68 for ($y=0;$yimageReply($postObj->FromUserName,$access_token,$img_reply[$y][‘mediaid‘]);70 }71 //循環發送圖文
72 for ($j=0;$jnewsReply($postObj->FromUserName,$access_token,$news_reply[$j][‘url‘],$news_reply[$j][‘thumb‘],$news_reply[$j][‘title‘],$news_reply[$j][‘description‘],$news_reply[$j][‘media_id‘]);74 }75 //視頻
76 for ($d=0;$dvideoReply($postObj->FromUserName,$access_token,$video_reply[$d][‘mediaid‘],$video_reply[$d][‘title‘],$video_reply[$d][‘description‘]);78 }79 //語音
80 for ($s=0;$svoiceReply($postObj->FromUserName,$access_token,$voice_reply[$s][‘mediaid‘]);82 }83 //循環發送文字
84 for($i=0;$ireplymsg($postObj->FromUserName,$access_token,trim($reply[$i][‘content‘]));89 }90 }91 }92 return 0;93 }
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的微信公众号发多个消息php,微擎系统微信公众号关键字触发回复多条消息实现的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: oracle 增长型分区,oracle表
- 下一篇: oracle sql文本 参数,ORAC