zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    http
    node 学习 http
    socket.io
    每日日报
    每日日报
    每日日报
    06人件读书笔记之一
    每日日报
    每日日报
    05程序员修炼之道:从小工到专家阅读笔记之三
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/9845294.html
Copyright © 2011-2022 走看看