以前写的,现在融合了微韵的第三方扩展接口,所以这个用不到了,分享出来,希望能给大家一些开发思路!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
public function replyState($content,$status=1,$type='text'){ return array('content'=>$content,'status'=>$status,'type'=>$type); } /*回复文字消息*/ public function text($message){ $keywords = $message['Content']; $setContent = GetDbDet($keywords); if(S($message['FromUserName']) || $message['Content'] == $setContent['keywords']){ if($message['Content'] == $setContent['keywords']){ $TempArr = array('next'=>$setContent['next'],'Fname'=>$setContent['Fname'],'num'=>1); S($message['FromUserName'],json_encode($TempArr)); return $this->reply(1,$setContent['prompt'],'text'); }else{ $DbSendMes = json_decode(S($message['FromUserName']),true); //拿出来上次缓存的 if($DbSendMes['num'] == 1){ $result = $this->$DbSendMes['Fname']($message); /*如果不进行后续操作,直接清理缓存,*/ if($DbSendMes['next']) { $TempNum = -1;S($message['FromUserName'],null);} $TempArr = array('next'=>$DbSendMes['next'],'Fname'=>$DbSendMes['Fname'],'num'=>$TempNum); S($message['FromUserName'],json_encode($TempArr)); //第二次缓存 return $this->reply($result['status'],$result['content'],$result['type']); }elseif($DbSendMes['num'] == 2){ S($message['FromUserName'],null); return $this->reply(1,$DbSendMes['next'],'text'); }else{ $content = $this->Nokeyword($keywords); return $this->reply(1,$content['content'],'text'); } } }else{ $content = $this->Nokeyword($keywords); return $this->reply(1,$content['content'],'text'); } } /*没有遇到关键词时候调用图灵机器人进行回复*/ public function Nokeyword($keywords){ $url= 'http://www.tuling123.com/openapi/api?key=a0a06743dc5ce0887e6a65eac23999b5&info='; $result = https_request($url.$keywords); $content = json_decode($result,true); if ($content['code'] == 100000) { return $this->replyState($content['text']); }else{ return $this->replyState('人类泥豪~,这个微信天明宝宝正在开发中...'); } } /*回复图文*/ public function ArticleImg(){ $ImgData= array( "0"=>array( 'Title'=>'msg title', 'Description'=>'summary text', 'PicUrl'=>'http://www.domain.com/1.jpg', 'Url'=>'http://www.domain.com/1.html' ), "1"=>array( 'Title'=>'msg title', 'Description'=>'summary text', 'PicUrl'=>'http://www.domain.com/1.jpg', 'Url'=>'http://www.domain.com/1.html' ), ); return $ImgData; } /*回复音乐*/ public function music($message){ $music = new Kugou(); $list = $music->kgMusicSearch($message['Content'],1); $url = "http://m.kugou.com/app/i/getSongInfo.php?hash=".$list[0]['hash']."&cmd=playInfo"; $data = json_decode(file_get_contents($url),true); $MusicData = array( 'Title'=>$data['fileName'], 'Description'=>$data['fileName'], 'MusicUrl'=>$data['url'], 'HQMusicUrl'=>$data['url'], ); S($message['FromUserName'].'_Music',null); return $MusicData; } /*说说碎碎念*/ public function sendShuoshuo($message){ $SendUser = ['o76__jm91gcavuxhghgsUe96xxJY','o76__jsR7Sat9HjmF3reVFINoyNA'];//授权用户 if (!in_array($message['FromUserName'],$SendUser)) { return $this->replyState('天明宝宝好坏好坏的,最近又调整了碎碎念发表程序的逻辑,您可能需要重新授权哦~'); }else{ $TempArr = array($message['FromUserName'],$message['Content'],'wx'); $result = A('Api/Twitter')->add($message['FromUserName'],$message['Content'],'wx',1); if($result['code'] > 0){ return $this->replyState('^_^碎碎念发表成功啦[大笑]'); } } } /*投诉建议*/ public function Myspeak($message){ $MessageData = GetTitleContent($message['Content']); if ($MessageData > 0) { $content = array($MessageData[0],$MessageData[1]); setLog('jianyi_json.json',json_encode($content),'json');//存入日志 S($message['FromUserName'].'_Speak',null); return $this->replyState('^_^,感谢你,明哥哥已经收到你的信息了...'); }else{ return $this->replyState('^~^,别闹,明哥哥都被你玩坏了,你输入的都是些什么啊,说好的##中间的标题呢?'); } } /*天气预报*/ public function weather($message){ $url = 'http://api.map.baidu.com/telematics/v3/weather?location='.$message['Content'].'&output=json&ak=Isfaaj45HoG35tgG1rEv0U3G'; $weatheer = https_request($url); $weatheer = json_decode($weatheer,true); $weatheer = $weatheer['results'][0]['weather_data']; foreach ($weatheer as $k => $v){ $time = date('H',time()); if($time <18 && $time > 8){ $picurl = $v['dayPictureUrl']; }else{ $picurl = $v['nightPictureUrl']; } $TempArr[] = array( 'Title'=>$v['date'].' '.$v['weather'].''.$v['wind'], 'Description'=>$v['date'].'天气情况', 'PicUrl'=>$picurl, 'Url'=>'http://blog.he29.com' ); } return $this->replyState($TempArr,1,'ArticleImg');//回复图文小西类型 } /*许愿墙*/ public function Wish($message){ $MessageData = GetTitleContent($message['Content']); if (!empty($MessageData)) { $TempArr = ['name'=>$MessageData[0],'id'=>$message['FromUserName'],'content'=>$MessageData[1],'time'=>time()]; setLog('wish_json.json',json_encode($TempArr),'json');//存入日志 return $this->replyState('许愿成功啦~~静静等待愿望的实现吧~~'); }else{ if($MessageData[1] <= 3) return $this->replyState('^~^,别闹,明哥哥都被你玩坏了,咱能多写几个字进去嘛,重新发送"许愿"进入许愿模式'); if($MessageData < 0) return $this->replyState('说好的名字呢?赶快给自己起一个名字吧~重新发送"许愿"进入许愿模式'); } } |
天明