Пример #1
0
function wikiLogin()
{
    global $login;
    global $wikilogin;
    global $snoopy;
    global $wikiapi_url;
    while (!$login) {
        $wikilogin['action'] = 'login';
        $wikilogin['lgname'] = trim(ask('wiki user name'));
        $wikilogin['lgpassword'] = getPassword('wikis');
        $wikilogin['format'] = 'php';
        if (!$snoopy instanceof Snoopy) {
            $snoopy = new Snoopy();
        }
        if (!$snoopy->submit($wikiapi_url, $wikilogin)) {
            I2CE::raiseError("Could not log in to {$wikiapi_url}");
            continue;
        }
        $res = unserialize($snoopy->results);
        if (array_key_exists('error', $res)) {
            I2CE::raiseError("Could not login:\n" . print_r($res['error'], true));
            continue;
        }
        if (!array_key_exists('login', $res) || !is_array($res['login']) || !array_key_exists('result', $res['login'])) {
            I2CE::raiseError("Error logging in:" . print_r($res, true));
            continue;
        }
        if ($res['login']['result'] == 'NeedToken' && array_key_exists('token', $res['login']) && $res['login']['token']) {
            $wikilogin['lgtoken'] = $res['login']['token'];
            $snoopy->setcookies();
            if (!$snoopy->submit($wikiapi_url, $wikilogin)) {
                I2CE::raiseError("Could not log in to {$wikiapi_url}");
                continue;
            }
            $res = unserialize($snoopy->results);
            if (array_key_exists('error', $res)) {
                I2CE::raiseError("Could not login:\n" . print_r($res['error'], true));
                continue;
            }
            if (!array_key_exists('login', $res) || !is_array($res['login']) || !array_key_exists('result', $res['login'])) {
                I2CE::raiseError("Error logging in");
                continue;
            }
        }
        if ($res['login']['result'] != 'Success') {
            I2CE::raiseError("No success logging in:" . print_r($res, true));
            continue;
        }
        I2CE::raiseError("Logged into {$wikiapi_url} as " . $wikilogin['lgname']);
        $snoopy->setcookies();
        $login = true;
    }
    return $login;
}
Пример #2
0
function sso_user_login($username, $password)
{
    global $CFG, $SESSION;
    include $CFG->libdir . '/snoopy/Snoopy.class.inc';
    if (empty($CFG->hivehost)) {
        return false;
        // Hive config variables not configured yet
    }
    /// Set up Snoopy
    $snoopy = new Snoopy();
    $submit_url = $CFG->hiveprotocol . '://' . $CFG->hivehost . ':' . $CFG->hiveport . '' . $CFG->hivepath;
    $submit_vars['HIVE_UNAME'] = $username;
    $submit_vars['HIVE_UPASS'] = $password;
    $submit_vars['HIVE_ENDUSER'] = $username;
    $submit_vars['HIVE_REQ'] = '2112';
    $submit_vars['HIVE_REF'] = 'hin:hive@API Login 3';
    $submit_vars['HIVE_RET'] = 'ORG';
    $submit_vars['HIVE_REM'] = '';
    $submit_vars['HIVE_PROD'] = '0';
    $submit_vars['HIVE_USERIP'] = getremoteaddr();
    /// We use POST to call Hive with a bit more security
    $snoopy->submit($submit_url, $submit_vars);
    /// Extract HIVE_SESSION from headers
    foreach ($snoopy->headers as $header) {
        if (strpos($header, 'HIVE_SESSION=') !== false) {
            $header = explode('HIVE_SESSION=', $header);
            if (count($header) > 1) {
                $cookie = explode(';', $header[1]);
                $cookie = $cookie[0];
                $SESSION->HIVE_SESSION = $cookie;
                return true;
            }
        }
    }
    /// Try again with the guest username and password
    $submit_vars['HIVE_UNAME'] = $CFG->hiveusername;
    $submit_vars['HIVE_UPASS'] = $CFG->hivepassword;
    $submit_vars['HIVE_ENDUSER'] = $CFG->hiveusername;
    $snoopy->submit($submit_url, $submit_vars);
    foreach ($snoopy->headers as $header) {
        if (strpos($header, 'HIVE_SESSION=') !== false) {
            $header = explode('HIVE_SESSION=', $header);
            if (count($header) > 1) {
                $cookie = explode(';', $header[1]);
                $cookie = $cookie[0];
                $SESSION->HIVE_SESSION = $cookie;
                return true;
            }
        }
    }
    return false;
    // No cookie found
}
 private function renew()
 {
     $postArray = array('action' => 'Renew', 'book_barcode' => preg_match('/\\//', $this->bookID) ? $this->bookID : urlencode($this->bookID), 'department_id' => $this->deptID, 'library_id' => $this->libraryID);
     print_r($postArray);
     $studentData;
     $url = 'http://202.197.232.4:8081/opac_two/reader/jieshuxinxi.jsp';
     $snoopy = new Snoopy();
     $snoopy->rawheaders['Cookie'] = $this->cookies;
     $snoopy->submit($url, $postArray);
     if ($snoopy->status != 200) {
         return $this->setMsg(3);
     }
     $data = iconv('gbk', 'utf-8', $snoopy->results);
     if (preg_match('/续借成功/', $data)) {
         return $this->setMsg(0);
     } else {
         if (preg_match('/现已续借/', $data)) {
             return $this->setMsg(6);
         } else {
             if (preg_match('/读取续借规则错误/', $data)) {
                 return $this->setMsg(7);
             } else {
                 return $this->setMsg(4);
             }
         }
     }
 }
