Example #1
0
 function request($url, $data = null, $timeout = 10, $headers = array())
 {
     $ch = curl_init();
     $options = array(CURLOPT_URL => $url, CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_ENCODING => 'utf-8', CURLOPT_USERAGENT => self::agent(), CURLOPT_AUTOREFERER => true, CURLOPT_CONNECTTIMEOUT => $timeout, CURLOPT_TIMEOUT => $timeout, CURLOPT_MAXREDIRS => 10, CURLOPT_SSL_VERIFYPEER => false);
     if (!empty($headers)) {
         $options[CURLOPT_HTTPHEADER] = $headers;
     }
     if (!empty($data)) {
         $options[CURLOPT_POST] = true;
         $options[CURLOPT_POSTFIELDS] = $data;
     }
     curl_setopt_array($ch, $options);
     $content = curl_exec($ch);
     $error = curl_errno($ch);
     $message = curl_error($ch);
     $response = curl_getinfo($ch);
     curl_close($ch);
     $response['error'] = $error;
     $response['message'] = $message;
     $response['content'] = $content;
     self::$response = $response;
     if (a::get($response, 'error')) {
         return array('status' => 'error', 'msg' => 'The remote request failed: ' . $response['message']);
     }
     if (a::get($response, 'http_code') >= 400) {
         return array('status' => 'error', 'msg' => 'The remote request failed - code: ' . $response['http_code'], 'code' => $response['http_code']);
     }
     return $response;
 }
Example #2
0
 static function post($url, $post_data_array, $extra_headers = array())
 {
     $post_data_raw = self::_encode_post_data($post_data_array, $extra_headers);
     /* Read the web page into a buffer */
     list($response_status, $response_headers, $response_body) = remote::do_request($url, 'POST', $extra_headers, $post_data_raw);
     return array($response_body, $response_status, $response_headers);
 }
Example #3
0
File: t.php Project: GStepOne/CI
 public static function reset()
 {
     self::$pname = 'androidc';
     self::$url = 'http://dts.kuaidihelp.com/api.php';
     self::$key = '9ebfea665766969ddf7ee98ef9bd9d38';
     self::$timeout = 5;
 }
Example #4
0
 public function index()
 {
     // Get all active scheduled items
     foreach (ORM::factory('scheduler')->where('scheduler_active', '1')->find_all() as $scheduler) {
         $scheduler_id = $scheduler->id;
         $scheduler_last = $scheduler->scheduler_last;
         // Next run time
         $scheduler_weekday = $scheduler->scheduler_weekday;
         // Day of the week
         $scheduler_day = $scheduler->scheduler_day;
         // Day of the month
         $scheduler_hour = $scheduler->scheduler_hour;
         // Hour
         $scheduler_minute = $scheduler->scheduler_minute;
         // Minute
         // Controller that performs action
         $scheduler_controller = $scheduler->scheduler_controller;
         if ($scheduler_day <= -1) {
             // Ran every day?
             $scheduler_day = "*";
         }
         if ($scheduler_weekday <= -1) {
             // Ran every day?
             $scheduler_weekday = "*";
         }
         if ($scheduler_hour <= -1) {
             // Ran every hour?
             $scheduler_hour = "*";
         }
         if ($scheduler_minute <= -1) {
             // Ran every minute?
             $scheduler_minute = "*";
         }
         $scheduler_cron = $scheduler_minute . " " . $scheduler_hour . " " . $scheduler_day . " * " . $scheduler_weekday;
         //Start new cron parser instance
         $cron = new CronParser($scheduler_cron);
         $lastRan = $cron->getLastRan();
         //Array (0=minute, 1=hour, 2=dayOfMonth, 3=month, 4=week, 5=year)
         $cronRan = mktime($lastRan[1], $lastRan[0], 0, $lastRan[3], $lastRan[2], $lastRan[5]);
         if (!($scheduler_last > $cronRan - 45) || $scheduler_last == 0) {
             // within 45 secs of cronRan time, so Execute control
             $site_url = "http://" . $_SERVER['SERVER_NAME'] . "/";
             $scheduler_status = remote::status($site_url . "scheduler/" . $scheduler_controller);
             // Set last time of last execution
             $schedule_time = time();
             $scheduler->scheduler_last = $schedule_time;
             $scheduler->save();
             // Record Action to Log
             $scheduler_log = new Scheduler_Log_Model();
             $scheduler_log->scheduler_id = $scheduler_id;
             $scheduler_log->scheduler_name = $scheduler->scheduler_name;
             $scheduler_log->scheduler_status = $scheduler_status;
             $scheduler_log->scheduler_date = $schedule_time;
             $scheduler_log->save();
         }
     }
     Header("Content-Type: image/gif");
     // Transparent GIF
     echo base64_decode("R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==");
 }
