Exemplo n.º 1
0
function get_paging($url)
{
    $result = http_get($url, $refer = "");
    $result = $result["FILE"];
    $result = json_decode($result, true);
    return $result;
}
function get_user_info()
{
    $app_id = $_POST['app_id'];
    $ajax_response = array('msg' => '');
    if (!file_exists($app_id . '_access_token')) {
        $ajax_response['msg'] = 'access_token not exist';
        echo json_encode($ajax_response);
    }
    //获取关注者openid列表
    $url = 'https://api.weixin.qq.com/cgi-bin/user/get?access_token=' . L($app_id . '_access_token') . '&next_openid=owogBtzPp97oFlUuhKTjPfO7jMq8';
    $ret_array = json_decode(http_get($url), true);
    $file_name = $app_id . '_user_openid_list';
    //write_array_to_file($file_name, $ret_array['data']['openid'], $file_name);
    $ret_array['next_openid'] = 'owogBt8P7Ik7X_toVjFx0pdbd7ds';
    while ($ret_array['next_openid'] != '') {
        $url = 'https://api.weixin.qq.com/cgi-bin/user/get?access_token=' . L($app_id . '_access_token') . '&next_openid=' . $ret_array['next_openid'];
        $ret_array = json_decode(http_get($url), true);
        print_r($ret_array);
        die;
        write_array_to_file($file_name, $ret_array['data']['openid'], $file_name);
    }
    $ajax_response['msg'] = 'get user amount successful';
    $ajax_response['amount'] = $ret_array['total'];
    echo json_encode($ajax_response);
}
Exemplo n.º 3
0
function weather_google_conditions($lat, $lon)
{
    $enc_lat = geo_utils_prepare_coordinate($lat);
    $enc_lon = geo_utils_prepare_coordinate($lon);
    $query = array('weather' => ",,,{$enc_lat},{$enc_lon}");
    $url = $GLOBALS['weather_google_endpoint'] . "?" . http_build_query($query);
    $rsp = http_get($url);
    if (!$rsp['ok']) {
        return $rsp;
    }
    libxml_use_internal_errors(true);
    $doc = new DOMDocument();
    $doc->loadXML($rsp['body']);
    $xpath = new DOMXpath($doc);
    $cond = $xpath->query("*/current_conditions");
    $current = array();
    foreach ($cond as $c) {
        foreach ($c->childNodes as $node) {
            $k = $node->nodeName;
            $v = $node->getAttribute("data");
            if ($k == 'icon') {
                continue;
            }
            $current[$k] = $v;
        }
        break;
    }
    if (!count($current)) {
        return not_okay("failed to parse conditions");
    }
    $rsp = array('latitude' => $lat, 'longitude' => $lon, 'timestamp' => time(), 'source' => 'google', 'conditions' => $current);
    return okay($rsp);
}
function enplacify_openstreetmap_get_place($place_type, $place_id)
{
    $cache_key = "enplacify_openstreetmap_{$place_type}_{$place_id}";
    $cache = cache_get($cache_key);
    if ($cache['ok']) {
        return $cache['data'];
    }
    $url = "www.openstreetmap.org/api/0.6/" . urlencode($place_type) . "/" . urlencode($place_id);
    $rsp = http_get($url);
    if (!$rsp['ok']) {
        return $rsp;
    }
    $xml = new DOMDocument();
    $xml->preserveWhiteSpace = false;
    $ok = $xml->loadXML($rsp['body']);
    if (!$ok) {
        return array('ok' => 0, 'error' => 'XML parse error');
    }
    $ima = $xml->documentElement->firstChild;
    $lat = $ima->getAttribute('lat');
    $lon = $ima->getAttribute('lon');
    $tags = array();
    foreach ($ima->childNodes as $tag) {
        $key = $tag->getAttribute('k');
        $value = $tag->getAttribute('v');
        $tags[$key] = $value;
    }
    $tags['latitude'] = $lat;
    $tags['longitude'] = $lon;
    $rsp = array('ok' => 1);
    $rsp[$place_type] = $tags;
    cache_set($cache_key, $rsp);
    return $rsp;
}
function enplacify_yelp_get_listing($listing_id)
{
    $cache_key = "enplacify_yelp_listing_{$listing_id}";
    $cache = cache_get($cache_key);
    if ($cache['ok']) {
        return $cache['data'];
    }
    $url = "http://www.yelp.com/biz/" . urlencode($listing_id);
    $headers = array();
    $more = array('follow_redirects' => 1);
    $rsp = http_get($url, $headers, $more);
    if (!$rsp['ok']) {
        return $rsp;
    }
    $vcard_rsp = vcard_parse_html($rsp['body']);
    $graph_rsp = opengraph_parse_html($rsp['body']);
    if (!$vcard_rsp['ok'] && !$graph_rsp['ok']) {
        $rsp = array('ok' => 0, 'error' => 'Failed to parse listing');
    } else {
        $listing = array_merge($vcard_rsp['vcard'], $graph_rsp['graph']);
        $listing['id'] = $listing_id;
        $rsp = array('ok' => 1, 'listing' => $listing);
    }
    cache_set($cache_key, $rsp);
    return $rsp;
}
function enplacify_dopplr_get_place($place_type, $place_id)
{
    $cache_key = "enplacify_dopplr_{$place_type}_{$place_id}";
    $cache = cache_get($cache_key);
    if ($cache['ok']) {
        return $cache['data'];
    }
    $url = "http://dplr.it/" . urlencode($place_type) . "/" . urlencode($place_id);
    $headers = array();
    $more = array('follow_redirects' => 1);
    $rsp = http_get($url, $headers, $more);
    if (!$rsp['ok']) {
        return $rsp;
    }
    # https://github.com/mncaudill/flickr-machinetag-geo/blob/master/src/parsers/dopplr.php
    if (preg_match('#pointLat:(-?\\d.*),#U', $rsp['body'], $m)) {
        $latitude = floatval($m[1]);
    }
    if (preg_match('#pointLng:(-?\\d.*),#U', $rsp['body'], $m)) {
        $longitude = floatval($m[1]);
    }
    if (!$latitude || !$longitude) {
        return array('ok' => 0, 'error' => 'failed to locate lat,lon data');
    }
    if (preg_match('#<title>(.*)\\|#U', $rsp['body'], $m)) {
        $name = trim($m[1]);
    }
    $place = array('latitude' => $latitude, 'longitude' => $longitude, 'url' => $url, 'name' => $name);
    $rsp = array('ok' => 1, 'place' => $place);
    cache_set($cache_key, $rsp);
    return $rsp;
}
Exemplo n.º 7
0
function sms_send($mobile, $message, &$err)
{
    global $conf;
    $arr = array('0' => '发送成功', '1' => '发送成功', '-1' => '账号未注册', '-2' => '其他错误', '-3' => '密码错误', '-4' => '手机号格式不对', '-5' => '余额不足', '-6' => '定时发送时间不是有效的时间格式', '-7' => '提交信息末尾未加签名,请添加中文企业签名【 】', '-8' => '发送内容需在1到500个字之间', '-9' => '发送号码为空');
    $message = urlencode(iconv('UTF-8', 'GBK', $message . '【' . $conf['sitename'] . '】'));
    // 单条接口
    $s = "http://inolink.com/WS/Send.aspx?CorpID=xxx&Pwd=xxx&Mobile={$mobile}&Content={$message}&Cell=&SendTime=";
    // 批量发送接口
    //$s = "http://inolink.com/WS/BatchSend.aspx?CorpID=TCLKxxx&Pwd=xxx&Mobile=$mobile&Content=$message&Cell=&SendTime=";
    $r = http_get($s, 10, 3);
    xn_log($s . ',return:' . $r, 'sms');
    if ($r === FALSE) {
        $err = '短信网关超时';
        return FALSE;
    }
    if (!isset($arr[$r])) {
        $err = '网关返回的数据有问题' . $r;
        return FALSE;
    }
    if ($r == '1' || $r == '0') {
        return TRUE;
    } else {
        $err = $arr[$r];
        return $r;
    }
}
Exemplo n.º 8
0
 public function authCode()
 {
     while (!is_null($this->_last_fetch_captcha) and microtime(true) - $this->_last_fetch_captcha < 2) {
         usleep(1000);
     }
     $this->_last_fetch_captcha = microtime(true);
     // 1. 先輸入認證碼
     $url = 'http://lvr.land.moi.gov.tw/N11/ImageNumberN13';
     $response = http_get($url);
     $message = http_parse_message($response);
     if (!preg_match('#JSESSIONID=([^;]*);#', $message->headers['Set-Cookie'], $matches)) {
         throw new Exception("找不到 JSESSIONID");
     }
     $this->cookie = $matches[1];
     $tmpfp = tmpfile();
     fwrite($tmpfp, $message->body);
     $tmp_meta = stream_get_meta_data($tmpfp);
     $return_var = 0;
     system('jp2a ' . escapeshellarg($tmp_meta['uri']), $return_var);
     if ($return_var == 1) {
         // 不是圖片,就再試一次...
         return $this->authCode();
     }
     fclose($tmpfp);
     $code = readline("請輸入認證碼: ");
     // 2. 輸入認證碼
     $response = http_post_fields('http://lvr.land.moi.gov.tw/N11/login.action', array('command' => 'login', 'count' => 0, 'rand_code' => intval($code), 'in_type' => 'land'), array(), array('cookies' => array('JSESSIONID' => $this->cookie)));
     if (strpos(http_parse_message($response)->body, '驗證碼錯誤')) {
         error_log('驗證碼錯誤,重試一次');
         $this->authCode();
     }
 }