function socialdiscuss_http_post($link, $body)
{
    if (!$link) {
        return array(500, 'Invalid Link');
    }
    require_once ABSPATH . WPINC . '/class-snoopy.php';
    $snoop = new Snoopy();
    if ($snoop->submit($link, $body)) {
        if (strpos($snoop->response_code, '200')) {
            $response = $snoop->results;
            return array(200, $response);
        }
    }
    if (!class_exists('WP_Http')) {
        include_once ABSPATH . WPINC . '/class-http.php';
    }
    if (!class_exists('WP_Http')) {
        return array(500, $snoop->response_code);
    }
    $request = new WP_Http();
    $response_full = $request->request($link, array('method' => 'POST', 'body' => $body, 'headers' => $headers));
    if (isset($response_full->errors)) {
        return array(500, 'Unknown Error');
    }
    $response_code = $response_full['response']['code'];
    if ($response_code === 200) {
        $response = $response_full['body'];
        return array($response_code, $response);
    }
    $response_msg = $response_full['response']['message'];
    return array($response_code, $response_msg);
}
Пример #5
0
/**
 * 学校验证
 * @method getName
 * @param  [type]  $stu_number [学号]
 * @param  [type]  $pwd        [密码]
 * @return [string/bool]              [验证成功返回姓名,验证失败返回false]
 * @author NewFuture[newfuture@yunyin.org]
 */
function getName($stu_number, $pwd)
{
    /*基本信息*/
    $ACTION_URL = 'http://jw.tifert.edu.cn/2003/Logon.do?method=logon';
    $INFO_URL = 'http://jw.tifert.edu.cn/2003/framework/main.jsp';
    $SUCCESS_KEY = '<script language=\'javascript\'>window.location.href=\'http://jw.tifert.edu.cn/2003/framework/main.jsp\';</script>';
    $START_FALG = '当前用户:';
    $END_FLAG = '</td>';
    $snoopy = new Snoopy();
    /*设置请求头,非必需 */
    $snoopy->referer = 'http://jw.tifert.edu.cn/2003/';
    $snoopy->rawheaders['Pragma'] = 'no-cache';
    $snoopy->rawheaders['X_FORWARDED_FOR'] = get_client_ip();
    /*用户学号和密码*/
    $input['USERNAME'] = $stu_number;
    $input['PASSWORD'] = $pwd;
    //模拟登陆
    $snoopy->submit($ACTION_URL, $input);
    $result = $snoopy->results;
    //登录结果页面
    if (strpos($result, $SUCCESS_KEY) === false) {
        /*验证失败*/
        return false;
    } else {
        /*登录成功,保存cookie信息页面抓取信息*/
        $snoopy->setcookies();
        $snoopy->fetch($INFO_URL);
        $results = $snoopy->results;
        $s = strpos($results, $START_FALG) + strlen($START_FALG);
        //起始位置
        $e = strpos($results, $END_FLAG, $s);
        $name = substr($results, $s, $e - $s);
        return trim($name);
    }
}
Пример #6
0
 /**
  * @param $url
  * @param $post_data
  * @return mixed|null
  */
 public static function post($url, array $post_data)
 {
     //因线上PHP版本为5.5所以移到此处
     $host2 = array('account/register.json', 'bankBranch/select/branch.json', 'account/bank/list.json', 'account/bankcard/bind.json', 'user/identity/auth.json', 'loginRest/getUserCenterInfo.json', 'account/bankcard/modify.json');
     $post_data['_ts'] = time();
     $post_data['token'] = self::TOKEN;
     $post_data['user_id'] = isset($post_data['user_id']) ? $post_data['user_id'] : Yii::app()->user->getId();
     if ($url != 'account/bankcard/bind.json' && $url != 'loginRest/getUserCenterInfo.json' && $url != 'account/bankcard/modify.json') {
         $post_data['access_from'] = 'admin';
     }
     $sdata = array();
     foreach ($post_data as $key => $value) {
         $sdata[$key] = trim($value);
     }
     try {
         $_snoopy = new Snoopy();
         $data = null;
         if (in_array($url, $host2)) {
             $furl = Yii::app()->params['back_host2'] . $url;
         } else {
             $furl = Yii::app()->params['back_host'] . $url;
         }
         $_snoopy->submit($furl, $sdata);
         if ($_snoopy->results != '') {
             $data = json_decode($_snoopy->results, true);
         }
         //		    var_dump($furl, $sdata, $data);
         self::json_log($_snoopy->results);
         return $data;
     } catch (Exception $ex) {
         return null;
     }
     return null;
 }
 private function init()
 {
     $snoopy = new Snoopy();
     //Get Viewstate First
     $snoopy->fetch('http://202.197.224.66:8084/pyxx/login.aspx');
     if ($snoopy->status != 200) {
         return $this->setMsg(3);
     }
     if (preg_match('/value="(.*?)"/', $snoopy->results, $viewstate)) {
         $this->postArray['__VIEWSTATE'] = $viewstate[1];
     } else {
         return $this->setMsg(3);
     }
     //Set SessionId
     $snoopy->cookies['ASP.NET_SessionId'] = $this->sessionId;
     //Submit Form
     $snoopy->submit('http://202.197.224.66:8084/pyxx/login.aspx', $this->postArray);
     if ($snoopy->status != 200) {
         return $this->setMsg(3);
     }
     if (preg_match('/密码错误/', $snoopy->results)) {
         return $this->setMsg(1);
     }
     if (!preg_match('/html/', $snoopy->results)) {
         return $this->setMsg(4);
     }
     //Get Student Info
     $snoopy->fetch('http://202.197.224.66:8084/pyxx/grgl/xsinfoshow.aspx');
     if ($snoopy->status != 200) {
         return $this->setMsg(3);
     }
     //echo $snoopy->results;
     if (!preg_match('/个人基本信息/', $snoopy->results)) {
         return $this->setMsg(4);
     }
     if (preg_match('/<span id="lblxm1">(.*?)<\\/span>/', $snoopy->results, $matches)) {
         $studentData['name'] = urlencode($matches[1]);
     } else {
         return $this->setMsg(4);
     }
     if (preg_match('/<span id="lblxb">(.*?)<\\/span>/', $snoopy->results, $matches)) {
         $studentData['sex'] = urlencode($matches[1]);
     }
     if (preg_match('/<span id="lblcsrq">(.*?)<\\/span>/', $snoopy->results, $matches)) {
         $studentData['date_of_birth'] = urlencode($matches[1]);
     }
     if (preg_match('/<span id="lbljtdq">(.*?)<\\/span>/', $snoopy->results, $matches)) {
         $studentData['location'] = urlencode($matches[1]);
     }
     if (preg_match('/<span id="lblyxzy">(.*?)<\\/span>/', $snoopy->results, $matches)) {
         $arr = explode('_', $matches[1]);
         $studentData['college'] = urlencode($arr[0]);
         $studentData['major'] = urlencode($arr[1]);
     }
     $this->studentData = $studentData;
     return $this->setMsg(0);
 }