Example #5
0
 public function __construct($xml)
 {
     if (str::is_path($xml)) {
         if (str::is_url($xml)) {
             $r = remote::get($xml);
             $this->data = $r['content'];
         } else {
             $this->data = file_get_contents($xml);
         }
     } else {
         $this->data = $xml;
     }
     if (empty($this->data)) {
         return false;
     }
     unset($xml, $r, $fp);
 }
Example #6
0
	public function generate_link($link, $hash = "")
	{
		$response = remote::send_request($this->base_path . "shorts.json?apiKey=" . $this->key, array(
			"short[expanded]" => $link,
			"short[contracted]" => $hash
		));
		
		$response = json_decode($response);
		if($response->status_code == 200)
		{
			return $response->shorts->short->hashed; // Will return the hashed ID of the short.
		}
		else
		{
			throw new Exception($response->status_text, 500);
		}
	}
Example #7
0
 public static function latest_post()
 {
     $cache = kirby()->cache()->get('facebook.latest.post');
     if (!is_null($cache)) {
         return response::json($cache);
     }
     $response = remote::get(url::build(array('scheme' => static::$graph_scheme, 'host' => static::$graph_host, 'fragments' => array(c::get('facebook.id'), 'posts'), 'query' => array('access_token' => c::get('facebook.accesstoken'), 'limit' => 1))));
     if ($response->content) {
         // parse json string
         $data = str::parse($response->content)['data'][0];
         $return = array('text' => $data['message'], 'picture' => $data['picture'], 'timestamp' => strtotime($data['updated_time']), 'time_formatted' => strftime('%d. %B %G', strtotime($data['updated_time'])), 'link' => $data['link']);
         // set cache for 10 minutes
         kirby()->cache()->set('facebook.latest.post', $return, 10);
     } else {
         return false;
     }
     return $return;
 }
Example #8
0
 /**
  * Geonames Feeds GeoCoding (RSS to GEORSS)
  * Due to limitations, this returns only 20 items
  *
  * @param   string location / address
  * @return  string raw georss data
  */
 function geocode_feed($feed_url = NULL)
 {
     $base_url = "http://" . GEOCODER_GEONAMES . "/rssToGeoRSS?";
     if ($feed_url) {
         // First check to make sure geonames webservice is running
         $geonames_status = remote::status($base_url);
         if ($geonames_status == "200") {
             // Successful
             $request_url = $base_url . "&feedUrl=" . urlencode($feed_url);
         } else {
             // Down perhaps?? Use direct feed
             $request_url = $feed_url;
         }
         $georss = file_get_contents($request_url);
         $georss = utf8_encode($georss);
         return $georss;
     } else {
         return false;
     }
 }
Example #9
0
 /**
  * Fech version info from the Gallery website.
  */
 static function fetch_version_info()
 {
     $result = new stdClass();
     try {
         list($status, $headers, $body) = remote::do_request(upgrade_checker::CHECK_URL);
         if ($status == "HTTP/1.1 200 OK") {
             $result->status = "success";
             foreach (explode("\n", $body) as $line) {
                 if ($line) {
                     list($key, $val) = explode("=", $line, 2);
                     $result->data[$key] = $val;
                 }
             }
         } else {
             $result->status = "error";
         }
     } catch (Exception $e) {
         Kohana_Log::add("error", sprintf("%s in %s at line %s:\n%s", $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTraceAsString()));
     }
     $result->timestamp = time();
     Cache::instance()->set("upgrade_checker_version_info", serialize($result), null, 86400 * 365);
 }