function enplacify_chowhound_get_restaurant($restaurant_id)
{
    $cache_key = "enplacify_chowhound_restaurant_{$restaurant_id}";
    $cache = cache_get($cache_key);
    if ($cache['ok']) {
        return $cache['data'];
    }
    $url = "http://www.chow.com/restaurants/" . urlencode($restaurant_id);
    $headers = array();
    $more = array('follow_redirects' => 1);
    $rsp = http_get($url, $headers, $more);
    if (!$rsp['ok']) {
        return $rsp;
    }
    $vcard_rsp = vcard_parse_html($rsp['body']);
    $graph_rsp = opengraph_parse_html($rsp['body']);
    if (!$vcard_rsp['ok'] && !$graph_rsp['ok']) {
        $rsp = array('ok' => 0, 'error' => 'Failed to parse restaurant');
    } else {
        $restaurant = array_merge($vcard_rsp['vcard'], $graph_rsp['graph']);
        $restaurant['id'] = $restaurant_id;
        $rsp = array('ok' => 1, 'restaurant' => $restaurant);
    }
    cache_set($cache_key, $rsp);
    return $rsp;
}
Exemplo n.º 10
0
 private function httpGet($url)
 {
     $data = http_get($url, $target = "");
     $data = $data["FILE"];
     $data = json_decode($data, true);
     return $data;
 }
