• Curl函数


    <?php
    define('ROUTE_ROOT','');
    define('ROUTE_PASSWORD','');
    define('ROUTE_URL','');
    define('COOKIE_FILE','cookie_file.txt');
    define('TiYanShiJian','30');
    define('ADMIN_PHONE','0571-83055016');
    $time=time();
    $ddate=$time+TiYanShiJian*60;
    header("Content-Type:text/html;charset=UTF-8");
    //require("config.php");
    //封装登陆函数
    function curl_tijiao($tijiao_url,$zhuce_data,$access,$callback){
        $cookie_file = dirname(__FILE__).'/'.COOKIE_FILE;
        $post_fields = 'user='.ROUTE_ROOT.'&password='.ROUTE_PASSWORD;
    
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $tijiao_url);
        curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        if ($access==true){
            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($zhuce_data));
            curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
        }
        curl_setopt($ch, CURLOPT_ENCODING, "");
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        $return = curl_exec($ch);
        $tishi_json = iconv("GB2312","UTF-8",$return);
        //var_dump($zhuce_url);
        //var_dump($post_fields);
        curl_close($ch);
        if (strpos($tishi_json,'{pppoe_client') !== false) {
            //return $tishi_json;
            echo $callback."({ret:0,msg:'亲,你别看!行么?'})";
        }else if (strpos($tishi_json,'{err') !== false) {
            echo $callback.'('.$tishi_json.')';
        }else{
            if ($access==true){
                $login_url = ROUTE_URL.'login.cgi';
                $ch = curl_init($login_url);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
                curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
                curl_exec($ch);
                curl_close($ch);
            }
            //return error_msg('路由连接失败!');
            echo $callback."({ret:1,msg:'参数错误!或没有申请到key!支持Ajax跨域提交!详细QQ:264059790'})";
        }
        //curl_close($ch);
    }
    //封装登陆函数结束
    //开始获取参数
    
    $callback = isset($_REQUEST['callback']) ? trim($_REQUEST['callback']) : '';
    $Mob = isset($_REQUEST['Mob']) ? trim($_REQUEST['Mob']) : '';
    $realname="zhouein";
    $cellphone="0571-83055016";
    $mem="beizhu>>".$realname.">>".$cellphone;
    $tijiao_url=ROUTE_URL.'/user.asp';
    $zhuce_data = array(
             'user' => '15336500025',
             'pwd' => '15336500025',
             'ddate' => '1479138600',
             'mem' => 'beizhu>>zhouein>>83055016',
             'num' => '1',
             'vlan' => '0',
             'state' => '96',
             'gid' => '0',
             'speed_mode' => 'dl',
             'speed_up' => '20',
             'speed_down' => '500',
             'mod_pwd' => '0',
             'opt' => 'add',
             );
             
        $zhuce_data['user']=$Mob;
        $zhuce_data['pwd']=$Mob;
        $zhuce_data['mem']=$mem;
        $zhuce_data['ddate']=$ddate;
        $zhuce_data['_']=$time;
        $return = curl_tijiao($tijiao_url,$zhuce_data,true,$callback);
    ?>
    View Code

    客户端

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
        <html>  
        <head>  
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
        <title>Ajax Jsonp</title>  
        <script type="text/javascript" src="http://lib.sinaapp.com/js/jquery/1.7.2/jquery.min.js"></script>  
        </head>  
        <script type="text/javascript">  
        $(function(){     
            $.ajax({  
                type : "GET",  
                async:false,  
                url : "http://www.zhouein.com/wayos_api/function.php",  
                dataType : "jsonp",
                data:{
                      Mob:"15967128951",
                      mykey:"222",
                      mystr:"ggg"
                      },
                jsonp: "callback",
                jsonpCallback:"zhouein",
                success : function(data){  
                    $("#showcontent").text(data.msg)
                    $("#showcontent").text(data.err)                
                },  
                error:function(){  
                    alert('no!');  
                }  
            });   
        });  
        </script>  
        <body>  
        <div id="showcontent">ddddddddddddddddddd:</div>
        <!--http://115.236.183.115:81/php_encode/?act=ENCODE&mykey=222&mystr=ggg&callback=kkkk-->
        </body>  
        </html>  
  • 相关阅读:
    python基础易错题
    经典案例题2
    经典案例题1
    Http和Https的区别
    爬虫过程中需要注意的问题
    [转]项目规模估计方法介绍
    [转]23种设计模式总结
    [转]分布式session的几种实现方式
    [转]Redis哨兵模式(sentinel)学习总结及部署记录(主从复制、读写分离、主从切换)
    [转]【Linux】Linux 目录结构
  • 原文地址:https://www.cnblogs.com/zhouein/p/5962667.html
Copyright © 2020-2023  润新知