Example #10
0
 /**
  * Geonames Feeds GeoCoding (RSS to GEORSS)
  * Due to limitations, this returns only 20 items
  *
  * @param   string location / address
  * @return  string raw georss data
  */
 function geocode_feed($feed_url = NULL)
 {
     $base_url = "http://" . GEOCODER_GEONAMES . "/rssToGeoRSS?";
     if ($feed_url) {
         // First check to make sure geonames webservice is running
         $geonames_status = @remote::status($base_url);
         if ($geonames_status == "200") {
             // Successful
             $request_url = $base_url . "&feedUrl=" . urlencode($feed_url);
         } else {
             // Down perhaps?? Use direct feed
             $request_url = $feed_url;
         }
         if (!($georss = @file_get_contents($request_url))) {
             // If the request failed, something may be wrong with the GEOCODER_GEONAMES service
             return false;
         }
         //$georss = utf8_encode($georss);
         return trim($georss);
     } else {
         return false;
     }
 }
Example #11
0
 public function _loginAct()
 {
     $phone = V('mobile');
     $pas = $_POST['pwd'];
     if (empty($phone) || empty($pas)) {
         return 0;
     }
     $data = array('sname' => 'user.login', 'mobile' => $phone, 'passwd' => $pas);
     core::Singleton('comm.remote.remote');
     $result = remote::send($data);
     setcookie("version", remote::$session_id, time() + 3600 * 12, '/', 'cailai.com');
     $data = json_decode($result, TRUE);
     if ($data['code'] != 0) {
         $this->view->assign('tipMsg', $data['msg']);
     }
     setcookie("uid", md5(uniqid()) . $data['data']['mobile'], time() + 3600 * 12, '/', 'cailai.com');
     if (empty(remote::$session_id)) {
         $this->view->assign('n', $phone);
         return 0;
     } else {
         skip();
     }
 }
Example #12
0
 /**
  * Parses a remote feed into an array.
  *
  * @param   string   remote feed URL
  * @param   integer  item limit to fetch
  * @return  array
  */
 public static function parse($feed, $limit = 0)
 {
     // Make limit an integer
     $limit = (int) $limit;
     // Disable error reporting while opening the feed
     $ER = error_reporting(0);
     // Allow loading by filename/url or raw XML string
     if (valid::url($feed)) {
         $feed = remote::get($feed, 45);
         $feed = $feed['content'];
     } elseif (is_file($feed)) {
         $feed = file_get_contents($feed);
     }
     // Double check we have something to work with
     if (empty($feed)) {
         return FALSE;
     }
     // Load the feed
     $feed = simplexml_load_string($feed, 'SimpleXMLElement', LIBXML_NOCDATA);
     // Restore error reporting
     error_reporting($ER);
     // Feed could not be loaded
     if ($feed === NO) {
         return array();
     }
     // Detect the feed type. RSS 1.0/2.0 and Atom 1.0 are supported.
     $feed = isset($feed->channel) ? $feed->xpath('//item') : $feed->entry;
     $i = 0;
     $items = array();
     foreach ($feed as $item) {
         if ($limit > 0 and $i++ === $limit) {
             break;
         }
         $items[] = (array) $item;
     }
     return $items;
 }
Example #13
0
 /**
  * Geonames Feeds GeoCoding (RSS to GEORSS)
  * Due to limitations, this returns only 20 items
  *
  * @param   string location / address
  * @return  string raw georss data
  */
 function geocode_feed($feed_url = NULL)
 {
     $base_url = "http://" . GEOCODER_GEONAMES . "/rssToGeoRSS?";
     // Only requests service if we have an user
     $geocode_username = Settings_Model::get_setting('feed_geolocation_user');
     if ($feed_url && !empty($geocode_username)) {
         // First check to make sure geonames webservice is running
         $geonames_status = @remote::status($base_url);
         if ($geonames_status == "200") {
             // Successful
             $request_url = $base_url . "&feedUrl=" . urlencode($feed_url) . "&username=" . $geocode_username;
         } else {
             // Down perhaps?? Use direct feed
             $request_url = $feed_url;
         }
         $request = new HttpClient($request_url);
         if (!($georss = $request->execute($request_url))) {
             // If the request failed, something may be wrong with the GEOCODER_GEONAMES service
             return false;
         }
         //$georss = utf8_encode($georss);
         // Lez verify this we got a good reply from the geocoder before proceeding
         $data = new SimplePie();
         $data->set_raw_data($georss);
         $data->init();
         $data->handle_content_type();
         // Feed no good - get outta here!
         if ($data->error()) {
             Kohana::log('error', $data->error() . $request_url);
             return false;
         }
         return trim($georss);
     } else {
         return false;
     }
 }