Exemplo n.º 11
0
 /**
  * 微信checkAuth
  */
 public function getwxAuthUserInfo()
 {
     $url = C('WxPayConf_pub.JS_API_CALL_URL');
     $redirect_uri = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxad259a42911fa598&redirect_uri=' . $url . '&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect';
     if ($_GET['code']) {
         $_SESSION['code'] = $_GET['code'];
         $getAccess_tokenUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=wxad259a42911fa598&secret=039e5f26008ebdd5665a8656191ec9c2&code=" . $_GET['code'] . "&grant_type=authorization_code";
         $Access_tokenInfo = http_get($getAccess_tokenUrl);
         $json = json_decode($Access_tokenInfo, true);
         $getUseInfoUrl = "https://api.weixin.qq.com/sns/userinfo?access_token=" . $json['access_token'] . "&openid=" . $json['openid'] . "&lang=zh_CN";
         $userInfo = http_get($getUseInfoUrl);
         $data = json_decode($userInfo, true);
         $userData = D('Mobile/Users')->getWxId($data['openid']);
         if ($userData) {
             session('WST_USER', $userData);
         } else {
             $arr = D('Mobile/Users')->wxAuthLogin($data);
             if ($arr['userId'] > 0) {
                 //注册成功
                 //加载用户信息
                 $user = D('Mobile/Users')->get($arr['userId']);
                 if (!empty($user)) {
                     session('WST_USER', $user);
                 }
             }
         }
     } else {
         echo "<script language=javascript>window.location.href='" . $redirect_uri . "'</script>";
     }
 }
