public static function sendRequest($req) { $rsp = Http::send($req); $info = Http::info(); $ret = json_decode($rsp, true); if ($ret) { if (0 === $ret['code']) { $ret['httpcode'] = $info['http_code']; return $ret; } else { return array('httpcode' => $info['http_code'], 'code' => $ret['code'], 'message' => $ret['message'], 'data' => array()); } } else { return array('httpcode' => $info['http_code'], 'code' => self::COSAPI_NETWORK_ERROR, 'message' => $rsp, 'data' => array()); } }
public static function del($bucket, $fileid, $userid = 0) { if (!$fileid) { return array('httpcode' => 0, 'code' => self::IMAGE_PARAMS_ERROR, 'message' => 'params error', 'data' => array()); } $expired = 0; $url = self::generateResUrl($bucket, $userid, $fileid, 'del'); $sign = Auth::getAppSignV2($bucket, $fileid, $expired); $req = array('url' => $url, 'method' => 'post', 'timeout' => 10, 'header' => array('Authorization:QCloud ' . $sign)); $rsp = Http::send($req); $info = Http::info(); $ret = json_decode($rsp, true); if ($ret) { if (0 === $ret['code']) { return array('httpcode' => $info['http_code'], 'code' => $ret['code'], 'message' => $ret['message'], 'data' => array()); } else { return array('httpcode' => $info['http_code'], 'code' => $ret['code'], 'message' => $ret['message'], 'data' => array()); } } else { return array('httpcode' => $info['http_code'], 'code' => self::IMAGE_NETWORK_ERROR, 'message' => 'network error', 'data' => array()); } }
/** * 上传文件流 * @param integer $userid 用户自定义分类 * @param string $file_data 文件内容 * @param string $session 上传唯一标识符 * @param string $offset 开始传输的位移 * @return [type] [description] */ public static function upload_data($userid, $file_data, $session, $offset) { $expired = time() + self::EXPIRED_SECONDS; $url = self::generateResUrl($userid); $sign = Auth::appSign($url, $expired); $data = array('FileContent' => $file_data, 'op' => 'upload_slice', 'session' => $session, 'offset' => $offset); $req = array('url' => $url, 'method' => 'post', 'timeout' => 10, 'data' => $data, 'header' => array('Authorization:' . $sign)); $rsp = Http::send($req); $info = Http::info(); $ret = json_decode($rsp, true); if ($ret) { if (0 === $ret['code']) { $ret['httpcode'] = $info['http_code']; return $ret; } else { return array('httpcode' => $info['http_code'], 'code' => $ret['code'], 'message' => $ret['message'], 'data' => array()); } } else { return array('httpcode' => $info['http_code'], 'code' => self::VIDEO_NETWORK_ERROR, 'message' => 'network error', 'data' => array()); } }
/** * return the status message */ public static function getStatusText() { $status = Http::info()['http_code']; return self::statusText($status); }