微度云课堂

由于现在人们搜索的公交查询和火车票余票查询,所以今天的视频我就做了这个就是专门的介绍和讲解公交查询--捎带的说了火车票余票查询的功能,当然视频的代码就在我的博客里边http://yun.widuu.com/archives/07/733.html
ABclinet.php多加的方法
public function test_transfer($city,$start,$end) {
	$result = list($code, $arr) = $this->getBusTransfer($city, array("start_addr" => $start, "end_addr" => $end));
	return $result[1]['buses']["bus"];
}
使用中会出现Missing argument 1 for ABClient::test_transfer(), 这个问题我们注释掉$a = $this->model->test_transfer();这是因为test_transfer()没有传参的原因
 public function __construct(){
        $this->model = new ABClient();
        //$a = $this->model->test_transfer();
        $this->name = include("name.php");
    }

视频的完整代码widuu.php
include("ABClient.php");
include("express.php");
define("APIKEY","TBSUOFdvHEWaabpBd9g5prtE");
define("TOKEN", "xiaolvge");
/*
$a = new Express();
$result = $a->getorder("圆通","9149223354");
var_dump($a);
*/
$wechatObj = new wechatCallbackapiTest();
$wechatObj->responseMsg();

class wechatCallbackapiTest
{
	public function valid()
    {
        $echoStr = $_GET["echostr"];

        //valid signature , option
        if($this->checkSignature()){
        	echo $echoStr;
        	exit;
        }
    }

    public function responseMsg()
    {
		//get post data, May be due to the different environments
		$postStr = $GLOBALS["HTTP_RAW_POST_DATA"];

      	//extract post data
		if (!empty($postStr)){
                
              	$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
                $fromUsername = $postObj->FromUserName;
                $toUsername = $postObj->ToUserName;
				$MsgType = $postStr->MsgType;
				$event 	= $postStr->Event;
                $keyword = trim($postObj->Content);
                $time = time();
                $textTpl = "<xml>
							<ToUserName><![CDATA[%s]]></ToUserName>
							<FromUserName><![CDATA[%s]]></FromUserName>
							<CreateTime>%s</CreateTime>
							<MsgType><![CDATA[%s]]></MsgType>
							<Content><![CDATA[%s]]></Content>
							<FuncFlag>0</FuncFlag>
							</xml>";  
				$imageTpl = " <xml>
							<ToUserName><![CDATA[%s]]></ToUserName>
							<FromUserName><![CDATA[%s]]></FromUserName>
							<CreateTime>%s</CreateTime>
							<MsgType><![CDATA[%s]]></MsgType>
							<ArticleCount>%s</ArticleCount>
							<Articles>
							<item>
							<Title><![CDATA[%s]]></Title> 
							<Description><![CDATA[%s]]></Description>
							<PicUrl><![CDATA[%s]]></PicUrl>
							<Url><![CDATA[%s]]></Url>
							</item>
							<item>
							<Title><![CDATA[%s]]></Title> 
							<Description><![CDATA[%s]]></Description>
							<PicUrl><![CDATA[%s]]></PicUrl>
							<Url><![CDATA[%s]]></Url>
							</item>
							</Articles>
							</xml>";
				if($MsgType == "event" && $event =="subscribe")
                {
              		$msgType = "text";
                	$contentStr = "欢迎您关注我的微信‘微度云课堂’";
                	$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
                	echo $resultStr;
                }else if(!empty($keyword)){
					$data = explode("+",$keyword);
					if(isset($data[1])&&empty($data[2])){
						$msgType = "text";
						$contentStr =$this->fanyi($data[1]);
						$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
						echo $resultStr;
					}else if(isset($data[2])){
						$bus = new ABClient();
						$keywords = explode("+",$keyword);
						$city = $keywords[0];
                        $start = $keywords[1];
                        $end =$keywords[2];
                        $a = $bus->test_transfer($city,$start,$end);
						//var_dump($a);
                        if(!empty($a)){
                             foreach($a as $k=>$v){
                                $contentStr.= "线路{$c}:".$v['dist']."米。估计耗费时间:{$v['time']}分钟。\n乘车线路:{$v['segments']["segment"][0]["line_name"]}。\n上车地点:{$v['segments']["segment"][0]["start_stat"]}。\n下车地点:{$v['segments']["segment"][0]["end_stat"]}。\n经过路线:{$v['segments']["segment"][0]["stats"]}\n\n";
                                if($k == 4){
                                    break;
                                }
                            }
						}else{
							$contentStr="没有公交";
						}
						
						$msgType = "text";
						$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
						echo $resultStr;
						
					}else{
						preg_match_all("/(\d+)$/",$keyword,$data);
						$order = $data[0][0];
						$odername = trim($keyword,$order);
						$result = array_key_exists($odername,$this->expressname);
						if($result){
							$a = new Express();
							$result = $a->getorder($odername,$order);
							if($result["message"] !== "ok"){
								$contentStr="您查询的快递单号不存在";
							}else{
								foreach ($result["data"] as $key => $value) {
									$contentStr.= $value['ftime']."快递".$value['context']."\n";
								}
								if($result["ischeck"]==1){
									$contentStr.="您的快递已经查收";
								}else{
									$contentStr.="您的快递还未查收";
								}
							}
							$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
							echo $resultStr;
						}else{
						
							if($keyword == "苍老师"){
							$msgType = "news";
							$ArticleCount = 2;
							$title = "苍老师";
							$description = "注明的日本女优,宅男最爱";
							$pic = "http://www.365rzf.com/1.jpg";
							$url = "http://www.365rzf.com/archives/39.html";
							$title1 = "美女美女美女美女美女美女";
							$description1 = "注明的日本女优,宅男最爱";
							$pic1 = "http://www.365rzf.com/2.png";
							$url1 = "http://www.365rzf.com/archives/39.html";
							$resultStr = sprintf($imageTpl, $fromUsername, $toUsername, $time, $msgType,$ArticleCount,$title,$description,$pic,$url,$title1,$description1,$pic1,$url1);
						}else{
							$msgType = "text";
							$contentStr =$this->xiaoHuang($keyword);
							$resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
						}
						
						echo $resultStr;
						}
						
					}
					
				}else{
                	echo "Input something...";
                }

        }else {
        	echo "";
        	exit;
        }
    }
	private function fanyi($data){
		$url ="http://openapi.baidu.com/public/2.0/bmt/translate?client_id=".APIKEY."&q={$data}&from=auto&to=auto";
		$result = file_get_contents($url);
		$rdata = json_decode($result,true);
		return $rdata['trans_result'][0]["dst"];
	}	
	
	private function xiaoHuang($data){
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, "http://www.xiaohuangji.com/ajax.php");
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POSTFIELDS,array('para'=>$data));
		// 抓取URL并把它传递给浏览器
		$content = curl_exec($ch);
		// 关闭cURL资源,并且释放系统资源
		curl_close($ch);
		return $content;
	}
	private function checkSignature()
	{
        $signature = $_GET["signature"];
        $timestamp = $_GET["timestamp"];
        $nonce = $_GET["nonce"];	
        		
		$token = TOKEN;
		$tmpArr = array($token, $timestamp, $nonce);
		sort($tmpArr);
		$tmpStr = implode( $tmpArr );
		$tmpStr = sha1( $tmpStr );
		
		if( $tmpStr == $signature ){
			return true;
		}else{
			return false;
		}
	}
}
大家自己多动手,谢谢代码,然后不懂得可以留言哈

点赞(1) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部