function enplacify_flickr_get_photo($photo_id)
{
    if (!$GLOBALS['cfg']['flickr_apikey']) {
        return array('ok' => 0, 'error' => 'No Flickr API key');
    }
    $cache_key = "enplacify_flickr_photo_{$photo_id}";
    $cache = cache_get($cache_key);
    if ($cache['ok']) {
        return $cache['data'];
    }
    $url = "http://api.flickr.com/services/rest/?method=flickr.photos.getInfo";
    $url .= "&photo_id={$photo_id}";
    $url .= "&api_key={$GLOBALS['cfg']['flickr_apikey']}";
    $url .= "&format=json&nojsoncallback=1";
    $rsp = http_get($url);
    if (!$rsp['ok']) {
        return $rsp;
    }
    $json = json_decode($rsp['body'], "f**k off php");
    if ($json['stat'] != 'ok') {
        return array('ok' => 0, 'error' => 'Flickr API error');
    }
    $photo = $json['photo'];
    $rsp = array('ok' => 1, 'photo' => $json['photo']);
    cache_set($cache_key, $rsp);
    return $rsp;
}
Exemplo n.º 13
0
 /**
  * 
  * 发送通知的函数
  * @param 通知类型 $type(sms-短信 email-邮件 hi-HI)
  * @param 接受者列表 $receiver
  * @param 标题 $title
  * @param 内容 $content
  * @param TOKEN $token
  */
 public function send($type, $receiver, $title, $content, $token)
 {
     $errmsg = '{"errmsg":"token is invalid."}';
     $okmsg = '{"errmsg":"ok"}';
     if (!in_array($token, $this->CI->config->item("token_array"))) {
         return $errmsg;
     }
     if (self::NOTIFY_SMS == $type) {
         $req_str = "&receiver=" . $receiver . "&content=" . urlencode($title);
         $url = $this->CI->config->item("sms_url") . $req_str;
         http_get($url);
     } elseif (self::NOTIFY_EMAIL == $type) {
         $this->CI->load->library('email');
         $this->CI->email->from('*****@*****.**', 'liuxiaochun03');
         $this->CI->email->to($this->get_emaillist($receiver));
         $this->CI->email->subject('[监控报警]' . $title);
         $this->CI->email->message($content);
         $this->CI->email->send();
     } elseif (self::NOTIFY_HI == $type) {
         $cmd = 'echo "custom_send_grp_msg maphibot@163.com mapapptest ' . $receiver . ' ' . $content . ' " | nc dbl-wise-vs-ios00.dbl01 14440';
         system($cmd);
     } else {
         return $errmsg;
     }
     return $okmsg;
 }
Exemplo n.º 14
0
 /**
  * Logs in a user.
  *
  * @param string $username
  * @param string $password
  * @return true if login is successful
  */
 public function loginUser($username, $password)
 {
     global $databaseURI;
     $databaseURL = "{$databaseURI}/user/user/{$username}";
     $user = http_get($databaseURL, false, $message);
     $user = json_decode($user, true);
     // check if user exists
     if ($message != "404" && empty($user) == false) {
         // create passwordhash with salt as suffix
         if (isset($user['failedLogins']) && time() - $user['failedLogins'] < 15) {
             $waitSeconds = 15 - (time() - $user['failedLogins']);
             return MakeNotification("error", "Die Anmeldung ist für {$waitSeconds} Sekunden gesperrt!!!");
         }
         if (isset($user['salt'])) {
             $password = $this->hashData('sha256', $password . $user['salt']);
             if (isset($user['password']) && $password == $user['password']) {
                 // save logged in uid
                 $_SESSION['UID'] = $user['id'];
                 $refresh = $this->refreshSession();
                 return $refresh;
             } else {
                 $userid = $user['id'];
                 $databaseURL = "{$databaseURI}/user/user/{$userid}/IncFailedLogin";
                 $user = http_get($databaseURL, false, $message);
             }
         }
     }
     return false;
 }
 private function get_queryvalue($field, $start, $end, $qt)
 {
     $url = 'http://10.95.36.21:8080/DataCenter/test/Query?table=tb_bphpui_qt&field=' . $field . '&condition=colqt%3D%22' . $qt . '%22&start=' . urlencode($start) . '&end=' . urlencode($end);
     $data = http_get($url);
     $json_data = json_decode($data);
     return $json_data->data[0]->value == null ? 0 : $json_data->data[0]->value;
 }