Пример #8
0
 private function checkInfo()
 {
     $snoopy = new Snoopy();
     $postArray = array('username' => $this->sid, 'password' => $this->password, 'identity' => 'student', 'role' => 1);
     $snoopy->submit($this->checkUrl, $postArray);
     $this->processCookies($snoopy->headers);
     $snoopy->rawheaders['Cookie'] = $this->cookies;
     $data = iconv('gbk', 'utf-8', $snoopy->results);
     $this->checkIfError($data);
     $this->getName($snoopy, $postArray);
 }
Пример #9
0
 function upload()
 {
     $snoopy = new Snoopy();
     $submit = self::img_url . "post.php";
     $file = $this->uploadfile;
     $data["type"] = $this->type;
     $data["filename"] = $this->file;
     $data["path"] = $this->path;
     $snoopy->_submit_type = "multipart/form-data";
     $snoopy->submit($submit, $data, $file);
     return $snoopy->results;
 }
 function executeDefaultOp()
 {
     error_reporting(E_ERROR);
     $referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : $_ENV['HTTP_REFERER'];
     if (!$referer) {
         exit;
     }
     if (strpos($referer, $this->getUrlBase()) === false) {
         exit;
     }
     if (empty($_REQUEST['geoop'])) {
         exit;
     }
     include "../../class/snoopy.php";
     $snoopy = new Snoopy();
     //$snoopy->proxy_host='proxy.host.com';
     //$snoopy->proxy_port='8080';
     $snoopy->agent = 'XOOPS MyGmap Module';
     $postArray = array();
     if ($_REQUEST['geoop'] == 'csis') {
         $postArray['addr'] = mb_convert_encoding(urldecode($_REQUEST['addr']), 'EUC-JP', 'auto');
         $postArray['series'] = $_REQUEST['series'];
         $postArray['geosys'] = 'world';
         $postArray['charset'] = 'x-euc-jp';
         $snoopy->submit("http://geocode.csis.u-tokyo.ac.jp/cgi-bin/simple_geocode.cgi", $postArray);
     } else {
         if ($_REQUEST['geoop'] == 'invgeo') {
             $postArray['lat'] = floatval($_REQUEST['lat']);
             $postArray['lon'] = floatval($_REQUEST['lon']);
             $postArray['format'] = 'simple';
             $snoopy->submit("http://nishioka.sakura.ne.jp/google/ws.php", $postArray);
         }
     }
     header('Content-type: application/xml');
     echo $snoopy->results;
 }
