Пример #1
0
 protected function sendRequest($url, $user, $password)
 {
     if ($this->printEnabled) {
         echo 'API request: ', $url, PHP_EOL;
     }
     if ($this->logEnabled) {
         $this->log[] = $url;
     }
     $curl = new CURL();
     $curl->addOption(CURLOPT_USERPWD, $user . ':' . $password);
     $curl->addOption(CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-type: application/json'));
     $curl->addOption(CURLOPT_HEADER, true);
     $data = $curl->get($url);
     if ($curl->getRequestInfo('http_code') != 200) {
         $e = 'ERROR: ' . PHP_EOL;
         $e .= "\trequest URL:\t\t" . $url . PHP_EOL;
         $e .= "\trequest response:\t" . $curl->getRequestInfo('response_body') . PHP_EOL;
         if ($this->printEnabled) {
             echo $e;
         }
         if ($this->logEnabled) {
             $this->log[] = $e;
         }
         return false;
     } else {
         return $data;
     }
 }
Пример #2
0
 protected function get_jsapi_ticket()
 {
     $url = 'https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=' . $this->access_token . '&type=jsapi';
     $param = array('appid' => $this->appid, 'secret' => $this->appsecret);
     $ret = CURL::get($url, $param);
     return $ret;
 }
Пример #3
0
 public function down_media($media_id)
 {
     $file_type = 'jpg';
     $filename = strtotime('now') . str_pad(mt_rand(1, 9999), 4, '0', STR_PAD_LEFT) . '.' . $file_type;
     $directory = realpath(APPPATH . '../data/upload');
     $sub_directory = date('Y/m/d');
     $sub_directory = str_replace('/', DIRECTORY_SEPARATOR, $sub_directory);
     $upload_dir = $directory . DIRECTORY_SEPARATOR . $sub_directory;
     if (!is_dir($upload_dir)) {
         mkdir($upload_dir, 0755, TRUE);
     }
     if (!is_writable($upload_dir)) {
         chmod($upload_dir, 0755);
     }
     $url = 'http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=' . $this->access_token . '&media_id=' . $media_id;
     //error_log($url . "\n", 3, '/tmp/wx_upload.log');
     $data = CURL::get($url);
     $file_path = $upload_dir . DIRECTORY_SEPARATOR . $filename;
     file_put_contents($file_path, $data);
     list($width, $height) = getimagesize($file_path);
     $file_src = str_replace($directory, '', $file_path);
     $file_src = str_replace('\\', '/', $file_src);
     $file_src = trim($file_src, '/');
     return $file_src . '?' . $width . 'x' . $height;
 }
Пример #4
0
 /**
  * Perform a REST "get" method at a URL
  *
  * @param String $url the URL to "get"
  * @param String $type the content type to use (optional)
  * @param String $charset the charset encoding to use (optional)
  * @return Array any decoded data returned from the method
  */
 public static function get($url, $type = NULL, $charset = NULL)
 {
     $type = first($type, self::$type);
     $charset = first($charset, self::$charset);
     $text = CURL::get($url, self::headers_for($type));
     return self::decode($type, $text, 'get');
 }
Пример #5
0
 public function verify_sign($params)
 {
     if (empty($params)) {
         return false;
     }
     $mysign = $this->create_sign($params);
     $responseTxt = 'true';
     if (!empty($params["notify_id"])) {
         $notify_id = $params["notify_id"];
         $transport = strtolower(trim($this->_config['transport']));
         $partner = $this->_config['partner'];
         if ($transport == 'https') {
             $veryfy_url = 'https://mapi.alipay.com/gateway.do?service=notify_verify&';
         } else {
             $veryfy_url = 'http://notify.alipay.com/trade/notify_query.do?';
         }
         $veryfy_url .= 'partner=' . $partner . '&notify_id=' . $notify_id;
         $responseTxt = CURL::get($veryfy_url, '', array(CURLOPT_CAINFO => ''));
     }
     if (preg_match("/true\$/i", $responseTxt) && $mysign == $params["sign"]) {
         return true;
     } else {
         throw new Kohana_Exception('alipay 即时到帐支付  验证错误:' . $mysign . '--' . $params["sign"]);
         return false;
     }
 }
Пример #6
0
 public function get_access_token()
 {
     $url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential';
     $param = array('appid' => $this->appid, 'secret' => $this->appsecret);
     $ret_json = CURL::get($url, $param);
     $ret_array = json_decode($ret_json, true);
     return $ret_array;
 }
Пример #7
0
 public function action_zz2()
 {
     $str = '';
     $content = trim($_GET['q']);
     $ret_json = CURL::get('http://rmbz.net/Api/AiTalk.aspx?key=rmbznet&word=' . $content);
     $ret_array = json_decode($ret_json, true);
     if (isset($ret_array['result']) && $ret_array['result'] == 1) {
         $str = $ret_array['content'];
     }
     $this->response['data'] = $str;
 }
Пример #8
0
 public static function parse($feed, $limit = 0)
 {
     // Check if SimpleXML is installed
     if (!function_exists('simplexml_load_file')) {
         throw new Kohana_Exception('SimpleXML must be installed!');
     }
     // Make limit an integer
     $limit = (int) $limit;
     // Disable error reporting while opening the feed
     $error_level = error_reporting(0);
     // Allow loading by filename or raw XML string
     if (Valid::url($feed)) {
         // Use native Request client to get remote contents
         $feed = CURL::get($feed);
         //$feed = HTTP::get($feed);
     } elseif (is_file($feed)) {
         // Get file contents
         $feed = file_get_contents($feed);
     }
     //var_dump($feed);
     // Load the feed
     $feed = simplexml_load_string($feed, 'SimpleXMLElement', LIBXML_NOCDATA);
     // Restore error reporting
     error_reporting($error_level);
     // Feed could not be loaded
     if ($feed === FALSE) {
         return array();
     }
     $namespaces = $feed->getNamespaces(TRUE);
     // 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;
         }
         $item_fields = (array) $item;
         // get namespaced tags
         foreach ($namespaces as $ns) {
             $item_fields += (array) $item->children($ns);
         }
         $items[] = $item_fields;
     }
     return $items;
 }