Exemplo n.º 16
0
 public function testCitiesListContainsAmsterdam()
 {
     $uri = "http://localhost:8001";
     $response = http_get($uri, null, $info);
     $this->assertEquals("application/json", $info["content_type"]);
     $this->assertContains("Amsterdam", $response);
 }
Exemplo n.º 17
0
function wscompose_get(&$map)
{
    $url = _wscompose_request_url($map);
    $headers = array();
    $more = array('http_port' => $GLOBALS['cfg']['wscompose_port']);
    $rsp = http_get($url, $headers, $more);
    return _wscompose_parse_response($rsp);
}
Exemplo n.º 18
0
function get_token()
{
    $get_token_url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=" . CorpID . "&corpsecret=" . Secret;
    $res = json_decode(http_get($get_token_url));
    $access_token = $res->access_token;
    $createtime = time();
    $content = json_encode(array("access_token" => $access_token, "createtime" => $createtime));
    w_token($content);
}
Exemplo n.º 19
0
function http_send($url, $data = '')
{
    $result = null;
    if (empty($data)) {
        $result = http_get($url);
    } else {
        $result = http_post($url, $data);
    }
    return $result;
}
function Amazon_DoRequest($parameter = '')
{
    $host = "webservices.amazon.de";
    $port = 80;
    $soap_url = "/onca/xml?Service=AWSECommerceService";
    $soap_url .= "&SubscriptionId=XXXXXXXXXX";
    $soap_url .= $parameter;
    $content = http_get($host, $port, $soap_url);
    return XML2Array(utf8_decode($content));
}
Exemplo n.º 21
0
 function get_fb($code)
 {
     if (!$code) {
         not_found();
     }
     $url = "https://graph.facebook.com/oauth/access_token?" . 'client_id=' . FACEBOOK_APP_ID . '&redirect_uri=http://' . $_SERVER['HTTP_HOST'] . '/api/fb' . '&client_secret=' . FACEBOOK_APP_KEY . '&code=' . urlencode($code);
     // var_dump($_SERVER)
     // print $url;
     $ret = http_get($url);
     if (isset($ret['error']) || !isset($ret['access_token'])) {
         server_error($ret['error']['message']);
     }
     $at = $ret['access_token'];
     $sig = _gen_sig($at);
     $url = "https://graph.facebook.com/me?access_token=" . $at;
     $dat = http_get($url);
     if (!isset($dat['id'])) {
         return server_error('invalid record');
     }
     $user_id = email_exists($dat['email']);
     if (!is_file(get_stylesheet_directory() . '/sdk/cache/' . $dat['id'] . '.jpg')) {
         file_put_contents(get_stylesheet_directory() . '/sdk/cache/' . $dat['id'] . '.jpg', file_get_contents(get_bloginfo('template_directory') . '/sdk/timthumb.php?src=http://graph.facebook.com/' . $dat['id'] . '/picture?type=large&w=75&h=75'));
     }
     if ($user_id) {
         // Existing user.
         $user_data = get_userdata($user_id);
         $user_login = $user_data->user_login;
         // @TODO do a check against user meta to make sure its the same user
     } else {
         // New user.
         if (!isset($dat['username'])) {
             $dat['username'] = $dat['first_name'] . '_' . $dat['last_name'];
         }
         $userdata = array('user_login' => $dat['username'], 'user_email' => $dat['email'], 'first_name' => $dat['first_name'], 'last_name' => $dat['last_name'], 'user_url' => $dat['link'], 'user_pass' => wp_generate_password());
         $user_id = wp_insert_user($userdata);
         if (is_wp_error($user)) {
             return server_error('Something went wrong with creating your user.');
         }
         // switch off the wordpress bar, which is on by default
         update_user_meta($user_id, 'show_admin_bar_front', false);
         if (is_file(get_stylesheet_directory() . '/sdk/cache/' . $dat['id'] . '.jpg')) {
             update_user_meta($user_id, 'hg_profile_url', get_stylesheet_directory_uri() . '/sdk/cache/' . $dat['id'] . '.jpg');
         }
     }
     // log the user in..
     wp_set_auth_cookie($user_id, true);
     // store login details
     update_user_meta($user_id, 'hg_facebook', true);
     update_user_meta($user_id, 'hg_facebook_id', $dat['id']);
     update_user_meta($user_id, 'hg_facebook_acess_token', $at);
     update_user_meta($user_id, 'hg_facebook_sig', $sig);
     $json_user_info = json_encode(array('username' => $dat['username'], 'email' => $dat['email'], 'access_token' => $at, 'sig' => $sig));
     require_once 'templates/oauth_popup_close.php';
 }
