PHP模拟登录发送闪存

url,post,cookie。

有这三种就可以了。

下面使用Postman模拟发送。

其中,body中是post参数,header中是cookie数据。

下面是php模拟代码。

public function test_flash() {
        $url = 'https://ing.cnblogs.com/ajax/ing/Publish';

        $param = [
            'content' => '为了防止各位沉迷刷星,本人耗时一年写了一个脚本,会每5分钟提醒各位好好敲(写)代(b)码(ug)。 ',
            'publicFlag' => 1
        ];

        $cookie = 'xxx';

        $result = json_decode(Http::doPostCookie($url,$param,$cookie),true);
        dump($result);
}
static public function doPostCookie($url, $data = array(),$cookie = '', $timeout = 5) {
        $ch = curl_init();
        if (is_array($data) && $data) {
            $formdata = http_build_query($data);
            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $formdata);
        }
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
        curl_setopt($ch,CURLOPT_COOKIE,$cookie);
        $result = curl_exec($ch);
        curl_close($ch);
        return $result;
}
array(2) {
  ["isSuccess"] => bool(true)
  ["responseText"] => string(4) "为了防止各位沉迷刷星,本人耗时一年写了一个脚本,会每5分钟提醒各位好好敲(写)代(b)码(ug)。 "
}

下面写一个定时任务!

*/6 * * * * cd /home/wwwroot/default/ssy/mouse/Public && /usr/bin/php cron.php Test/flash >> /tmp/ssy_flash.log 2>&1

下面是doGet

static public function doGetCookie($url, $data = array(),$cookie = '', $timeout = 5) {
        $pairs = array();
        foreach ($data as $key => $val) {
            array_push($pairs, $key . '=' . urlencode($val));
        }
        $url_prefix = join('&', $pairs);
        $url=$url.'?'.$url_prefix;
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
        curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
        curl_setopt($ch,CURLOPT_COOKIE,$cookie);
        $result = curl_exec($ch);
        curl_close($ch);
        return $result;
}
posted @ 2018-10-24 18:23  TBHacker  阅读(303)  评论(1编辑  收藏  举报