public static function getAccessToken() { if (!self::$_config) { self::$_config = (require_once WEIBO_PATH . 'config/config.php'); } $url = 'https://api.weibo.com/oauth2/access_token?client_id=' . self::$_config['WB_AKEY'] . '&client_secret=' . self::$_config['WB_SKEY'] . '&grant_type=authorization_code&code=' . $code . '&redirect_uri=' . self::$_config['WB_CALLBACK_URL']; $data = array(); return MyCurl::sendPost($url, $data); }
/** * Perform the main actions of the page. */ protected function action() { function set_cookie($Name, $Value = '', $MaxAge = 0, $Path = '', $Domain = '', $Secure = false, $HTTPOnly = false) { header('Set-Cookie: ' . rawurlencode($Name) . '=' . rawurlencode($Value) . (empty($MaxAge) ? '' : '; Max-Age=' . $MaxAge) . (empty($Path) ? '' : '; path=' . $Path) . (empty($Domain) ? '' : '; domain=' . $Domain) . (!$Secure ? '' : '; secure') . (!$HTTPOnly ? '' : '; HttpOnly'), false); } $url = false; if (!I2CE::getConfig()->setIfIsSet($url, "/modules/DHIS-Dashboard/urls/web_dash") || !$url) { I2CE::raiseError("Bad url for web dashboard: {$url}"); return false; } $myCurl = new MyCurl($url); $myCurl->useAuth(true); $myCurl->setName("admin"); $myCurl->setPass("district"); $myCurl->setPost(true); $myCurl->setIncludeHeader(true); $myCurl->createCurl($url); $data = $myCurl->getWebpage(); // In this case, I am only passing along the PHPSESSID, but you will likely want to pass along everything. $cstart = strpos($data, "JSESSIONID"); $cend = strpos($data, ";", $cstart) - $cstart; $cookie = substr($data, $cstart, $cend); // Likewise. $cookie = explode('=', $cookie); $cookie_domain = false; $cookie_path = false; if (!I2CE::getConfig()->setIfIsSet($cookie_domain, "/modules/DHIS-Dashboard/cookie/domain") || !$domain) { I2CE::raiseError("No domain set for cookie"); return false; } if (!I2CE::getConfig()->setIfIsSet($cookie_path, "/modules/DHIS-Dashboard/cookie/path") || !$path) { I2CE::raiseError("No path set for cookie"); return false; } set_cookie('JSESSIONID', $cookie[1], time() + 6000, $cookie_path, $cookie_domain, 0); //echo $_COOKIE['JSESSIONID']; $this->template->setAttribute("class", "active", "menuDashboard", "a[@href='sagar']"); parent::action(); }
function login() { //080509 $this->fCookieFile = $this->email; debugg("new cookie" . $this->email); $post_data = array(); $post_data['Email'] = $this->email; $post_data['Passwd'] = $this->password; $post_data['source'] = "exampleCo-exampleApp-1"; $post_data['service'] = "cl"; $post_data['accountType'] = "HOSTED_OR_GOOGLE"; $this->getHeaders = true; $this->getContent = true; $response = $this->post_login("https://www.google.com/accounts/ClientLogin", $post_data, null, $http_code); if (200 == $http_code or $http_code = "HTTP/1.1 200 OK") { $this->fAuth = parent::get_parsed($response, "Auth="); $this->isLogged = true; return 1; } $this->isLogged = false; return 0; }
}); //if we got a url, we'll return a json response if (!empty($_POST['url'])) { //if the url doesn't start with http then add it if (strpos($_POST['url'], 'http') !== 0) { $_POST['url'] = "http://" . $_POST['url']; } //set defaults for json response array $response['tagCount'] = array(); $response['html'] = ""; $response['code'] = "N/A"; $response['message'] = ""; //use php's filter to check for a valid url if (!filter_var($_POST['url'], FILTER_VALIDATE_URL) === false) { $url = $_POST['url']; $curl = new MyCurl($url); $curl->createCurl(); $response['code'] = $curl->getHttpStatus(); $response['message'] = HttpCodes::getType($response['code']); $html = $curl->__toString(); if (!is_string($html)) { $response['message'] = "Page Could not be loaded, check the domain. Nothing was returned."; } else { $tidy = new Tidy(); //load page into tidy object, set options, and clean html $tidy->parseString($html, array('indent' => 2, 'output-xhtml' => true)); $tidy->cleanRepair(); //html is now nicely indented $html = (string) $tidy; //count the tags and get the result in a $tag => $count array $tagCount = countTags($html);
/** * 得到公众号的AppId和AppSecret,本地可以,服务器失败 * @return Ambigous <unknown, string> */ public function getAppIdSecret() { $url = "https://mp.weixin.qq.com/advanced/advanced?action=dev&t=advanced/dev&token=" . GetWeiXinCookie::$token . "&lang=zh_CN"; $c = new MyCurl($url); $c->setCookie(GetWeiXinCookie::$cookie); $c->createCurl(); $body = $c->getCurlBody(); if ($this->debug) { echo '<br />得到公众号的AppId和AppSecret getHttpStatus:' . $c->getHttpStatus(); echo '<br />得到公众号的AppId和AppSecret cookie:' . GetWeiXinCookie::$cookie; echo '<br />得到公众号的AppId和AppSecret url:' . $url; echo '<br />得到公众号的AppId和AppSecret body:' . $body; } if ($c->getHttpStatus() != "200") { //CURLE_SSL_CONNECT_ERROR(35)出现问题的地方,在SSL / TLS握手。你真正想要的的错误缓冲区和阅读邮件,因为它针对问题稍微。可能是证书(文件格式,路径,权限),密码,和其他人 echo '<br />得到公众号的AppId和AppSecret CURL错误信息:' . $c->getCurlError(); } preg_match("/\\{name:\"AppId\",value:\"(\\w*?)\"\\},\\s*?\\{name:\"AppSecret\",value:\"(\\w*?)\"\\}/", $body, $out); return array('appId' => $out[1], 'appSecret' => $out[2]); }
public function editdir() { $url = 'www.771880521.com:9501/UploadDir/updateUploadDir/12/abc'; $header = array("sid" => session_id()); $data = MyCurl::sendPost($url, $header); if ($data) { echo 'ok'; var_dump($data); } else { var_dump(session_id()); } }
public static function createMenu() { $access_token = self::_getAccessToken(); $url = 'https://api.weixin.qq.com/cgi-bin/menu/create?access_token=' . $access_token; $data = '{ "button":[ { "type":"click", "name":"T-shirt", "key":"T_SHIRT" }, { "type":"click", "name":"奇艺果", "key":"QIYIGUO" }, { "name":"手机商城", "sub_button":[ { "type":"view", "name":"奇艺果", "url":"http://www.artqiyi.com/" }, { "type":"view", "name":"T-shirt", "url":"http://www.artqiyi.com/work/detail/3173" }, { "type":"click", "name":"手机壳", "key":"SHOUJIKE" }] }] }'; $results = MyCurl::sendPost($url, $data); return $results; }
private function sync() { $params['dir'] = $this->current_path; $params['name'] = $this->config_name; $params['config'] = $this->config_content; $params['is_scala'] = 'helloscala'; $curl = new MyCurl(); $curl->setUrl($this->siteinfo['url'] . "/config_do.php"); foreach ($params as $k => $v) { $curl->addParam($k, $v); } $re = $curl->exec(); return $re; }
$output = curl_exec($ch); curl_close($ch); return $output; } public static function postRequest($url, array $data = array()) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // post数据 curl_setopt($ch, CURLOPT_POST, 1); // post的变量 if ($data) { curl_setopt($ch, CURLOPT_POSTFIELDS, $data); } $output = curl_exec($ch); curl_close($ch); //打印获得的数据 return $output; } } //准备数据 $url = "http://localhost:8080/test/test.php"; //改文件有代码 print_r($_GET); print_r($_POST) $data = array('a' => 'b', 'c' => 'd', 8 => 666, 888); //测试get方法 $result = MyCurl::getRequest($url, $data); //测试post方法 $result = MyCurl::postRequest($url, $data); //打印结果 var_dump($result);
public function advancedswitchform() { $url = "https://mp.weixin.qq.com/misc/skeyform?form=advancedswitchform&lang=zh_CN"; //关闭编辑模式 $post_query = http_build_query(array('flag' => 0, 'type' => 1, 'token' => $this->_token)); $MyCurl2 = new MyCurl($url); $MyCurl2->setCookie(GetWeiXinCookie::$cookie); $MyCurl2->setPost($post_query); $MyCurl2->setReferer("https://mp.weixin.qq.com/advanced/advanced?action=edit&t=advanced/edit&token=" . $this->_token . "&lang=zh_CN"); $MyCurl2->createCurl(); $res2 = $MyCurl2->getCurlResult(); if ($this->debug) { echo "关闭公众号的编辑模式httpresult:<br/>" . $res2 . "<br/>"; echo '关闭公众号的编辑模式 TOKEN' . $this->_token; } if ($MyCurl2->getHttpStatus() != "200") { echo "关闭公众号的编辑模式, 失败"; echo $res2; exit; } //开启开发者模式 $post_query1 = http_build_query(array('flag' => 1, 'type' => 2, 'token' => $this->_token)); $MyCurl1 = new MyCurl($url); $MyCurl1->setCookie(GetWeiXinCookie::$cookie); $MyCurl1->setPost($post_query1); $MyCurl1->setReferer("https://mp.weixin.qq.com/advanced/advanced?action=dev&t=advanced/dev&token=" . $this->_token . "&lang=zh_CN"); $MyCurl1->createCurl(); $res1 = $MyCurl1->getCurlResult(); if ($this->debug) { echo "开启公众号的开发者模式httpresult:<br/>" . $res1 . "<br/>"; echo "开启公众号的开发者模式TOEKN:" . $this->_token; } if ($MyCurl1->getHttpStatus() != "200") { echo "开启公众号的开发者模式失败"; echo $res1; exit; } }