Exemplo n.º 1
0
function getWxUserByOpenid($openid)
{
    $access_token = getAccessToken();
    $param = array('access_token' => $access_token, 'openid' => $openid, 'lang' => 'zh_CN');
    $url = "https://api.weixin.qq.com/cgi-bin/user/info";
    //获取userinfo"
    $resp = SimpleHttpClient::get($url, $param);
    $resp = parseResponse($resp);
    return $resp;
}
Exemplo n.º 2
0
 private static function build_http_query_multi($params, $files)
 {
     if (!$params) {
         return '';
     }
     $pairs = array();
     self::$boundary = $boundary = uniqid('------------------');
     $MPboundary = '--' . $boundary;
     $endMPboundary = $MPboundary . '--';
     $multipartbody = '';
     foreach ($params as $key => $value) {
         $multipartbody .= $MPboundary . "\r\n";
         $multipartbody .= 'content-disposition: form-data; name="' . $key . "\"\r\n\r\n";
         $multipartbody .= $value . "\r\n";
     }
     foreach ($files as $key => $value) {
         if (!$value) {
             continue;
         }
         if (is_array($value)) {
             $url = $value['url'];
             if (isset($value['name'])) {
                 $filename = $value['name'];
             } else {
                 $parts = explode('?', basename($value['url']));
                 $filename = $parts[0];
             }
             $field = isset($value['field']) ? $value['field'] : $key;
         } else {
             $url = $value;
             $parts = explode('?', basename($url));
             $filename = $parts[0];
             $field = $key;
         }
         $content = file_get_contents($url);
         $multipartbody .= $MPboundary . "\r\n";
         $multipartbody .= 'Content-Disposition: form-data; name="' . $field . '"; filename="' . $filename . '"' . "\r\n";
         $multipartbody .= "Content-Type: image/unknown\r\n\r\n";
         $multipartbody .= $content . "\r\n";
     }
     $multipartbody .= $endMPboundary;
     return $multipartbody;
 }
Exemplo n.º 3
0
function _oid_httpclient_test()
{
    $url_get = 'http://www.google.com';
    $c1 = new SimpleHttpClient();
    $response = $c1->get($url_get);
    if ($response) {
        list($url, $data) = $response;
        echo $data;
    } else {
        echo "test 1 failed";
    }
}
Exemplo n.º 4
0
 public function post($method, $params = array(), $files = array())
 {
     return $this->parseResponse(SimpleHttpClient::post(self::$apiEntry, $this->buildRequestParams($method, $params), $files));
 }
Exemplo n.º 5
0
<?php

include "./lib/Util.class.php";
include "./lib/SimpleHttpClient.class.php";
$dataPath = "/usr/local/data/comics";
$linkPattern = "#<div\\sclass=\"img\\-url\">//(.*?)</div>#is";
$imagePattern = "#/([-_0-9a-zA-Z]+)/([-\\._0-9a-zA-Z]+\\.\\w{3})#is";
$titlePattern = "#<title>(.*?)\\|[^\\|]*?</title>#is";
$baseUrl = "https://";
if (!isset($argv[1])) {
    die("Uso: " . $argv[0] . " url|file\n");
}
$galeryUrl = $argv[1];
$galeryUrl = str_replace("/galleries/", "/reader/", $galeryUrl);
$client = new SimpleHttpClient();
$content = $client->get($galeryUrl);
if (!preg_match_all($linkPattern, $content, $matches)) {
    die("Não foram encontradas imagens\n{$content}\n");
}
print "Foram encontradas " . count($matches[1]) . " imagens\n";
if (preg_match($titlePattern, $content, $m)) {
    $destDir = $dataPath . "/" . Util::asSlug($m[1]);
    if (!is_dir($destDir)) {
        mkdir($destDir);
    }
}
$client->setBinaryTransfer(true);
$i = 0;
foreach ($matches[1] as $link) {
    $i++;
    if (!preg_match($imagePattern, $link, $m)) {