Example #14
0
 public function photo()
 {
     if (!is_null($this->photo)) {
         return $this->photo;
     }
     $extension = f::extension($this->data['photo']);
     $filename = rtrim(sha1($this->url) . '.' . $extension, '.');
     $path = c::get('webmentions.images', 'assets/images/mentions');
     $root = kirby()->roots()->index() . DS . str_replace('/', DS, $path) . DS . $filename;
     $url = kirby()->urls()->index() . '/' . $path . '/' . $filename;
     $photo = new Media($root, $url);
     if (!$photo->exists()) {
         $image = remote::get($this->data['photo']);
         $allowed = array('image/jpeg', 'image/png', 'image/gif');
         f::write($root, $image->content());
         if (!in_array($photo->mime(), $allowed) or $photo->size() == 0) {
             $photo->delete();
         }
     }
     if (!$photo->exists() or !$photo->type() == 'image') {
         $photo = new Obj(array('url' => $this->data['photo'], 'exists' => false));
     }
     return $this->photo = $photo;
 }
Example #15
0
        foreach ($only as $key) {
            $data[$key] = $form[$key];
        }
    } else {
        $data = $form;
        // remove those fields specified in 'except'
        foreach (a::get($actionOptions, 'except', array()) as $key) {
            unset($data[$key]);
        }
    }
    $params = a::get($actionOptions, 'params', array());
    // merge the optional 'static' data from the action array with the form data
    $params['data'] = array_merge(a::get($params, 'data', array()), $data);
    $headers = array('Content-Type: application/x-www-form-urlencoded');
    $params['headers'] = array_merge(a::get($params, 'headers', array()), $headers);
    $response = remote::request($url, $params);
    if ($response->error === 0) {
        return array('success' => true, 'message' => l::get('uniform-webhook-success'));
    } else {
        return array('success' => false, 'message' => l::get('uniform-webhook-error') . $response->message);
    }
};
/*
 * Action to choose from multiple recipients who should receive the form by
 * email.
 */
