public function testPostFilePathUpload() { $file_path = $this->get_png(); $data = array('key' => 'image', 'image' => '@' . $file_path); $this->curl->setOpt(CURLOPT_RETURNTRANSFER, true); $this->curl->post(self::TEST_URL . '/post_file_path_upload.php', $data); $this->assertEquals(array('request_method' => 'POST', 'key' => 'image', 'mime_content_type' => 'image/png'), json_decode($this->curl->response, true)); unlink($file_path); }
function fAlamat($lat = 0, $lon = 0) { include_once './curl.class.php'; $curl = new Curl(); // $a = $curl->post('http://ws.geonames.org/extendedFindNearby?lng='.$lon.'&lat='.$lat); $a = $curl->post('http://maps.google.com/maps/geo?q=' . $lat . ',' . $lon . '&gl=id&output=xml'); /* $r["negara"] = $a["geonames"]["geoname"][2]["name"]; $r["propinsi"] = $a["geonames"]["geoname"][3]["name"]; $r["kota"] = $a["geonames"]["geoname"][4]["name"]; */ $r["koordinat"] = $a['kml']['Response']['name']; $r["alamat"] = $a['kml']['Response']['Placemark']['address']; $r["negara"] = $a['kml']['Response']['Placemark']['AddressDetails']['Country']['CountryName']; $r["propinsi"] = $a['kml']['Response']['Placemark']['AddressDetails']['Country']['AdministrativeArea']['AdministrativeAreaName']; //if (empty($a['kml']['Response']['Placemark']['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['SubAdministrativeAreaName'])){ $r["kota"] = $a['kml']['Response']['Placemark']['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['Locality']['LocalityName']; $r["daerah"] = $a['kml']['Response']['Placemark']['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['Locality']['DependentLocalityName']; $r["jalan"] = $a['kml']['Response']['Placemark']['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['Locality']['Thoroughfare']['ThoroughfareName']; //} else { // $r["kota"] = $a['kml']['Response']['Placemark']['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['Locality']['LocalityName'] . "," . $a['kml']['Response']['Placemark'][0]['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['SubAdministrativeAreaName']; // $r["daerah"] = $a['kml']['Response']['Placemark']['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['Locality']['DependentLocality']['DependentLocalityName']; // $r["jalan"] = $a['kml']['Response']['Placemark']['AddressDetails']['Country']['AdministrativeArea']['SubAdministrativeArea']['Locality']['DependentLocality']['Thoroughfare']['ThoroughfareName']; //} return $r; }
public function createAddconditionalButton($button) { $url = $this->apiUrl . '/cgi-bin/menu/addconditional?access_token=' . $this->getAccessToken(); $content = Curl::post($url, urldecode(json_encode($this->urlencodeArray($button)))); $result = json_decode($content, true); return $this->get($result); }
public static function post($path, $data) { $curl = new Curl(); $curl->setHeader('Content-Type', 'application/json'); $curl->post(\Slim\Slim::getInstance()->globalConfig['oaUrl'] . $path, $data); return json_decode($curl->response->json, TRUE); }
public function testStoreDelete() { $data1 = ['name' => time(), 'creative_id' => 60, 'budget' => 500, 'price' => 20, 'start_time' => '2015-08-01 09:40:00', 'end_time' => '2970-01-01 00:00:00', 'fans' => '["1662047260","2977214740"]', 'age[start]' => '8', 'age[end]' => '78', 'gender' => '401', 'location' => '-1', 'device' => '110201', 'network_type[]' => '1204', 'talking_data_url' => 'http://www.baidu.com', 'ge_tui_url' => 'http://www.ba222idu.com', 'customer_id' => 3779606125]; $result = Curl::post('http://local.app.weibo.com/app/campaigns?_is_ajax=1', $data1, [$this->cookies]); echo $result; $this->assertEquals(201, Curl::getHttpCode()); // // $data1 = [ // 'customer_id' => 0, // '_method' => 'delete' // ]; // // $result = Curl::post('http://suchong.fst.weibo.com/creatives/5?_is_ajax=1', $data1, [$this->cookies]); // $this->assertEquals(200, Curl::getHttpCode()); // echo $result; // // $data1 = [ // 'customer_id' => 0, // '_method' => 'put', // 'disable_comment' => 0 // ]; // // $result = Curl::post('http://suchong.fst.weibo.com/creatives/4?_is_ajax=1', $data1, [$this->cookies]); // echo $result; // $this->assertEquals(200, Curl::getHttpCode()); }
private function send($toUser, $msgType, $data) { $url = $this->apiUrl . '/cgi-bin/message/custom/send?access_token=' . $this->getAccessToken(); $json = json_encode(array('touser' => $toUser, 'msgtype' => $msgType, $msgType => $data)); $result = Curl::post($url, $json); return $this->get($result); }
public function process_user($username, $password, $facility_code) { $curl = new Curl(); $response = array(); //Get Supplier $supplier = $this->get_supplier($facility_code); if ($supplier == "kemsa") { //Use nascop url $url = $this->default_url; $post = array("email" => $username, "password" => $password); $url = $this->default_url . 'sync/user'; $curl->post($url, $post); } else { //Use escm url $curl->setBasicAuthentication($username, $password); $curl->setOpt(CURLOPT_RETURNTRANSFER, TRUE); $url = $this->default_url . 'user/' . $username; $curl->get($url); } //Handle Response if ($curl->error) { $response['error'] = TRUE; $response['content'] = array($curl->error_code); } else { $response['error'] = FALSE; $response['content'] = json_decode($curl->response, TRUE); } return json_encode($response); }
public function getUserInfoLists($param) { $url = $this->apiUrl . '/cgi-bin/user/info/batchget?access_token=' . $this->getAccessToken(); $content = Curl::post($url, urldecode(json_encode($this->urlencodeArray($param)))); $result = json_decode($content, true); return $this->get($result); }
public function expressTakeUp($userID, $expressID) { $curl = new Curl(); $data = array("expressID" => $expressID, "userID" => $userID); $curl->post($this->url['expressTake'], $data); return $curl->response; }
public function delGroup($param) { $url = $this->apiUrl . "/cgi-bin/groups/delete?access_token={$this->access_token}"; $content = Curl::post($url, urldecode(json_encode($this->urlencodeArray($param)))); $result = json_decode($content, true); return $this->get($result); }
public function get_link() { // Check Captcha $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6LfXLBwTAAAAAKog-gWVMOmDJKhHGEMCELdR-Ukn&response=" . Input::get('g-recaptcha-response')); $obj = json_decode($response); if ($obj->success == false) { echo 'Captcha error'; exit; } else { libxml_use_internal_errors(true); require_once app_path('Libraries/Curl.php'); $url = Input::get('url'); $url = str_replace("http://", "https://", $url); // step 1: Login $curl = new \Curl(); $curl->get('https://www.fshare.vn'); $session_id = $curl->getCookie('session_id'); $doc = new \DOMDocument(); $doc->loadHTML($curl->response); $xpath = new \DOMXpath($doc); $array = $xpath->query("//*[@id='login-form']//*[@name='fs_csrf']"); foreach ($array as $value) { $fs_csrf = $value->getAttribute('value'); } $curl->setCookie('session_id', $session_id); $curl->post('https://www.fshare.vn/login', array("fs_csrf" => $fs_csrf, "LoginForm[email]" => "*****@*****.**", "LoginForm[password]" => "7508286", "LoginForm[rememberMe]" => "0", "yt0" => "Đăng nhập")); $session_id = $curl->getCookie('session_id'); $curl->setCookie('session_id', $session_id); $curl->post('https://www.fshare.vn/login', array("fs_csrf" => $fs_csrf, "LoginForm[email]" => "*****@*****.**", "LoginForm[password]" => "7508286", "LoginForm[rememberMe]" => "0", "yt0" => "Đăng nhập")); echo "Step 1: Login - Done !!! <br>"; // step 2: Get link download $curl->get($url); $doc = new \DOMDocument(); $doc->loadHTML($curl->response); $xpath = new \DOMXpath($doc); $array = $xpath->query("//*[@id='download-form']/div[1]/input"); foreach ($array as $value) { $fs_csrf = $value->getAttribute('value'); } $split_url = explode('/', $url); $curl->post('https://www.fshare.vn/download/get', array("fs_csrf" => $fs_csrf, "DownloadForm[pwd]" => "", "DownloadForm[linkcode]" => end($split_url), "ajax" => "download-form", "undefined" => "undefined")); echo "Step 2: Get Link Download - Done !!! <br><br>"; echo "URL: " . @$curl->response->url; return redirect()->away($curl->response->url); } // END IF CHECK RECAPTCHA }
private function postRequest($url, $fields) { $curl = new Curl(); $curl->addHeader('Authorization: Bearer ', $fields['code']); $curl->addOption(CURLOPT_RETURNTRANSFER, true); $request = $curl->post($url, $fields); return $request; }
static function post_json($url_mixed, $data = array()) { Yii::import('application.vendors.*'); require_once 'Tp/Curl.class.php'; $curl = new Curl(); $curl->post($url_mixed, $data); return $curl->response; }
/** * 获得access_token * */ function get_access_token($code) { $this->config->load('oauth_qq'); $curl = new Curl(); $postdata = array('grant_type' => 'authorization_code', 'code' => $code, 'client_id' => $this->config->item('api_key'), 'client_secret' => $this->config->item('api_key_secret'), 'redirect_uri' => $this->config->item('callback_url'), 'state' => '1'); $curl->options['CURLOPT_SSL_VERIFYPEER'] = false; $response = $curl->post($this->config->item('access_token_url'), $postdata); preg_match('/^access_token=.*&/', $response, $matches); $access_token = $matches[0]; $access_token = substr($access_token, 13, -1); //echo $access_token; return $access_token; }
private function getAccessToken() { $oauth_data = $this->getOAuthParameters(); $oauth_data['oauth_token'] = $_GET['oauth_token']; $oauth_data['oauth_verifier'] = $_GET['oauth_verifier']; $access_token_url = 'https://www.flickr.com/services/oauth/access_token'; $oauth_data['oauth_signature'] = $this->getSignature('POST', $access_token_url, $oauth_data); $curl = new Curl(); $curl->post($access_token_url, $oauth_data); parse_str($curl->response, $parts); $_SESSION['oauth_access_token'] = $parts['oauth_token']; $_SESSION['oauth_access_token_secret'] = $parts['oauth_token_secret']; $_SESSION['user_id'] = $parts['user_nsid']; $_SESSION['authenticated'] = true; }
function post($url, $post = null, $opts = null) { //post 传string if ($post) { $post = array_to_string($post); } $this->curl = Curl::post($url, $post); $options = array(CURLOPT_SSL_VERIFYPEER => false, CURLOPT_RETURNTRANSFER => true, CURLOPT_COOKIEFILE => $this->cookie, CURLOPT_COOKIEJAR => $this->cookie, CURLOPT_HTTPHEADER => $this->header, CURLOPT_CONNECTTIMEOUT => 100); if ($opts) { $options = array_merge($options, $opts); } $this->curl->option($options); $r = $this->curl->call(); return $r->raw_body; }
public function testToken2() { $_app_key = '4009338982'; $_app_secret = 'ffac76a449f5f2ec5a05e14097dcdee5'; $post_data = array('app_secret' => $_app_secret); $retry_count = 3; $url = 'http://i2.api.weibo.com/auth/tauth_token.json?source=' . $_app_key; while ($retry_count-- > 0) { $result = Curl::post($url, $post_data); if (Curl::getHttpCode() === 200) { break; } } //code返回 $this->assertEquals(200, Curl::getHttpCode()); }
function work() { $date = self::getStart(); $datetime1 = new DateTime($date); $datetime2 = new DateTime(date('Y-m-d')); $interval = $datetime1->diff($datetime2); $days = $interval->format('%a'); self::log("Work Start At {$date}, All {$days} Days"); while ($days > 0) { $days--; $getDate = date('Y-m-d', strtotime("-{$days}day")); $html = Curl::post(self::URL, array('date_time' => $getDate), 60); self::log("Get Date {$getDate}"); $this->getInfo($getDate, $html); } }
public function send($from, $to, $subject, $mailPlain, $mailHTML = "") { $json = array(); $json["From"] = $from; $json["To"] = $to; $json["Subject"] = $subject; if ($mailHTML != "") { $json["HtmlBody"] = $mailHTML; } $json["TextBody"] = $mailPlain; $json["TrackOpens"] = False; $postData = json_encode($json); $curl = new \Curl(); $curl->headers["Content-Type"] = "application/json"; $curl->headers["Accept"] = "application/json"; $curl->headers["X-Postmark-Server-Token"] = $this->apiKey; $res = $curl->post("https://api.postmarkapp.com/email", $postData); }
/** * @param int $scene_id 自行设定的参数(第几个二维码) * @param int $expire 正数为临时二维码 0 永久二维码 * * @return bool */ public function createQrcode($scene_id = 0, $expire = 0) { if ($expire) { //临时二维码 $data = array('action_name' => 'QR_SCENE', 'expire_seconds' => 604800, 'action_info' => array('scene' => array('scene_id' => $scene_id))); } else { //永久二维码 //永久二维码只能在1~100000 if ($scene_id < 1 || $scene_id > 100000) { $scene_id = 1; } $data = array('action_name' => 'QR_SCENE', 'action_info' => array('scene' => array('scene_id' => $scene_id))); } $url = $this->apiUrl . '/cgi-bin/qrcode/create?access_token=' . $this->getAccessToken(); $content = Curl::post($url, json_encode($data)); $result = $this->get(json_decode($content, true)); return isset($result['ticket']) ? $result['ticket'] : false; }
protected static function post($url, $data = null, $method = null) { $output = Curl::post($url, $data, $method); return $output['content']; }
public function concat($path, $sources) { $url = $this->_buildUrl($path, array('op' => 'CONCAT', 'sources' => $sources)); return Curl::post($url); }
<?php require_once "include/Delegate.php"; require_once "include/Curl.php"; $delegate = new Delegate(); $curl = new Curl(); if ($delegate->usingMinions()) { if (empty($_POST["server"])) { if (!empty($_POST["mix_id"])) { $mixId = $_POST["mix_id"]; } else { $output->error("mix_id is empty."); } // TODO: need to set this dynamically for songza etc. support $table = "8tracks_playlists"; $server = $delegate->getServer($mixId, $table); } else { $server = $_POST["server"]; if (!$delegate->verifyServer($server)) { $output->error("invalid server: " . $server); } } $results = $curl->post($server . $script, $_POST); } else { $server = "/api/stuff/download/"; $results = $curl->localPost(__DIR__ . "/download", $script); } $results = json_decode($results, true); $results["server"] = $server; $output->successWithData($results);
/** * 写图片 * @param string $blob * @param string $path * @return array * <code>array( * img_id, * block_id, * create_time, * )</code> */ function writeImage($blob, $path, $info) { $fh = fopen($path, 'r+'); fseek($fh, $info['file_id'], SEEK_SET); $imageType = $info['rimg_id'] !== 0 ? 1 : 0; $output = ''; // 写入1字节类型和状态 if ($imageType != 0) { $output .= pack('C', $imageType << 7); } else { $output .= pack('C', 0); } // 写入17字节图片id $output .= $info['img_id']; // 写入4个字节的创建时间 if (!isset($info['create_time'])) { $info['create_time'] = time(); } $output .= pack('N', intval($info['create_time'])); // 写入8个字节的md5校验码 $output .= pack('N2', $info['img_md5'] >> 32, $info['img_md5'] & 4294967295.0); if (!$imageType) { // 写入4字节长度信息 $output .= pack('N', $info['img_length']); $output .= $blob; } else { // 写入17字节参考id $output .= $info['rimg_id']; } fwrite($fh, $output); fclose($fh); unset($blob); $bNodes = $this->getBackupNodes($info['node_id'], $info['block_id']); if ($bNodes) { require_once LIB_ROOT . 'curl/Curl.php'; $curl = new Curl(); foreach ($bNodes as $bNodeId => $bNode) { $url = sprintf('%s/image/_backup', $bNode['node_url']); // 备份图片 $writeData = array('img_id' => self::_2to64($info['img_id']), 'from' => $info['file_id'], 'blob' => $output); $curl->post($url, $writeData, array(), FALSE); Logger::trace('backup to:' . $url); } } }
private function _call($call, $data = FALSE, $type = FALSE) { switch ($type) { case "post": $curl = new Curl(); $url = $this->api_host . $call . "?key={$this->key}"; $response = $curl->post($url, $data); $response = json_decode($response->body); return $response; break; case "put": $curl = new Curl(); $url = $this->api_host . $call . "?key={$this->key}"; $response = $curl->put($url, $data); $response = json_decode($response->body); return $response; break; case "delete": $curl = new Curl(); $url = $this->api_host . $call . "?key={$this->key}"; $response = $curl->request('DELETE', $url, $data); $response = json_decode($response->body); return $response; break; default: $data["key"] = $this->key; $curl = new Curl(); //$url = $this->api_host . $call . "?key=$this->key"; $url = $this->api_host . $call; $response = $curl->get($url, $data); $response = json_decode($response->body); return $response; break; } }
public function lists($param) { $url = $this->apiUrl . "/cgi-bin/material/batchget_material?access_token={$this->access_token}"; $content = Curl::post($url, urldecode(json_encode($this->urlencodeArray($param)))); $result = json_decode($content, true); return $this->get($result); }
public function preview($data) { $url = $this->apiUrl . '/cgi-bin/message/mass/preview?access_token=' . $this->getAccessToken(); $content = Curl::post($url, json_encode($data, JSON_UNESCAPED_UNICODE)); $result = json_decode($content, TRUE); return $this->get($result); }
/** * 请求 * @param type $data * @return type */ private function run($data) { $curl = new \Curl(); $fields = array('data' => json_encode($data), 'version' => SHUIPF_VERSION, 'act' => $this->act, 'identity' => $this->getIdentity(), 'token' => $this->token); //curl支持 检测 if ($curl->create() == false) { $this->error = '服务器不支持Curl扩展!'; return false; } //请求 $status = $curl->post(self::serverHot, $fields); if (false == $status) { $this->error = '无法联系服务器,请稍后再试!'; return false; } return $this->returnResolve($status); }
<?php // Perform a post-redirect-get request (POST data and follow 303 redirections // using GET requests). $curl = new Curl(); $curl->setOpt(CURLOPT_FOLLOWLOCATION, true); $curl->post('https://www.example.com/login/', array('username' => 'myusername', 'password' => 'mypassword')); // POST data and follow 303 redirections by POSTing data again. Please note // that 303 redirections should not be handled this way. // https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4 $curl = new Curl(); $curl->setOpt(CURLOPT_FOLLOWLOCATION, true); $curl->post('https://www.example.com/login/', array('username' => 'myusername', 'password' => 'mypassword'), false); // A POST request performs a post-redirect-get by default. Other request // methods force an option which conflicts with the post-redirect-get behavior. // Due to technical limitations of PHP engines <5.5.11 and HHVM, it is not // possible to reset this option. It is therefore impossible to perform a // post-redirect-get request using a php-curl-class Curl object that has already // been used to perform other types of requests. Either use a new php-curl-class // Curl object or upgrade your PHP engine.
public function post(array $data = [], $multiPartFormData = false) { return $this->curl->post()->setPostFields($data, $multiPartFormData)->execute(); }