-
图文天气查询
效果:
<?php $msg=$this->message[‘content‘];//文本消息内容 $id=$this->message[‘from‘];//用户ID $msgid=$this->message[‘msgid‘];//消息ID $time=$this->message[‘time‘];//消息发送时间 return $this->respText($msg); $city=str_replace("天气","",$msg); if(empty($city)){ $city=‘江夏‘; } $url=‘http://api.map.baidu.com/telematics/v3/weather?location=‘.$city.‘&output=json&ak=rMyLMFj0NLj6TbKqul7m6Bf6‘; //$json=ihttp_get($url); $w=file_get_contents($url); /* if($json[‘code‘]!=200){ return $this->respText(‘网络连接失败,请重试‘); } */ $weather=json_decode($w,TRUE); //$error1 = $weather[error]; $now = $weather[date];//今天日期 $c=$weather[results][0][currentCity];//城市 $wall=$weather[results][0][weather_data]; $n=count($wall); //第一天 $today=$wall[0][date]; $today_dayPictureUrl = $wall[0][dayPictureUrl]; //白天图片 $today_nightPictureUrl = $wall[0][nightPictureUrl]; //夜晚图片 $today_wind = $wall[0][wind]; //风力 $today_weather = $wall[0][weather]; //气候 $today_temperature = $wall[0][temperature]; //气温 //次日天气 $tomorrow = $wall[1][date]; $tomorrow_dayPictureUrl = $wall[1][dayPictureUrl]; //白天图片 $tomorrow_nightPictureUrl = $wall[1][nightPictureUrl]; //夜晚图片 $tomorrow_wind = $wall[1][wind]; //风力 $tomorrow_weather = $wall[1][weather]; //气候 $tomorrow_temperature = $wall[1][temperature]; //气温 //第三天 $afterTomorrow = $wall[2][date]; $afterTomorrow_dayPictureUrl = $wall[2][dayPictureUrl]; //白天图片 $afterTomorrow_nightPictureUrl = $wall[2][nightPictureUrl]; //夜晚图片 $afterTomorrow_wind = $wall[2][wind]; //风力 $afterTomorrow_weather = $wall[2][weather]; //气候 $afterTomorrow_temperature = $wall[2][temperature]; //气温 //第四天 $fourDay = $wall[3][date]; $fourDay_dayPictureUrl = $wall[3][dayPictureUrl]; //白天图片 $fourDay_nightPictureUrl = $wall[3][nightPictureUrl]; //夜晚图片 $fourDay_wind = $wall[3][wind]; //风力 $fourDay_weather = $wall[3][weather]; //气候 $fourDay_temperature = $wall[3][temperature]; //气温 $news[] = array( ‘title‘ => "$c $now", ‘description‘ =>‘‘, ‘picurl‘ =>‘‘, ‘url‘ =>‘http://zy62.com‘); $news[] = array( ‘title‘ => "$today $today_weather $today_wind $today_temperature", ‘description‘ =>‘‘, ‘picurl‘ => $today_dayPictureUrl, ‘url‘ =>‘http://zy62.com‘); $news[] = array( ‘title‘ => "$tomorrow $tomorrow_weather $tomorrow_wind $tomorrow_temperature", ‘description‘ =>‘‘, ‘picurl‘ => $tomorrow_dayPictureUrl, ‘url‘ =>‘http://zy62.com‘); $news[] = array( ‘title‘ => "$afterTomorrow $afterTomorrow_weather $afterTomorrow_wind $afterTomorrow_temperature", ‘description‘ =>‘‘, ‘picurl‘ => $afterTomorrow_dayPictureUrl, ‘url‘ =>‘http://zy62.com‘); $news[] = array( ‘title‘ => "$fourDay $fourDay_weather $fourDay_wind $fourDay_temperature", ‘description‘ =>‘‘, ‘picurl‘ => $fourDay_dayPictureUrl, ‘url‘ =>‘http://zy62.com‘); return $this->respNews($news); return $this->respText($today_weather); if($rs){ return $this->respText($error); }else{ return $this->respText(‘获取失败‘); } $error=$rs[‘error‘]; return $this->respText($rs);
2.人脸识别:
效果:
<?php /** * 人脸识别模块处理程序 * * @author Rain Tao * @url http://bzy62.com/ */ defined(‘IN_IA‘) or exit(‘Access Denied‘); class FaceModuleProcessor extends WeModuleProcessor { public function respond() { $content = $this->message[‘content‘]; //这里定义此模块进行消息处理时的具体过程, 请查看微擎文档来编写你的代码 $from=$this->message[‘from‘]; $time=$this->message[‘time‘]; $url=$this->message[‘url‘]; $api=‘http://apicn.faceplusplus.com/v2/detection/detect?url=‘.$url.‘&api_secret=OS0BEe0ZxjrQMf9Ii-2YIU2tAz3FJo8U&api_key=9adeceabbf1e730f5729922c97e96698‘; //return $this->respText($api); $rs=ihttp_get($url); if ($rs[‘code‘] == 200 && $rs[‘content‘]){ $info=file_get_contents($api); $arr=json_decode($info,true); $face=$arr[‘face‘]; $nums=count($face); //echo $nums; //echo $face[0][‘attribute‘][‘age‘][‘value‘]; $str=‘‘; $str.=‘照片*有‘.$nums.‘人‘."\n"; for($i=0;$i<$nums;$i++){ if($face[$i][‘attribute‘][‘gender‘][‘value‘]==‘Male‘){ $sex=‘男‘; }else{ $sex=‘女‘; } $str.=‘第‘.($i+1).‘人[‘.$sex.‘]的年龄是‘.$face[$i][‘attribute‘][‘age‘][‘value‘].‘,误差为‘.$face[$i][‘attribute‘][‘age‘][‘range‘]."\n"; } //$type=gettype($face); return $this->respText($str); }else{ return $this->respText(‘请求超时,请重试‘); } } }
3.抓取学校网站新闻:
<?php $msg = $this->message[‘content‘]; // 文本消息内容 $id = $this->message[‘from‘]; // 用户ID $msgid = $this->message[‘msgid‘]; // 消息ID $time = $this->message[‘time‘]; // 消息发送时间 $str=file_get_contents(‘http://zy62.com/news.php‘); $info=json_decode(trim($str,chr(239).chr(187).chr(191)),true); //print_r($info); $news=$info[‘news1‘]; //print_r($news); $result=‘‘; for($i=0;$i<count($news);$i++){ $result.=‘<a href="‘.$news[$i][‘src‘].‘">‘.$news[$i][‘title‘].‘</a>‘."\n\n"; } $result=rtrim($result); return $this->respText($result);
处理部分:
<?php header("Content-type:text/html;charset=utf-8"); require ‘QueryList/QueryList.class.php‘; $url = "http://www.hkxy.edu.cn/"; $reg = array( "title" => array("td>a","text"), "src" => array("td>a","href"), ); //$rang = "[id^=post-]"; $hj = QueryList::Query($url,$reg); //$hj = QueryList::Query($url,$reg,$rang); for($i=0;$i<count($hj->jsonArr);$i++){ //$hj->jsonArr[$i][‘title‘]=html_entity_decode(($hj->jsonArr[$i][‘title‘]),ENT_NOQUOTES,‘utf-8‘); $hj->jsonArr[$i][‘title‘]=str_replace(‘ ‘,‘‘,$hj->jsonArr[$i][‘title‘]); $hj->jsonArr[$i][‘title‘]=iconv(‘gbk‘, ‘utf-8‘, $hj->jsonArr[$i][‘title‘]); $hj->jsonArr[$i][‘src‘]=‘http://www.hkxy.edu.cn‘.$hj->jsonArr[$i][‘src‘]; } //print_r($hj->jsonArr); for($i=0;$i<5;$i++){ $arr[‘news1‘][$i]=$hj->jsonArr[$i]; $arr[‘news2‘][$i]=$hj->jsonArr[$i+17]; $arr[‘news3‘][$i]=$hj->jsonArr[$i+25]; } //print_r($arr); $str=json_encode($arr); function arrayRecursive(&$array, $function, $apply_to_keys_also = false) { static $recursive_counter = 0; if (++$recursive_counter >1000 ) { die(‘possible deep recursion attack‘); } foreach ($array as $key => $value) { if (is_array($value)) { arrayRecursive($array[$key], $function, $apply_to_keys_also); } else { $array[$key] = $function($value); } if ($apply_to_keys_also && is_string($key)) { $new_key = $function($key); if ($new_key != $key) { $array[$new_key] = $array[$key]; unset($array[$key]); } } } $recursive_counter--; } /************************************************************** * * 将数组转换为JSON字符串(兼容中文) * @param array $array 要转换的数组 * @return string 转换得到的json字符串 * @access public * *************************************************************/ function JSON($array) { arrayRecursive($array, ‘urlencode‘, true); $json = json_encode($array); return urldecode($json); } echo JSON($arr); //echo $hj->getJSON();