uniform::$actions['email-select'] = function ($form, $actionOptions) {
    $allowed = a::get($actionOptions, 'allowed-recipients');
    if (!is_array($allowed)) {
        throw new Exception('Uniform email select action: No allowed recipients!');
    }
        $cookie = tempnam("/tmp", "COOKIE");
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.54 Safari/536.5');
        //google snifs the UA
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
        curl_setopt($ch, CURLOPT_MAXREDIRS, 8);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        $response = curl_exec($ch);
        curl_close($ch);
        return $response;
    }
}
$db = new DB('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASS);
$image = new Image();
$remote = new remote();
$sql = 'SELECT filename,uid FROM images WHERE display=1';
$results = $db->fetch($sql);
foreach ($results as $result) {
    $image_url = WEB_ROOT . 'media/' . $result['filename'];
    $html = str_get_html($remote->fetch('http://www.google.com/searchbyimage?image_url=' . $image_url));
    $data = $html->find('a[style]', 0);
    $tag = $data->nodes[0]->_[4];
    if ($tag) {
        $image->addTag(array('name' => $tag, 'image' => $result['uid']));
        echo 'Tag added: ' . $tag . "\n";
    }
}
Example #17
0
 /**
  * Verify that our htaccess based permission system actually works.  Create a temporary
  * directory containing an .htaccess file that uses mod_rewrite to redirect /verify to
  * /success.  Then request that url.  If we retrieve it successfully, then our redirects are
  * working and our permission system works.
  */
 static function htaccess_works()
 {
     $success_url = url::file("var/tmp/security_test/success");
     @mkdir(VARPATH . "tmp/security_test");
     if ($fp = @fopen(VARPATH . "tmp/security_test/.htaccess", "w+")) {
         fwrite($fp, "RewriteEngine On\n");
         fwrite($fp, "RewriteRule verify {$success_url} [L]\n");
         fclose($fp);
     }
     if ($fp = @fopen(VARPATH . "tmp/security_test/success", "w+")) {
         fwrite($fp, "success");
         fclose($fp);
     }
     list($response) = remote::do_request(url::abs_file("var/tmp/security_test/verify"));
     $works = $response == "HTTP/1.1 200 OK";
     @dir::unlink(VARPATH . "tmp/security_test");
     return $works;
 }
Example #18
0
 /**
  * Invoke a Slack API method.
  */
 private static function api($method, $params)
 {
     return json_decode(remote::post('https://slack.com/api/' . $method, ['data' => array_merge($params, ['token' => c::get('slack.auth')])]), true);
 }
Example #19
0
 static function submit_translations()
 {
     // Request format (HTTP POST):
     //   client_token = <client_token>
     //   uid = <l10n server user id>
     //   signature = md5(user_api_key($uid, $client_token) . $data . $client_token))
     //   data = // JSON payload
     //
     //     {<key_1>: {message: <JSON encoded message>
     //                translations: {<locale_1>: <JSON encoded translation>,
     //                               <locale_2>: ...}},
     //      <key_2>: {...}
     //     }
     // @todo Batch requests (max request size)
     // @todo include base_revision in submission / how to handle resubmissions / edit fights?
     foreach (Database::instance()->select("key", "message", "locale", "base_revision", "translation")->from("outgoing_translations")->get() as $row) {
         $key = $row->key;
         if (!isset($request->{$key})) {
             $request->{$key}->message = json_encode(unserialize($row->message));
         }
         $request->{$key}->translations->{$row->locale} = json_encode(unserialize($row->translation));
     }
     // @todo reduce memory consumption, e.g. free $request
     $request_data = json_encode($request);
     $url = self::_server_url() . "?q=translations/submit";
     $signature = self::_sign($request_data);
     list($response_data, $response_status) = remote::post($url, array("data" => $request_data, "client_token" => self::client_token(), "signature" => $signature, "uid" => self::server_uid()));
     if (!remote::success($response_status)) {
         throw new Exception("@todo TRANSLATIONS_SUBMISSION_FAILED " . $response_status);
     }
     if (empty($response_data)) {
         return;
     }
     $response = json_decode($response_data);
     // Response format (JSON payload):
     //   [{key:<key_1>, locale:<locale_1>, rev:<rev_1>, status:<rejected|accepted|pending>},
     //    {key:<key_2>, ...}
     //   ]
     // @todo Move messages out of outgoing into incoming, using new rev?
     // @todo show which messages have been rejected / are pending?
 }
Example #20
0
 public function optionsFromApi($url)
 {
     $response = remote::get($url);
     $options = @json_decode($response->content(), true);
     return is_array($options) ? $options : array();
 }
Example #21
0
 /**
  * Verify that our htaccess based permission system actually works.  Create a temporary
  * directory containing an .htaccess file that uses mod_rewrite to redirect /verify to
  * /success.  Then request that url.  If we retrieve it successfully, then our redirects are
  * working and our permission system works.
  */
 static function htaccess_works()
 {
     $success_url = url::file("var/security_test/success");
     @mkdir(VARPATH . "security_test");
     try {
         if ($fp = @fopen(VARPATH . "security_test/.htaccess", "w+")) {
             fwrite($fp, "Options +FollowSymLinks\n");
             fwrite($fp, "RewriteEngine On\n");
             fwrite($fp, "RewriteRule verify {$success_url} [L]\n");
             fclose($fp);
         }
         if ($fp = @fopen(VARPATH . "security_test/success", "w+")) {
             fwrite($fp, "success");
             fclose($fp);
         }
         // Proxy our authorization headers so that if the entire Gallery is covered by Basic Auth
         // this callback will still work.
         $headers = array();
         if (function_exists("apache_request_headers")) {
             $arh = apache_request_headers();
             if (!empty($arh["Authorization"])) {
                 $headers["Authorization"] = $arh["Authorization"];
             }
         }
         list($status, $headers, $body) = remote::do_request(url::abs_file("var/security_test/verify"), "GET", $headers);
         $works = $status == "HTTP/1.1 200 OK" && $body == "success";
     } catch (Exception $e) {
         @dir::unlink(VARPATH . "security_test");
         throw $e;
     }
     @dir::unlink(VARPATH . "security_test");
     return $works;
 }
Example #22
0
 public function addQuery($host, $port, $query, $line, $class, $function)
 {
     $remote = new remote($host, $port, $query, $line, $class, $function, 8);
     $remote->setIrcClass($this);
     $remote->setTimerClass($this->timerClass);
     $remote->setSocketClass($this->socketClass);
     return $remote->connect();
 }
Example #23
0
 public static function reset()
 {
     self::$pname = 'm';
     self::$url = 'http://apitest.cailai.com/v1.0/';
     self::$key = '4e7d42a132e154cf6813aef44367402c';
     self::$timeout = 5;
 }
Example #24
0
 public function __construct($field)
 {
     $this->field = $field;
     if (is_array($field->options)) {
         $this->options = $field->options;
     } else {
         if (v::url($field->options)) {
             $response = remote::get($field->options);
             $options = @json_decode($response->content(), true);
             if (is_array($options)) {
                 $this->options = $options;
             } else {
                 $this->options = array();
             }
         } else {
             if (!$field->page) {
                 $this->options = array();
             } else {
                 if ($field->options == 'query') {
                     $defaults = array('page' => $field->page->id(), 'fetch' => 'children', 'value' => '{{uid}}', 'text' => '{{title}}', 'flip' => false, 'template' => false);
                     $query = array_merge($defaults, $field->query);
                     // dynamic page option
                     // ../
                     // ../../ etc.
                     if (str::startsWith($query['page'], '../')) {
                         $currentPage = $field->page;
                         $path = $query['page'];
                         while (str::startsWith($path, '../')) {
                             if ($parent = $currentPage->parent()) {
                                 $currentPage = $parent;
                             } else {
                                 break;
                             }
                             $path = str::substr($path, 3);
                         }
                         $page = $currentPage;
                     } else {
                         $page = page($query['page']);
                     }
                     $items = $this->items($page, $query['fetch']);
                     if ($query['template']) {
                         $items = $items->filter(function ($item) use($query) {
                             return in_array(str::lower($item->intendedTemplate()), array_map('str::lower', (array) $query['template']));
                         });
                     }
                     if ($query['flip']) {
                         $items = $items->flip();
                     }
                     foreach ($items as $item) {
                         $value = $this->tpl($query['value'], $item);
                         $text = $this->tpl($query['text'], $item);
                         $this->options[$value] = $text;
                     }
                 } else {
                     if ($items = $this->items($field->page, $field->options)) {
                         foreach ($items as $item) {
                             if (is_a($item, 'Page')) {
                                 $this->options[$item->uid()] = (string) $item->title();
                             } else {
                                 if (is_a($item, 'File')) {
                                     $this->options[$item->filename()] = (string) $item->filename();
                                 }
                             }
                         }
                     } else {
                         $this->options = array();
                     }
                 }
             }
         }
     }
     // sorting
     if (!empty($this->field->sort)) {
         switch (strtolower($this->field->sort)) {
             case 'asc':
                 asort($this->options);
                 break;
             case 'desc':
                 arsort($this->options);
                 break;
         }
     }
 }
Example #25
0
<?php

header("Content-type: text/html; charset=utf-8");
require_once dirname(__FILE__) . '/header.php';
core::Singleton('comm.remote.remote');
if (empty($_POST) || empty($_POST['code']) || empty($_POST['pwd'])) {
    echo json_encode(array('code' => 86, 'msg' => "填写信息不全,或者密码不可为空", 'stat' => false));
    return false;
}
$code = $_POST['code'];
if (!is_numeric($code)) {
    echo json_encode(array('code' => 87, 'msg' => "验证码时数字", 'stat' => false));
    return false;
}
$pwd = $_POST['pwd'];
$lenght = strlen($pwd);
if ($lenght < 6) {
    echo json_encode(array('code' => 88, 'msg' => "验证码时数字", 'stat' => false));
    return false;
}
$pwd = md5($pwd);
$data = array('sname' => 'user.validatefind', 'code' => $code, 'pwd' => $pwd);
remote::$open_debug = 1;
$result = remote::send($data);
var_dump($result);
Example #26
0
 public function __construct()
 {
     parent::__construct();
 }
Example #27
0
function transferAPI($data, $time = 5, $headers = array(), $return = 'body')
{
    core::Singleton('comm.remote.remote');
    remote::$open_debug = openDebug;
    // 判断 登陆的 登陆后把 cookie 发送 出去 呀!
    $temp = is_login();
    $headers = $temp == false ? $headers : $temp;
    $result = remote::send($data, $time, $headers, $return);
    return json_decode($result, TRUE);
}
Example #28
0
 public function attach($file, $filename = null)
 {
     // if the item has not been stored yet
     // throw an exception
     if (!$this->exists()) {
         throw new Exception('Unstored item');
     }
     // filename fallback
     if (is_null($filename)) {
         $filename = basename($file);
     }
     // sanitize the filename
     $filename = f::safeName($filename);
     // the item.yaml cannot be overwritten
     if ($filename == 'item.yaml') {
         throw new Exception('item.yaml is a reserved filename');
     }
     // files cannot be overwritten
     if (file_exists($this->root() . DS . $filename)) {
         throw new Exception('The file exists and cannot be overwritten');
     }
     // attach a remote url
     if (v::url($file)) {
         $response = remote::get($file);
         if ($response->code() < 400) {
             if (!f::write($this->root() . DS . $filename, $response->content())) {
                 throw new Exception('The file could not be saved');
             }
         } else {
             throw new Exception('The file could not be fetched');
         }
     } else {
         if (file_exists($file)) {
             if (!f::copy($file, $this->root() . DS . $filename)) {
                 throw new Exception('The file could not be copied');
             }
         }
     }
 }
    }
    $url = 'https://api.mailgun.net/v2/' . $email->options['domain'] . '/messages';
    $auth = base64_encode('api:' . $email->options['key']);
    $headers = array('Accept: application/json', 'Authorization: Basic ' . $auth);
    $data = array('from' => $email->from, 'to' => $email->to, 'subject' => $email->subject, 'text' => $email->body, 'h:Reply-To' => $email->replyTo);
    $email->response = remote::post($url, array('data' => $data, 'headers' => $headers));
    if ($email->response->code() != 200) {
        throw new Error('The mail could not be sent!');
    }
};
/**
 * Postmark mail driver
 */
