示例#1
1
 private function doAction($url, $action_type, $data)
 {
     if ($action_type == 'get') {
         $res = json_decode(DoGet($url));
     } else {
         $res = json_decode(DoPost($url, $data));
     }
     $res = $this->obj2Array($res);
     $this->status = $res['status'];
     $this->status_message = $res['status_message'];
     return $res['data'];
 }
示例#2
1
function HttpRequest($url, $data = array(), $abort = false)
{
    if (!function_exists('curl_init')) {
        return empty($data) ? DoGet($url) : DoPost($url, $data);
    }
    $timeout = $abort ? 1 : 2;
    $ch = curl_init();
    if (is_array($data) && $data) {
        $formdata = http_build_query($data);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $formdata);
    }
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
    $result = curl_exec($ch);
    return false === $result && false == $abort ? empty($data) ? DoGet($url) : DoPost($url, $data) : $result;
}