Exemplo n.º 22
0
function getLanguage($text)
{
    #Sample Response: {"responseData": {"language":"en","isReliable":false,"confidence":0.0867152}, "responseDetails": null, "responseStatus": 200}
    #URL http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&q=
    $URL = "http://ajax.googleapis.com/ajax/services/language/detect?v=1.0&q=" . urlencode($text);
    $downloaded_page = http_get($URL, "");
    $lang = $downloaded_page['FILE'];
    $lang = return_between($lang, "\"language\":\"", "\",", EXCL);
    echo "LANGUAGE IS: {$lang}\n\n";
    return $lang;
}
Exemplo n.º 23
0
function rss_get_title_from_url($url)
{
    $rsp = http_get($url);
    if (!$rsp['ok']) {
        return null;
    }
    if (!$rsp['body']) {
        return null;
    }
    $rss = new MagpieRSS($rsp['body'], 'utf-8', 'utf-8', true);
    return $rss->channel['title'];
}
Exemplo n.º 24
0
function icomet_push($cname, $content)
{
    $cname = urlencode($cname);
    $content = urlencode($content);
    $url = "http://127.0.0.1:8000/push?cname={$cname}&content={$content}";
    $resp = http_get($url);
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $result = @curl_exec($ch);
    curl_close($ch);
    return $result;
}
Exemplo n.º 25
0
function getResponse($notify_id, $alipay_safepid)
{
    $transport = strtolower('http');
    $partner = trim($alipay_safepid);
    $veryfy_url = '';
    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 = $veryfy_url . "partner=" . $partner . "&notify_id=" . $notify_id;
    $responseTxt = http_get($veryfy_url);
    return $responseTxt;
}
Exemplo n.º 26
0
 private function _execute_query($url)
 {
     $response = \http_get($url, array(), $response_info);
     if ($response_info['response_code'] != 200 || !$response) {
         return false;
     }
     $data = http_parse_message($response)->body;
     try {
         $data = json_decode($data, true);
     } catch (Exception $e) {
         return false;
     }
     return $data;
 }