Пример #9
0
 public function getContent($depth = 0, $callback)
 {
     $this->content = CURL::get($this->url);
     $this->content = mb_convert_encoding($this->content, 'utf-8', 'GBK,UTF-8,ASCII');
     if ($this->reg_url && preg_match($this->reg_url, $this->url, $matches)) {
         self::getTitle($this->content);
         if ($this->reg_content) {
             $html = SimpleHtml::str_get_html($this->content);
             call_user_func($callback, $this->url, $this->title, $html->find($this->{$reg_content}, 0) ? $html->find($this->{$reg_content}, 0)->innertext : $this->content);
             return null;
         }
         call_user_func($callback, $this->url, $this->title, $this->content);
     }
     if ($depth < $this->depth) {
         $links = self::getCurPageLinks($this->content);
         foreach ($links as $link) {
             \Log::info($link);
             $this->url = self::addDomainForURL($this->url, $link);
             self::getContent($depth + 1, $callback);
         }
     }
 }
Пример #10
0
 public function get_user_info()
 {
     $wx_user_info = Cookie::get('wx_user_info');
     if (!empty($wx_user_info)) {
         return json_decode($wx_user_info, true);
     }
     if (empty($_GET['code'])) {
         return array();
     }
     $code = $_GET['code'];
     $ret_array = $this->get_access_token($code);
     if (isset($ret_array['errcode'])) {
         return $ret_array;
     }
     $openid = $ret_array['openid'];
     $access_token = $ret_array['access_token'];
     $url = 'https://api.weixin.qq.com/sns/userinfo';
     $param = array('access_token' => $access_token, 'openid' => $openid, 'lang' => 'zh_CN');
     $ret_json = CURL::get($url, $param);
     $ret_array = json_decode($ret_json, true);
     Cookie::set('wx_user_info', $ret_json, 86400);
     return $ret_array;
 }
 private static function sendRequest($url, $user, $password)
 {
     require_once __DIR__ . '/includes/php/CURL.php';
     $curl = new CURL();
     $curl->addOption(CURLOPT_USERPWD, $user . ':' . $password);
     $curl->addOption(CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-type: application/json'));
     $curl->addOption(CURLOPT_HEADER, true);
     $data = $curl->get($url);
     if ($curl->getRequestInfo('http_code') != 200) {
         return false;
     } else {
         return $data;
     }
 }
Пример #12
0
<?php

if ($_POST['file']) {
    $curl = new CURL();
    $content = $curl->get($_POST['file']);
    header("Content-Type: text/xml; charset=UTF-8");
    exit($content);
}
//curl
class CURL
{
    var $callback = false;
    function setCallback($func_name)
    {
        $this->callback = $func_name;
    }
    function doRequest($method, $url, $vars)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
        //	    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
        curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
        //dungbt them vao de post duoc len lighttpd
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
        if ($method == 'POST') {
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
Пример #13
0
 function edit_push_order()
 {
     global $dbConn;
     $data = $_POST['skuObj'];
     $ordersn = $data['ordersn'];
     $sku = $data['sku'];
     $amount = $data['amount'];
     $operator = $_SESSION['sysUserId'];
     $sql = "update ph_ow_order_detail set count='{$amount}' where recordnumber='{$ordersn}' and sku='{$sku}'";
     if ($dbConn->execute($sql)) {
         /***添加结束B仓备货单功能 add by wangminwei 2014-07-28***/
         $mark = true;
         $sqlstr = "SELECT count, stockqty, sendqty FROM ph_ow_order_detail WHERE recordnumber = '{$ordersn}'";
         $query = $dbConn->execute($sqlstr);
         $detailData = $dbConn->getResultArray($query);
         if (!empty($detailData)) {
             foreach ($detailData as $kk => $vv) {
                 $count = $vv['count'];
                 $stockqty = $vv['stockqty'];
                 $sendqty = $vv['sendqty'];
                 if ($count != $stockqty || $stockqty != $sendqty) {
                     $mark = false;
                     break;
                 } else {
                     continue;
                 }
             }
         }
         if ($mark) {
             $upd = "UPDATE ph_ow_order SET status = 5 WHERE recordnumber = '{$ordersn}'";
             $dbConn->execute($upd);
         }
         $curl = new CURL();
         $url = "http://wh.valsun.cn/openapi.php?jsonp=1&mod=syncPreGoodsOrder&act=modifyPreGoodsSku&sku={$sku}&amount={$amount}&ordersn={$ordersn}&operator={$operator}";
         $rtn = $curl->get($url, false);
     }
     return $rtn;
 }
Пример #14
0
    <meta http-equiv="refresh" content="0; url=<?php 
echo $data->server;
?>
">
</noscript>
<base href="<?php 
echo $data->server;
?>
">
<div id="cpform" style="display: none;">
    <?php 
require 'CURL.php';
$curl = new CURL();
$curl->addOption(CURLOPT_RETURNTRANSFER, true);
$curl->addOption(CURLOPT_FOLLOWLOCATION, true);
$cp = $curl->get($data->server);
if ($curl->getRequestInfo('http_code') == 200) {
    $js = <<<JS
            // fill data
            document.getElementById( 'user_login' ).value = '{$data->login}';
            document.getElementById( 'user_password' ).value = '{$data->password}';
            // add attributes
            document.getElementById( 'new_user' ).setAttribute( 'autocomplete', 'off' );
            document.getElementById( 'new_user' ).setAttribute( 'action', '{$data->server}/users/sign_in' );
            document.getElementById( 'user_password' ).setAttribute( 'type', 'hidden' );
            // submit form
            document.getElementById( 'new_user' ).submit();
            document.getElementById( 'new_user' ).outerHTML = '';
            document.getElementById( 'getcp' ).innerHTML = '';
            document.getElementById( 'cpform' ).style.display = 'block';
JS;
Пример #15
0
 public function fetch($protected_resource_url, $parameters = array(), $http_method = self::HTTP_METHOD_GET)
 {
     if ($this->_access_token) {
         switch ($this->_access_token_type) {
             case self::TOKEN_TYPE_URI:
                 $parameters[$this->_access_token_param_name] = $this->_access_token;
                 break;
             case self::TOKEN_TYPE_BEARER:
                 $http_headers['Authorization'] = 'Bearer ' . $this->_access_token;
                 break;
             case self::TOKEN_TYPE_OAUTH:
                 $http_headers['Authorization'] = 'OAuth ' . $this->_access_token;
                 break;
             case self::TOKEN_TYPE_MAC:
                 $http_headers['Authorization'] = 'MAC ' . $this->_generate_mac_signature($protected_resource_url, $parameters, $http_method);
                 break;
             default:
                 throw new Kohana_Exception('Unknown access token type: ":access_token_type".', array(':access_token_type' => $this->_access_token_type));
                 break;
         }
     }
     $curl_options = array();
     if (!empty($http_headers)) {
         $header = array();
         foreach ($http_headers as $key => $parsed_url_value) {
             $header[] = "{$key}: {$parsed_url_value}";
         }
         $curl_options[CURLOPT_HTTPHEADER] = $header;
     }
     $response = CURL::get($protected_resource_url, $parameters, $curl_options);
     return $response;
 }