说说自定义尾巴爬虫

代码:

<?php
    header("Access-Control-Allow-Origin: *");
    function curlReq($url, $post = false, $data = array(), $headers = array(), $resp = 0, $timeout = 10, $CA = true) {
        $cacert = getcwd() . '/cacert.pem';
        $SSL = substr($url, 0, 8) == "https://" ? true : false;
        $cookie_file = dirname(__FILE__)."/data.cookie";
        $ch = curl_init();
        @curl_setopt($ch, CURLOPT_URL, $url);
        if ($resp == 0) {
            @curl_setopt($ch, CURLOPT_HEADER, false);
        } else {
            @curl_setopt($ch, CURLOPT_HEADER, true);
        }
        @curl_setopt($ch, CURLOPT_FAILONERROR, false);
        @curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
        @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout - 2);
        if ($SSL && $CA) {
            @curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
            @curl_setopt($ch, CURLOPT_CAINFO, $cacert);
        } else if ($SSL && !$CA) {
            @curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        }

        @curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12A365 MicroMessenger/5.4.1 NetType/WIFI');

        $ip = '49.86'.'.'.rand(1, 255).'.'.rand(1, 255);
        $headers[] = 'CLIENT-IP: '.$ip;

        @curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        @curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);

        @curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
        @curl_setopt($ch, CURLOPT_COOKIEJAR,  $cookie_file);

        if ($post) {
            @curl_setopt($ch, CURLOPT_POST, true);
            @curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
        }
        ob_start();
        $ret = curl_exec($ch);
        $content = ob_get_contents();
        ob_end_clean();
        $rescode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

        curl_close($ch);
        return $content;
    }
    if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') {
        try {
            $required_areas = [
                'qq' => 'QQ', 'sid' => 'SID', 'sname' => '机型', 'content' => '内容',
            ];
            foreach ($required_areas as $required_area => $required_area_text) {
                if (!isset($_POST[$required_area]) || empty($_POST[$required_area])) {
                    $alert_message = '请填写 '.$required_area_text.' 字段';
                    throw new exception('alert-danger');
                }
            }
            $publish_url = 'http://m.qzone.com/mood/publish_mood';
            $post = [
                'content' => $_POST['content'],
                'sid' => $_POST['sid'],
                'lon' => '',
                'lat' => '',
                'lbsid' => '',
                'res_uin' => $_POST['qq'],
                'richval' => '',
                'source_name' => $_POST['sname'],
                'is_winphone' => '2',
                'opr_type' => 'publish_shuoshuo',
                'format' => 'json',
                'issyncweibo' => '0',
            ];
            $result = curlReq($publish_url, true, $post);
            if (!$result) {
                $alert_message = '与空间服务器的通信异常。';
                throw new exception('alert-danger');
            }
            $res = json_decode($result, true);
            if (!$res || !isset($res['code']) || !isset($res['subcode']) || !isset($res['message'])) {
                $alert_message = '发布状态无效。';
                throw new exception('alert-danger');
            }
            if ($res['code'] == 0) {
                $alert_message = '说说发表成功,请在手机空间客户端查看效果!';
                throw new exception('alert-success');
            } else {
                $alert_message = '说说发表失败!<br />错误代码:'.(int)$res['code'].' ('.(int)$res['subcode'].')<br />错误信息:'.htmlspecialchars($res['message']);
                throw new exception('alert-danger');
            }
        } catch (exception $e) {
            $alert = true;
            $alert_type = $e->getMessage();
        }
    }
?>
<html lang="zh-cn">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="format-detection" content="telephone=no">
        <meta name="viewport" content="minimum-scale=1.0, width=device-width, maximum-scale=0.6667, user-scalable=no" />
        <meta name="HandheldFriendly" content="true" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="robots" content="index, follow" />
        <meta name="title" content="82Flex" />
        <meta name="description" content="每一个平凡的日常,都是连续发生中的奇迹。" />
        <meta name ="keywords" content="typecho,php,blog" />
        <base target="_top">
        <title>说说自定义尾巴工具</title>
        <link rel="shortcut icon" href="favicon.ico">
        <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.2.0/css/bootstrap.css">
    </head>
    <body>
        <div class="container">
            <div class="page-header">
                <div style="display: inline;">
                    <h1>说说自定义尾巴工具</h1>
                </div>
            </div>
<?php if (isset($alert)): ?>
            <div class="alert <?= $alert_type ?> alert-dismissible" role="alert">
                <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <?= $alert_message ?>
            </div>
<?php endif; ?>
            <form method="post" enctype="multipart/form-data" class="form-horizontal">
                <div class="form-group">
                    <label for="qq" class="col-sm-2 control-label">QQ 号码</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" name="qq" value="" required />
                    </div>
                </div>
                <div class="form-group">
                    <label for="sid" class="col-sm-2 control-label">SID</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" name="sid" value="" required />
                    </div>
                </div>
                <div class="form-group">
                    <label for="sname" class="col-sm-2 control-label">机型</label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" name="sname" value="" placeholder="iPhone 6 Plus" required />
                    </div>
                </div>
                <div class="form-group">
                    <label for="content" class="col-sm-2 control-label">内容</label>
                    <div class="col-sm-10">
                        <textarea class="form-control" name="content" rows="8" placeholder="2015 © 82Flex Studio. All Rights Reserved." required></textarea>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-2"></div>
                    <div class="col-sm-10">
                        <input type="submit" class="btn btn-primary btn-block" name="submit" value="发布">
                    </div>
                </div>
            </form>
        </div>
    </body>
</html>

资源 转载自82flex
下载地址:

php-qzone.zip (138.6 KB, 下载次数: 541, 最后修改: 2015-11-24 02:27)

添加新评论

返回顶部