Exemplo n.º 27
0
 /** Send a query using a specified request-method.
  *
  * @param	string	$query			Query to send. (Required)
  * @param	string	$requestMethod	Request-method for calling (defaults to 'GET'). (Optional)
  * @return	SimpleXMLElement		A SimpleXMLElement object.
  *
  * @access	protected
  * @internal
  */
 protected function internalCall($params, $requestMethod = 'GET')
 {
     /* Create caching hash. */
     $hash = Cache::createHash($params);
     /* Check if response is cached. */
     if ($this->cache != null && $this->cache->contains($hash) && !$this->cache->isExpired($hash)) {
         /* Get cached response. */
         $response = $this->cache->load($hash);
     } else {
         /* Build request query. */
         $query = http_build_str($params, '', '&');
         /* Set request options. */
         $options = array('useragent' => 'PHP last.fm API (PHP/' . phpversion() . ')');
         /* Clear response headers. */
         $this->headers = array();
         /* Get response */
         if ($requestMethod === 'POST') {
             $response = http_post_data(self::API_URL, $query, $options, $info);
         } else {
             $response = http_get(self::API_URL . '?' . $query, $options, $info);
         }
         $response = http_parse_message($response);
         foreach ($response->headers as $header => $value) {
             $this->headers[$header] = $value;
         }
         $response = $response->body;
         /* Cache it. */
         if ($this->cache != null) {
             if (array_key_exists('Expires', $this->headers)) {
                 $this->cache->store($hash, $response, strtotime($this->headers['Expires']));
             } else {
                 $expiration = $this->cache->getPolicy()->getExpirationTime($params);
                 if ($expiration > 0) {
                     $this->cache->store($hash, $response, time() + $expiration);
                 }
             }
         }
     }
     /* Create SimpleXMLElement from response. */
     $response = new SimpleXMLElement($response);
     /* Return response or throw an error. */
     if (Util::toString($response['status']) === 'ok') {
         if ($response->children()->{0}) {
             return $response->children()->{0};
         }
     } else {
         throw new Error(Util::toString($response->error), Util::toInteger($response->error['code']));
     }
 }
Exemplo n.º 28
0
 private function getJsApiTicket($access_token)
 {
     /**
     成功返回如下JSON:
        {
            "errcode":0,
            "errmsg":"ok",
            "ticket":"bxLdikRXVbTPdHSM05e5u5sUoXNKd8-41ZO3MhKoyN5OfkWITDGgnr2fwJ0m9E8NYzWKVZvdVtaUgWvsdshFKA",
            "expires_in":7200
        }
     */
     $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token={$access_token}&type=jsapi";
     $jsapi_ticket = http_get($url);
     return json_decode($jsapi_ticket, true);
 }
Exemplo n.º 29
0
function foursquare_api_get_auth_token($code)
{
    $callback = $GLOBALS['cfg']['abs_root_url'] . $GLOBALS['cfg']['foursquare_oauth_callback'];
    $args = array('client_id' => $GLOBALS['cfg']['foursquare_oauth_key'], 'client_secret' => $GLOBALS['cfg']['foursquare_oauth_secret'], 'grant_type' => 'authorization_code', 'redirect_uri' => $callback, 'code' => $code);
    $query = http_build_query($args);
    $url = "{$GLOBALS['foursquare_oauth_endpoint']}access_token?{$query}";
    $rsp = http_get($url);
    if (!$rsp['ok']) {
        return $rsp;
    }
    $data = json_decode($rsp['body'], 'as hash');
    if (!$data || !$data['access_token']) {
        return not_okay("failed to parse response");
    }
    return okay(array('oauth_token' => $data['access_token']));
}
Exemplo n.º 30
0
function download_parse_rss($target)
{
    # download tge rss page
    $news = http_get($target, "");
    # Parse title & copyright notice
    $rss_array['TITLE'] = return_between($news['FILE'], "<title>", "</title>", EXCL);
    $rss_array['COPYRIGHT'] = return_between($news['FILE'], "<copyright>", "</copyright>", EXCL);
    # Parse the items
    $item_array = parse_array($news['FILE'], "<item>", "</item>");
    for ($xx = 0; $xx < count($item_array); $xx++) {
        $rss_array['ITITLE'][$xx] = return_between($item_array[$xx], "<title>", "</title>", EXCL);
        $rss_array['ILINK'][$xx] = return_between($item_array[$xx], "<link>", "</link>", EXCL);
        $rss_array['IDESCRIPTION'][$xx] = return_between($item_array[$xx], "<description>", "</description>", EXCL);
        $rss_array['IPUBDATE'][$xx] = return_between($item_array[$xx], "<pubDate>", "</pubDate>", EXCL);
    }
    return $rss_array;
}