吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2949|回复: 1
收起左侧

[会员申请] 申请会员ID:siwer14

[复制链接]
吾爱游客  发表于 2017-2-20 17:40
1、申 请 I D:siwer14
2、个人邮箱:ergeserfsf@163.com
3、原创技术文章:

微信公众账号开发

[PHP] 纯文本查看 复制代码
define("TOK", "*");
$wcObj = new wcCallapiTest();
if (isset($_GET['echostr']))
{
    $wcObj->valid();
}else
{
    $wcObj->resMsg();
}
class wcCallapiTest{
    public function valid(){
        $echoStr = $_GET["echostr"];
        if($this->checkSig()){
            echo $echoStr;
            exit;
        }
    }
    private function checkSig(){
        $sig = $_GET["sig"];
        $time = $_GET["time"];
        $nonce = $_GET["nonce"];
 
        $token = TOK;
        $tmpArr = array($token, $time, $nonce);
        sort($tmpArr);
        $tmpStr = implode( $tmpArr );
        $tmpStr = sha1( $tmpStr );
 
        if( $tmpStr == $sig ){
            return true;
        }else{
            return false;
        }
    }
    public function resMsg(){
        $postStr = $GLOBALS["HTTP_RAW_POST_DATA"];
                $time = time();
        if (!empty($postStr)){
            $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
            $Username = $postObj->UserName;
            $toUsername = $postObj->ToUserName;
            $keyword = trim($postObj->Content);
            if($postObj->Event=="subscribe"){
                                $textTpl = "<xml>
                <ToUserName><![CDATA[%s]]></ToUserName>
                <UserName><![CDATA[%s]]></UserName>
                <CreateTime>%s</CreateTime>
                <MsgType><![CDATA[%s]]></MsgType>
                <Content><![CDATA[%s]]></Content>
                <FuncFlag>%d</FuncFlag>
                </xml>";
                                $msgType="text";
                                $content="已关注";                                
                                $resultStr = sprintf($textTpl, $Username, $toUsername, time(),$msgType, $content,$flag);
                                echo $resultStr;
                        }elseif($keyword){
                                if (strstr($keyword,"您好") || strstr($keyword,"您好") || strstr($keyword,"是否在线") || strstr($keyword,"在线") || strstr($keyword,"Hi") || strstr($keyword,"无人在") || strstr($keyword,"无人在线") || strstr($keyword,"?")){                                                
                                        $textTpl = "<xml>
                                        <ToUserName><![CDATA[%s]]></ToUserName>
                                        <UserName><![CDATA[%s]]></UserName>
                                        <CreateTime>%s</CreateTime>
                                        <MsgType><![CDATA[%s]]></MsgType>
                                        <Content><![CDATA[%s]]></Content>
                                        </xml>";
                                        $content='有什么问题请提问';
                                        $msgType="text";
                                        echo $resultStr = sprintf($textTpl, $Username, $toUsername, time(),$msgType,$content);
                                }elseif (substr($keyword,-6)=='天气'){
                                        $items=1;
                                        $data=crawl_weather($keyword);
                                        $picTplhead = "<xml>
                                        <ToUserName><![CDATA[%s]]></ToUserName>
                                        <UserName><![CDATA[%s]]></UserName>
                                        <CreateTime>%s</CreateTime>
                                        <MsgType><![CDATA[news]]></MsgType>
                                        <ArticleCount><![CDATA[%s]]></ArticleCount>
                                        <Articles>";
                                        $picTpl = "<item>
                                        <Title><![CDATA[%s]]></Title>
                                        <Description><![CDATA[%s]]></Description>
                                        <PicUrl><![CDATA[%s]]></PicUrl>
                                        <Url><![CDATA[%s]]></Url>
                                        </item>";
                                        $picTplfoot = "</Articles>
                                        <FuncFlag>0</FuncFlag>
                                        </xml>";
                                        $resultStrhead = sprintf($picTplhead, $Username, $toUsername, time(), 4);
                                        $i=1;
                                        if (count($data)){
                                                foreach($data as $f){
                                                        $title=$f["date"]."\r\n".$f["temp"].' '.$f["weather"].' '.$f["wind"];
                                                        $description=$f["Weather"].$f["wind"];
                                                        $imageurl=($i==1?'':$f["dayPictureUrl"]);
                                                        $resultpictpl .= sprintf($picTpl,$title,$description,$imageurl,'');
                                                        $i++;
                                                }
                                                $resultpictplfoot = sprintf($picTplfoot);
                                                echo $resultStr = $resultStrhead.$resultpictpl.$resultpictplfoot;
                                        }else{
                                                $textTpl = "<xml>
                                                <ToUserName><![CDATA[%s]]></ToUserName>
                                                <UserName><![CDATA[%s]]></UserName>
                                                <CreateTime>%s</CreateTime>
                                                <MsgType><![CDATA[text]]></MsgType>
                                                <Content><![CDATA[%s]]></Content>
                                                <FuncFlag>%d</FuncFlag>
                                                </xml>";
                                                $content="搜不到[".str_replace("天气","",$keyword).']天气!';
                                                $resultStr = sprintf($textTpl, $Username, $toUsername, time(),$content,$flag);
                                                echo $resultStr;
                                        }
                                }else{
                                        $xml=crawlContent($keyword,"search");
                                        $xmlArr=xml_to_array($xml);
                                        $items=count($xmlArr["pre"]);
                                        if ($items){
                                                $picTplhead = "<xml>
                                                <ToUserName><![CDATA[%s]]></ToUserName>
                                                <UserName><![CDATA[%s]]></UserName>
                                                <CreateTime>%s</CreateTime>
                                                <MsgType><![CDATA[news]]></MsgType>
                                                <ArticleCount><![CDATA[%s]]></ArticleCount>
                                                <Articles>";
                                                $picTpl = "<item>
                                                        <Title><![CDATA[%s]]></Title>
                                                        <Description><![CDATA[%s]]></Description>
                                                        <PicUrl><![CDATA[%s]]></PicUrl>
                                                        <Url><![CDATA[%s]]></Url>
                                                        </item>";
                                                $picTplfoot = "</Articles>
                                                        <FuncFlag>0</FuncFlag>
                                                        </xml>";
                                                $tickets_count=$items>=7?1:$items;
                                                $resultStrhead = sprintf($picTplhead, $Username, $toUsername, time(), $tickets_count+1);
                                                if ($items>=7){
                                                        foreach($xmlArr as $k=>$f){
                                                                $title=$f["title"];
                                                                $description=$f["desc"];
                                                                $image=$f["picurl"];
                                                                $url=$f["url"];
                                                                $resultpictpl .= sprintf($picTpl,$title,$description,$image,$url);
                                                        }
                                                }elseif($items<7 && $items>0){
                                                        foreach($xmlArr as $k=>$f){
                                                                if (strlen($f["url"])>0){
                                                                        $resultStrhead = sprintf($picTplhead, $Username, $toUsername, time(), 2);
                                                                        $title='['.$f["type"].']'.$f["title"];
                                                                        $description=$f["desc"];
                                                                        $image=$f["picurl"];
                                                                        $url=$f["url"];
                                                                        $resultpictpl .= sprintf($picTpl,$title,$description,$image,$url);
                                                                }else{
                                                                        foreach($f as $k=>$list){
                                                                                $title='['.$list["type"].']'.$list["title"];
                                                                                $description=$list["desc"];
                                                                                $image=$list["picurl"];
                                                                                $url=$list["url"];
                                                                                $resultpictpl .= sprintf($picTpl,$title,$description,$image,$url);
                                                                        }
                                                                }
                                                        }
                                                }
                                                $title="没有查到相关信息?\r\n请点击此处[".$keyword."]!";
                                                $description='';
                                                $image='[img]http://test.test/test.png[/img]';
                                                $url='http://test.test/search?q='.$keyword;
                                                $resultpictpl .= sprintf($picTpl,$title,$description,$image,$url);
                                                 
                                                $resultpictplfoot = sprintf($picTplfoot);
                                                echo $resultStr = $resultStrhead.$resultpictpl.$resultpictplfoot;
                                        }
                                }                                
            }
        }else{
                        echo "已关注";
            exit;
        }
    }
}
function crawlContent($keyword,$act){
        $url="http://test.test/search?q=?key=$keyword";
        //如下
        /*
        $html.='<?xml version="1.0" encoding="UTF-8"?><route>';
        for ($i=0;$i<=8;$i++){
                $url='<url>URL</url>';
                $picurl='<picurl>URL</picurl>';
                $title='<title>Head</title>';
                $desc='<desc>Description</desc>';
                $html.='<pre>';
                $html.=$url.$picurl.$title.$desc;
                $html.='</pre>';
        }
        $html.='</route>';
        echo $html;*/
        $ch=curl_init();
        curl_setopt($ch,CURLOPT_URL,$url);
        curl_setopt($ch,CURLOPT_HEADER,0);
        curl_setopt($ch,CURLOPT_TIMEOUT,30);
        curl_setopt($ch,CURLOPT_NOBODY,0);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch,CURLOPT_POST,0);
        curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/6.0 (Windows NT 6.2) AppleWebKit/547.12 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/538.12');
        $html=curl_exec($ch);
        curl_close($ch);
        return $html;
}
function xml_to_array($xml){
        $array = (array)(simplexml_load_string($xml));
        foreach ($array as $key=>$item){
                $array[$key]  =  struct_to_array((array)$item);
        }
        return $array;
}
function struct_to_array($item){
        if(!is_string($item)) {
                $item = (array)$item;
                foreach ($item as $key=>$val){
                        $item[$key]  =  struct_to_array($val);
                }
        }           
        return $item;
}
function crawl_weather($keyword){
        $ch=curl_init();
        $headurl='http://test.test/weather?location='.str_replace("天气","",$keyword).'&output=json&ak=ak';
        curl_setopt($ch,CURLOPT_URL,$headurl);
        curl_setopt($ch,CURLOPT_HEADER,0);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
        $data=curl_exec($ch);
        curl_close($ch);
        $data=json_decode($data,true);
        return $data["results"][0]["weather_data"];
}





发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

Hmily 发表于 2017-2-21 10:24
抱歉,未能达到申请要求,申请不通过,可以关注论坛官方微信(吾爱破解论坛),等待开放注册通知。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-15 17:30

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表