email::$services['postmark'] = function ($email) {
    if (empty($email->options['key'])) {
        throw new Error('Invalid Postmark API Key');
    }
    // reset the api key if we are in test mode
    if (a::get($email->options, 'test')) {
        $email->options['key'] = 'POSTMARK_API_TEST';
    }
    // the url for postmarks api
    $url = 'https://api.postmarkapp.com/email';
    $headers = array('Accept: application/json', 'Content-Type: application/json', 'X-Postmark-Server-Token: ' . $email->options['key']);
    $data = array('From' => $email->from, 'To' => $email->to, 'ReplyTo' => $email->replyTo, 'Subject' => $email->subject, 'TextBody' => $email->body);
    // fetch the response
    $email->response = remote::post($url, array('data' => json_encode($data), 'headers' => $headers));
    if ($email->response->code() != 200) {
        throw new Error('The mail could not be sent');
    }
};
Example #30
0
File: test.php Project: GStepOne/CI
function autoRedirect($reqData)
{
    //echo "<pre>";print_r($reqData);echo "</pre>";exit;
    $tmp = array();
    $html = <<<HTML
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head><body onload="document.getElementById('autoRedirectForm').submit();">
<div class="margin:10px;font-size:14px;">正在跳转...</div>
<form id="autoRedirectForm" method="POST" action="http://mertest.chinapnr.com/muser/publicRequests">
HTML;
    foreach ($reqData as $key => $value) {
        $html .= '<input type="hidden" value=\'' . $value . '\' name="' . $key . '" />';
        $tmp[$key] = $value;
    }
    $html .= "</form>";
    $html .= "</body></html>";
    //file_put_contents('/tmp/autoRedirect',date('m-d H:i:s')."autoRedirect ".print_r($autoRedirect,true)."\n",FILE_APPEND);
    //file_put_contents('/tmp/autoRedirect',date('m-d H:i:s')."autoRedirect ".print_r($reqData,true)."\n",FILE_APPEND);
    print $html;
    exit;
}
//我的资产(需要登陆才可以)
$data = array('sname' => 'member.capital');
$header[] = 'Cookie:session_id=c14e16e841390bf4be501b18b3ac56ce6';
$result = remote::send($data, '', $header);
print_R(json_decode($result));
//打印结果,body属性返回格式为json格式
//print_r(remote::$debug);
echo "\n\n";
exit;