Пример #11
0
function defensio_post($action, $args = null)
{
    global $defensio_conf;
    // Use snoopy to post
    require_once 'lib/class-snoopy.php';
    $snoopy = new Snoopy();
    $snoopy->read_timeout = $defensio_conf['post_timeout'];
    // Supress the possible fsock warning
    @$snoopy->submit(defensio_url_for($action, $defensio_conf['key']), $args, array());
    // Defensio will return 200 nomally, 401 on authentication failure, anything else is unexpected behaivour
    if ($snoopy->status == 200 or $snoopy->status == 401) {
        return $snoopy->results;
    } else {
        return false;
    }
}
Пример #12
0
function Red_Enviar($telefono, $mensaje, $firma)
{
    $snoopy = new Snoopy();
    // Opciones de Snoopy (Mensajitos se muestra como IExplore 6.0)
    // Esto es por las paginas que bloquean a navegadores que no
    // sean Internet Explorer
    $snoopy->agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)";
    // URL referente:
    $snoopy->referer = "http://red.com.sv/redsms/index.php";
    // URL para mensajes de Red (Intelfon)
    $submit_url = "http://sms.red.com.sv:13013/cgi-bin/sendsms";
    $submit_vars["to"] = $telefono;
    $submit_vars["text"] = $mensaje . $firma;
    $submint_vars["Submit"] = $Enviar;
    $snoopy->submit($submit_url, $submit_vars);
    return true;
}
Пример #13
0
 function send_request($job)
 {
     var_dump("scorpio");
     include_once APPPATH . 'third_party/snoopy.php';
     $snoopy = new Snoopy();
     $data = json_decode($job->workload());
     $method = $data->method;
     $url = $data->url;
     $params = $data->params;
     ${$method} = array();
     foreach ($params as $key => $value) {
         ${$method}[$key] = $value;
     }
     $snoopy->submit($url, ${$method});
     $result = $snoopy->results;
     return $result;
 }
Пример #14
0
function find_lms_user($installid, $username, $signature, $confirmaction = null, $firstname = null, $lastname = null, $email = null)
{
    global $CFG;
    // find this host from the installid
    if (empty($CFG->lmshosts) || !is_array($CFG->lmshosts) || !array_key_exists($installid, $CFG->lmshosts)) {
        return LMS_NO_SUCH_HOST;
    }
    $host = $CFG->lmshosts[$installid];
    // validate our md5 hash
    if ($confirmaction == 'signupconfirmation') {
        $stringtohash = $installid . '|' . $username . '|' . $firstname . '|' . $lastname . '|' . $email . '|' . $host['token'];
    } else {
        $stringtohash = $installid . '|' . $username . '|' . $host['token'];
        // firstname, lastname and email cannot be relied upon not to change
        // so we only want to add them to the hash on signup, not for auth or anything else.
    }
    $checksig = md5($stringtohash);
    if ($checksig != $signature) {
        return LMS_INVALID_HASH;
    }
    // if we have an ip address, check it.
    if (array_key_exists('networkaddress', $host) && empty($confirmaction)) {
        if (!address_in_subnet(getremoteaddr(), $host['networkaddress'])) {
            return LMS_INVALID_NETWORK;
        }
    }
    if (!empty($confirmaction) && !empty($host['confirmurl'])) {
        $client = new Snoopy();
        $client->agent = LMS_SNOOPY_USER_AGENT;
        $client->read_timeout = 5;
        $client->use_gzip = true;
        $postdata = array('action' => $confirmaction, 'username' => $username, 'signature' => $signature);
        @$client->submit($host['confirmurl'], $postdata);
        if ($client->results != 'OK') {
            return clean_param($client->results, PARAM_CLEAN);
        }
    }
    // find our user (we only want to check username and installid, the others could potentially change..
    if (!($user = get_record_sql('SELECT u.* FROM ' . $CFG->prefix . 'users u 
                        JOIN ' . $CFG->prefix . 'users_alias ua ON ua.user_id = u.ident
                        WHERE ua.installid = ? AND ua.username = ?', array($installid, $username)))) {
        return LMS_NO_SUCH_USER;
    }
    return $user;
}
Пример #15
0
 function send_trackbacks($id, $trackbacks)
 {
     global $tikilib;
     // Split to get each URI
     $tracks = explode(',', $trackbacks);
     $ret = array();
     // Foreach URI
     $post_info = $this->get_post($id);
     $blog_info = $this->get_blog($post_info['blogId']);
     //Build uri for post
     $parts = parse_url($_SERVER['REQUEST_URI']);
     $uri = $tikilib->httpPrefix() . str_replace('tiki-blog_post', 'tiki-view_blog_post', $parts['path']) . '?postId=' . $id . '&amp;blogId=' . $post_info['blogId'];
     include "lib/snoopy/Snoopy.class.php";
     $snoopy = new Snoopy();
     foreach ($tracks as $track) {
         @($fp = fopen($track, 'r'));
         if ($fp) {
             $data = '';
             while (!feof($fp)) {
                 $data .= fread($fp, 32767);
             }
             fclose($fp);
             preg_match("/trackback:ping=(\"|\\'|\\s*)(.+)(\"|\\'\\s)/", $data, $reqs);
             if (!isset($reqs[2])) {
                 return $ret;
             }
             @($fp = fopen($reqs[2], 'r'));
             if ($fp) {
                 fclose($fp);
                 $submit_url = $reqs[2];
                 $submit_vars["url"] = $uri;
                 $submit_vars["blog_name"] = $blog_info['title'];
                 $submit_vars["title"] = $post_info['title'] ? $post_info['title'] : date("d/m/Y [h:i]", $post_info['created']);
                 $submit_vars["title"] .= ' ' . tra('by') . ' ' . $post_info['user'];
                 $submit_vars["excerpt"] = substr($post_info['data'], 0, 200);
                 $snoopy->submit($submit_url, $submit_vars);
                 $back = $snoopy->results;
                 if (!strstr('<error>1</error>', $back)) {
                     $ret[] = $track;
                 }
             }
         }
     }
     return $ret;
 }
Пример #16
0
function do_dent($tweet = '')
{
    global $aktt;
    if (empty($aktt->twitter_username) || empty($aktt->twitter_password) || empty($tweet) || empty($tweet->tw_text)) {
        return;
    }
    require_once ABSPATH . WPINC . '/class-snoopy.php';
    $snoop = new Snoopy();
    $snoop->agent = 'OpenMicroBlogger http://openmicroblogger.org';
    $snoop->rawheaders = array('X-Twitter-Client' => 'OpenMicroBlogger', 'X-Twitter-Client-Version' => $aktt->version, 'X-Twitter-Client-URL' => 'http://alexking.org/projects/wordpress/twitter-tools.xml');
    $snoop->user = $aktt->twitter_username;
    $snoop->pass = $aktt->twitter_password;
    $snoop->submit('http://identi.ca/api/statuses/update.json', array('status' => $tweet->tw_text, 'source' => 'twittertools'));
    if (strpos($snoop->response_code, '200')) {
        update_option('aktt_last_dent_download', strtotime('-28 minutes'));
        return true;
    }
    return false;
}
 /**
  * 向阿里REST服务器发送调用请求。
  *
  * @param string $apiname api名字
  * @param string $appInstanceId 用户订购的appid
  * @param string $userId 用户id
  * @param string $token 阿里平台产生的请求token
  * @param string $sip_sessionid 用户的session id
  * @param string $sip_format 请求结果格式,xml或者json,默认xml。
  * @param string $otherParams 其他附加的参数。
  * @return string  请求结果字符串。
  */
 public static function postRequest($apiname, $appParams = null, $sip_sessionid = null, $sip_format = null)
 {
     //准备本次请求参数
     $timestamp = getTimeStamp();
     /* REST request url. Use snoopy to submit a request
     		$url = $this->SIP_URL_PRE."?sip_timestamp=".date("Y-m-d H:i:s")
     		.'&sip_appkey='.$this->APP_ID.'&appId='.$this->APP_ID.'&sip_sign='.$sip_sign.
     		'&token='.$token.'&appInstanceId='.$appInstanceId
     		.'&userId='.$userId.'&sip_apiname=alisoft.validateUser'.'&sip_sessionid='.$sip_sessionid;
     		*/
     $formVars['sip_appkey'] = APP_ID;
     $formVars['sip_apiname'] = $apiname;
     $formVars['sip_timestamp'] = $timestamp;
     $formVars['appId'] = APP_ID;
     if (isset($sip_sessionid)) {
         $formVars['sip_sessionid'] = $sip_sessionid;
     }
     if (isset($sip_format)) {
         $formVars['sip_format'] = $sip_format;
     }
     if (isset($appParams) && is_array($appParams)) {
         $formVars = array_merge($formVars, $appParams);
         //writeDebug('form var before encode:' . print_r($formVars,true));
         //$encodeParams = self::encodeParams($appParams);
     }
     // 生成签名
     $sip_sign = SignGenerator::generateSign($formVars);
     $formVars['sip_sign'] = $sip_sign;
     //$formVars = array_merge($formVars,$encodeParams);
     writeDebug(sprintf("API: %s\nParams: %s", $apiname, print_r($formVars, true)));
     $proxy = new Snoopy();
     //$proxy->set_submit_multipart();
     //向AEP发出服务端请求
     $proxy->submit(SIP_REST_URI, $formVars);
     WriteDebug("http header:" . print_r($proxy->headers, true));
     self::handleError($proxy->headers);
     // 返回请求结果
     return $proxy->results;
 }
 public static function sendPostRequest($url, $postParameters, $responseType = 'raw')
 {
     $snoopy = new Snoopy();
     $snoopy->accept = 'application/json';
     $snoopy->set_submit_normal();
     $snoopy->submit($url, $postParameters);
     $response = null;
     switch ($responseType) {
         case 'json':
             $response = json_decode($snoopy->results);
             break;
         case 'raw':
             $response = $snoopy->results;
             break;
         default:
             $response = $snoopy->results;
     }
     // on failure, throw an exception
     if ($snoopy->status != 200) {
         if ($responseType == 'raw') {
             throw new HttpException($response, $snoopy->status);
         } elseif ($responseType == 'json') {
             if (isset($response->field_errors) && !empty($response->field_errors)) {
                 $errorMsg = "[";
                 $i = 0;
                 foreach ($response->field_errors as $field_error) {
                     $errorMsg .= $i != 0 ? ' | ' . $field_error : $field_error;
                     ++$i;
                 }
                 $errorMsg .= "]";
                 throw new HttpException($response->message . ' => ' . $errorMsg, $snoopy->status);
             } else {
                 throw new HttpException($response, $snoopy->status);
             }
         }
     }
     return $response;
 }
Пример #19
0
 protected function checkValid()
 {
     if ($this->sid == '' || $this->password == '') {
         return $this->setMsg(65535);
     }
     $snoopy = new Snoopy();
     $postArray = array('username' => $this->sid, 'password' => $this->password, 'identity' => 'student', 'role' => 1);
     $snoopy->submit($this->checkUrl, $postArray);
     if ($snoopy->status != 200) {
         return $this->setMsg(3);
     }
     if ($this->processCookies($snoopy->headers) != 0) {
         return 0;
     }
     $snoopy->rawheaders['Cookie'] = $this->cookies;
     $data = iconv('gbk', 'utf-8', $snoopy->results);
     if ($this->checkIfError($data) != 0) {
         return 0;
     }
     if ($this->getName($snoopy, $postArray) != 0) {
         return 0;
     }
 }
Пример #20
0
 /**
  * @return string 生成商业id
  *
  */
 public function generate_business_id($post)
 {
     $params = array();
     //系统级参数
     $params['method'] = "shopex.user.add";
     $params['app_key'] = $this->passport_api_key;
     //测试环境可能有时间差!所以通过网络获取
     $snoopy = new Snoopy();
     $snoopy->submit("http://openapi.ishopex.cn/api/platform/timestamp", "");
     $params['timestamp'] = $snoopy->results;
     //$params['timestamp'] = time();
     $params['format'] = 'json';
     $params['v'] = '1.0';
     //将$post的内容添加进$params
     $params = array_merge($params, $post);
     //        print_r($params);
     //        exit;
     $params['sign'] = $this->make_sign($params, $this->passport_secret, array('sign'));
     $this->snoopy->submit($this->passport_api_url, $params);
     $res = $this->snoopy->results;
     $arrres = json_decode($res, true);
     return $arrres;
 }
Пример #21
0
 /**
  * @param $url
  * @param $post_data
  * @return mixed|null
  */
 public static function post($url, $post_data)
 {
     //        $post_data['_ts']=time();
     $session = new CHttpSession();
     $session->open();
     $post_data['token'] = $session['token'];
     if (false !== ($apiName = array_search($url, Yii::app()->params["scripts"]))) {
         //var_dump($apiName);
         return Yii::app()->api->postData($apiName, $post_data);
     }
     $sdata = array();
     foreach ($post_data as $key => $value) {
         $sdata[$key] = urlencode(trim($value));
     }
     try {
         $_snoopy = new Snoopy();
         $data = null;
         $furl = Yii::app()->params['back_host'] . $url;
         //            var_dump($furl,json_encode($sdata));
         $_snoopy->submit($furl, $sdata);
         if ($_snoopy->status != 0) {
             Yii::log(json_encode(array('url' => $url, 'msg' => $_snoopy->response_code)), 'error', 'api.http.request');
             if ($_snoopy->error) {
                 Yii::log(json_encode(array('url' => $url, 'msg' => $_snoopy->error)), 'error', 'api.http.request');
             }
             return null;
         }
         //            var_dump($_snoopy->results);
         if ($_snoopy->results != '') {
             $data = json_decode($_snoopy->results, false);
         }
         return $data;
     } catch (Exception $ex) {
         return null;
     }
     return null;
 }
Пример #22
0
 public function upload()
 {
     // $options['save_path'] = "comment/feed"; // 存储文件夹名
     // $options['time'] = time(); // 时间戳
     // $options['save_key'] = 'date'; // 文件存储方式(random & date),分别是当前文件夹随机文件名 & 当前文件夹/年/月/日/随机文件名
     // $options['upload_type'] = 'image';
     // $data["type"] = $this->type;
     // $data["filename"] = $this->file;
     // $data["path"] = $this->path;
     $snoopy = new Snoopy();
     $submit = self::img_url . "v2/upload.php";
     $file = $this->uploadfile;
     $data["save_path"] = $this->path;
     $data["time"] = time();
     $data["save_key"] = $this->save_key;
     $data["upload_type"] = $this->upload_type;
     $form["policy"] = base64_encode(json_encode($data));
     $form["signature"] = md5($form["policy"] . '&' . self::secret);
     $form["type"] = $this->type;
     $snoopy->_submit_type = "multipart/form-data";
     var_dump($file);
     $snoopy->submit($submit, $form, $file);
     return $snoopy->results;
 }
 private function init()
 {
     $studentData;
     $snoopy = new Snoopy();
     $postArray = array('postdata' => $this->sid, 'postname' => 'accountid', 'backname' => '');
     $snoopy->submit($this->checkUrl, $postArray);
     if ($snoopy->status != 200) {
         return $this->setMsg(3);
     }
     $data = iconv('gbk', 'utf-8', $snoopy->results);
     if (!preg_match('/script/', $data)) {
         return $this->setMsg(3);
     }
     if (preg_match('/输入错误/', $data)) {
         return $this->setMsg(5);
     }
     if (preg_match('/\\<br\\>用户姓名:(.*?)\\<br\\>/', $data, $matches)) {
         $studentData['name'] = urlencode(trim($matches[1]));
     } else {
         return $this->setMsg(3);
     }
     if (preg_match('/\\<br\\>账号套餐类型:(.*?)\\<br\\>/', $data, $matches)) {
         $studentData['package'] = urlencode($matches[1]);
     }
     if (preg_match('/\\<br\\>账号状态:(.*?)\\<br\\>/', $data, $matches)) {
         $studentData['status'] = urlencode($matches[1]);
     }
     if (preg_match('/\\<br\\>下次扣费时间:(.*?)\\<br\\>/', $data, $matches)) {
         $studentData['next_statement_date'] = urlencode($matches[1]);
     }
     if (preg_match('/\\<br\\>账号当前余额:(.*?)\\<\\/font\\>/', $data, $matches)) {
         $studentData['balance'] = urlencode($matches[1]);
     }
     $this->studentData = $studentData;
     return $this->setMsg(0);
 }
Пример #24
0
/**
 * function getName($stu_number,$pwd)
 * 获取
 * 			string name 验证成功返回姓名
 * 			bool false /null 验证失败返回false或空值
 *
 * @author 梁崇军
 *
 * @param  string  $stu_number 学号
 * @param  string  $pwd        登陆密码
 * @return mixed
 */
function getName($stu_number, $pwd)
{
    /*验证地址--urp密码验证页*/
    $action_url = 'http://urp.nankai.edu.cn/userPasswordValidate1.portal';
    $snoopy = new Snoopy();
    $snoopy->rawheaders['Pragma'] = 'no-cache';
    $snoopy->rawheaders['X_FORWARDED_FOR'] = get_client_ip();
    $success_words = '<script type="text/javascript">location.href = \'http://urp.nankai.edu.cn/index.portal\';</script>';
    $error_key = '密码错误';
    $snoopy->referer = 'http://urp.nku.cn';
    /*用户学号和密码*/
    $input['Login.Token1'] = $stu_number;
    $input['Login.Token2'] = $pwd;
    $snoopy->submit($action_url, $input);
    //模拟登陆
    $result = $snoopy->results;
    //登录结果页面
    if (strpos($result, $error_key) !== false) {
        return false;
    } elseif (strpos($result, $success_words) !== false) {
        /*登录成功,保存cookie信息页面抓取信息*/
        $snoopy->setcookies();
        $snoopy->fetchtext('http://urp.nankai.edu.cn/index.portal');
        $text = $snoopy->results;
        // $substr   = substr($input, strlen($start) + strpos($input, $start) , (strlen($input) - strpos($input, $end)) * (-1));
        $get_name = function ($input, $start, $end) {
            return substr($input, strlen($start) + strpos($input, $start), (strlen($input) - strpos($input, $end)) * -1);
        };
        $name = $get_name($text, '您好,', ' 欢迎来到南开大学');
        return $name;
    } else {
        $error = '未知错误[可能信息门户已经改版]返回信息:' . htmlspecialchars($result);
        E($error);
        return false;
    }
}
Пример #25
0
 /**
  * Opens a remote file using the WordPress API or Snoopy
  * 
  * @param $url The URL to open
  * @param $method get or post
  * @param $postData An array with key=>value paris
  * @param $timeout Timeout for the request, by default 10
  * @return mixed False on error, the body of the response on success
  */
 function RemoteOpen($url, $method = 'get', $postData = null, $timeout = 10)
 {
     global $wp_version;
     //Before WP 2.7, wp_remote_fopen was quite crappy so Snoopy was favoured.
     if (floatval($wp_version) < 2.7) {
         if (!file_exists(ABSPATH . 'wp-includes/class-snoopy.php')) {
             trigger_error('Snoopy Web Request failed: Snoopy not found.', E_USER_NOTICE);
             return false;
             //Hoah?
         }
         require_once ABSPATH . 'wp-includes/class-snoopy.php';
         $s = new Snoopy();
         $s->read_timeout = $timeout;
         if ($method == 'get') {
             $s->fetch($url);
         } else {
             $s->submit($url, $postData);
         }
         if ($s->status != "200") {
             trigger_error('Snoopy Web Request failed: Status: ' . $s->status . "; Content: " . htmlspecialchars($s->results), E_USER_NOTICE);
         }
         return $s->results;
     } else {
         $options = array();
         $options['timeout'] = $timeout;
         if ($method == 'get') {
             $response = wp_remote_get($url, $options);
         } else {
             $response = wp_remote_post($url, array_merge($options, array('body' => $postData)));
         }
         if (is_wp_error($response)) {
             $errs = $response->get_error_messages();
             $errs = htmlspecialchars(implode('; ', $errs));
             trigger_error('WP HTTP API Web Request failed: ' . $errs, E_USER_NOTICE);
             return false;
         }
         return $response['body'];
     }
     return false;
 }
 /**
  * 登出当前登陆用户
  */
 public function logout()
 {
     if (!$this->cookie) {
         return false;
     }
     preg_match("/wxuin=(\\w+);/", $this->cookie, $matches);
     if (count($matches) > 1) {
         $uid = $matches[1];
     }
     preg_match("/wxsid=(\\w+);/", $this->cookie, $matches);
     if (count($matches) > 1) {
         $sid = $matches[1];
     }
     $this->log('logout: uid=' . $uid . ';sid=' . $sid);
     $send_snoopy = new Snoopy();
     $submit = 'https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxlogout?redirect=1&type=1';
     $send_snoopy->rawheaders['Cookie'] = $this->cookie;
     $send_snoopy->referer = "https://wx2.qq.com/";
     $send_snoopy->submit($submit, array('uin' => $uid, 'sid' => $sid));
     $this->deleteCookie($this->_cookiename);
     return true;
 }
 function trackback($trackback_url, $title, $excerpt, $ID, $charset = "", $force = true)
 {
     require_once XOOPS_ROOT_PATH . '/class/snoopy.php';
     $ID = intval($ID);
     $blog_name = get_settings('blogname');
     if ($charset) {
         $title = mb_conv($title, $charset, $GLOBALS['blog_charset']);
         $excerpt = mb_conv($excerpt, $charset, $GLOBALS['blog_charset']);
         $blog_name = mb_conv($blog_name, $charset, $GLOBALS['blog_charset']);
     } else {
         $charset = $GLOBALS['blog_charset'];
     }
     $snoopy = new Snoopy();
     $formvars['title'] = $title;
     $formvars['excerpt'] = $excerpt;
     $formvars['blog_name'] = $blog_name;
     $formvars['charset'] = $charset;
     $formvars['url'] = get_permalink($ID);
     $result = $snoopy->submit($trackback_url, $formvars);
     $fp = debug_fopen(wp_base() . '/log/trackback.log', 'a');
     debug_fwrite($fp, "\n*****\nRequest:\n\nResponse:\n\n");
     debug_fwrite($fp, "CHARSET:{$charset}\n");
     debug_fwrite($fp, "TITLE:{$title}\n");
     debug_fwrite($fp, "EXCERPT:{$excerpt}\n");
     debug_fwrite($fp, "\n\nResponse:\n\n");
     debug_fwrite($fp, $snoopy->results);
     debug_fwrite($fp, "\n\n");
     debug_fclose($fp);
     $postHandler =& wp_handler('Post');
     $postObject =& $postHandler->create(false);
     $postObject->setVar('ID', $ID);
     $postObject->setVar('pinged', "__MySqlFunc__CONCAT(pinged, '\n', '{$trackback_url}')");
     $postObject->setVar('to_ping', "__MySqlFunc__REPLACE(to_ping, '{$trackback_url}', '')");
     $postObject->insert($postObject, $force, true);
     return $result;
 }
    $loginAPI = $zentaoRoot . "user-login.json?a=1";
    $sessionAPI = $zentaoRoot . "api-getsessionid.json?a=1";
    $myBugAPI = $zentaoRoot . "my-bug.json?a=1";
    $superMyBugAPI = $zentaoRoot . "api-getmodel-bug-getUserBugPairs-account={$account}.json?a=1";
}
/* 获取session. */
$snoopy = new Snoopy();
$snoopy->fetch($sessionAPI);
$session = json_decode($snoopy->results);
$session = json_decode($session->data);
/*用户登录*/
$authHash = md5(md5($password) . $session->rand);
$submitVars["account"] = $account;
$submitVars["password"] = $authHash;
$snoopy->cookies[$session->sessionName] = $session->sessionID;
$snoopy->submit($loginAPI, $submitVars);
/* 直接调用my模块的bugs页面。*/
$snoopy->fetch($myBugAPI . "&{$session->sessionName}={$session->sessionID}");
$result = json_decode($snoopy->results);
if ($result->status == 'success' && md5($result->data) == $result->md5) {
    $bugs = json_decode($result->data)->bugs;
} else {
    echo "called failed or transfered not complete.";
    exit;
}
if ($bugs) {
    foreach ($bugs as $bug) {
        echo $bug->id . "\t" . $bug->title . "\n";
    }
} else {
    echo 'no bugs' . "\n";
Пример #29
0
<?php

//Snoopy.class.php를 불러옵니다
require $_SERVER['DOCUMENT_ROOT'] . '/snoop/lib/Snoopy.class.php';
$params = array("foo" => "A", "bar" => "B");
$snoopy = new Snoopy();
$snoopy = new Snoopy();
$snoopy->httpmethod = "POST";
//$snoopy->fetch('http://165.246.149.135/index.php?mid=board_vqEn86&document_srl=5832');
$snoopy->submit("http://165.246.149.135/index.php?mid=board_vqEn86&document_srl=5832", $params);
print $snoopy->results;
$text = $snoopy->results;
Пример #30
0
$snoopy = new Snoopy();
$submit_url = "http://api.fanfou.com/statuses/update.xml";
if ($_POST[update] != null && $_POST[update] === "up") {
    if (!isset($_SESSION["username"])) {
        //登录
        session_start();
        $_SESSION[username] = trim($_POST[username]);
        $_SESSION[password] = trim($_POST[password]);
    }
    //header('Content-type: text/html;charset=GB2312');
    $snoopy->user = $_SESSION[username];
    $snoopy->pass = $_SESSION[password];
    $message = array("status" => "", "source" => "koomi's fanfou pubtools");
    $message["status"] = trim($_POST[message]);
    //$message["status"] = "再测试snoopy-php-class";
    $snoopy->submit($submit_url, $message);
    /*
    //header('Content-type: text/html;charset=GB2312'); 
    $host = "http://api.fanfou.com/statuses/update.xml";
    //$host = "http://api.fanfou.com/statuses/user_timeline.xml";
    $message = array("status"=>"");
    $message["status"] = trim($_POST[message]);
    //$message = trim($_POST[message]);
    $username = $_SESSION[username];
    $password = $_SESSION[password];
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL,$host);
    curl_setopt($ch,CURLOPT_VERBOSE,1);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch,CURLOPT_USERPWD,"$username:$password");//设置用户名密码
    curl_setopt($ch,CURLOPT_POST,1);//用POST方式发送