Пример #1
0
if (empty($_GET['fid']) || empty($_GET['ppfeature']) || !isset($_GET['start']) || empty($_GET['end'])) {
    die(json_encode(array('err' => '403', 'msg' => 'fid or ppfeature or start or end empty', 'data' => array())));
}
//得到ppfeature、start,end对应的upload_url
$key = "{$_GET['start']}_{$_GET['end']}";
$ranges = api_cache($_GET['ppfeature'], $key);
if (empty($ranges)) {
    die(json_encode(array('err' => 502, 'msg' => '传参start、end不对', 'data' => [$_GET, $_SERVER['REQUEST_URI'], $_SERVER['argv'], $_SERVER['SERVER_ADDR'], php_uname()])));
}
//处理nginx接收到的文件
$target = UPLOAD_DIR . "/{$_GET['ppfeature']}";
@mkdir($target);
$target .= "/{$key}";
rename($_GET['upload_tmp_path'], $target);
//文件大小校验
if ($_GET['end'] - $_GET['start'] != filesize($target)) {
    die(json_encode(array('err' => 502, 'msg' => '文件不完整', 'data' => [$_GET, $_SERVER['REQUEST_URI'], $_SERVER['argv'], $_SERVER['SERVER_ADDR'], php_uname()])));
}
//传swift
$uploadId = send_put_file($ranges['upload_url'], $target);
if (!$uploadId) {
    die(json_encode(array('err' => 500, 'msg' => '传文件至公有云出错', 'data' => array())));
}
//通知已完成
$md5 = strtoupper($uploadId);
$url = API_CLOUDPLAY . "/2/file/{$_GET['fid']}/action/uploaded?fromcp=private_cloud&range_md5={$md5}&bid={$ranges['bid']}&uploadid={$uploadId}";
$json = send_json_post($url, '');
$arr = json_decode($json, 1);
$arr['msg'] = 'success';
$arr['data'] = [$_GET, $_SERVER['REQUEST_URI'], $_SERVER['argv'], $_SERVER['SERVER_ADDR'], php_uname(), $md5];
die(json_encode($arr));
Пример #2
0
include 'api_common.inc.php';
if (empty($_SERVER['argv'])) {
    exit;
}
$fid = $_SERVER['argv'][1];
$ppFeature = $_SERVER['argv'][2];
$file_size_arr = explode('_', $ppFeature);
$file_size = $file_size_arr[0];
$fileArray = big_file_array($ppFeature);
$md5 = strtoupper(big_file_md5($fileArray));
$url = API_CLOUDPLAY . "/1/file/{$fid}/md5?fromcp=private_cloud&feature_pplive={$ppFeature}&md5={$md5}";
$json1 = send_post($url);
$xunlei_cid = big_file_cid($fileArray, $file_size);
$xunlei_gcid = big_file_gcid($fileArray, $file_size);
$url = API_CLOUDPLAY . "/1/file/{$fid}/features?fromcp=private_cloud&feature_pplive={$ppFeature}";
$json2 = send_json_post($url, '{"feature_xunlei_cid":"' . $xunlei_cid . '","feature_xunlei_gcid":"' . $xunlei_gcid . '"}');
//删除临时文件
$target = UPLOAD_DIR . "/{$ppFeature}";
delDirAndFile($target);
//必须,否则文件无法进入转码队列
$url = API_CLOUDPLAY . "/2/file/{$fid}/action/uploadrange?feature_pplive={$ppFeature}&segs=1";
sleep(30);
$json3 = send_get($url);
$arr3 = json_decode(send_get($url), 1);
if (empty($arr3['data']) || $arr3['data']['status'] == 50) {
    sleep(30);
    $json3 = send_get($url);
    $json3 = 'retry';
}
$phpPath = __DIR__ . '/0x0000.log';
file_put_contents($phpPath, " {$md5} \n {$xunlei_cid} \n {$xunlei_gcid} \n {$json1} \n {$json2} \n {$json3} \n ");
Пример #3
0
parse_str(des_decrypt(base64_decode($_GET['token']), $TRIPLEDES_KEY, $TRIPLEDES_IV), $session);
if (empty($session)) {
    ajaxReturn('', 'token error', 403);
}
//得到ppfeature、start,end对应的upload_url
$key = "{$_GET['start']}_{$_GET['end']}";
$ranges = api_cache($_GET['ppfeature'], $key);
if (empty($ranges)) {
    ajaxReturn('', '传参start、end不对', 502);
}
//先存本地
$target = UPLOAD_DIR . "/{$_GET['ppfeature']}";
@mkdir($target);
$target .= "/{$key}";
$input = fopen("php://input", "r");
@file_put_contents($target, $input);
//文件大小校验
if ($_GET['end'] - $_GET['start'] != filesize($target)) {
    ajaxReturn('', '文件不完整', 502);
}
//传swift
$uploadId = send_put_file($ranges['upload_url'], $target);
if (!$uploadId) {
    ajaxReturn('', '传文件至公有云出错', 500);
}
//通知已完成
$md5 = strtoupper($uploadId);
$url = API_CLOUDPLAY . "/2/file/{$_GET['fid']}/action/uploaded?fromcp=private_cloud&range_md5={$md5}&bid={$ranges['bid']}&uploadid={$uploadId}";
$arr = json_decode(send_json_post($url, ''), 1);
$arr['data'] = array('nextUrl' => "{$URL_PREFIX}/getRange.php");
ajaxReturn($arr['data'], 'success', 0);
Пример #4
0
parse_str(des_decrypt(base64_decode(urldecode($_POST['token'])), $TRIPLEDES_KEY, $TRIPLEDES_IV), $session);
if (empty($session)) {
    ajaxReturn('', 'token error', 403);
}
//获取ppFeature
$tmpArr = $_FILES['files']['tmp_name'];
$ppFeature = '';
foreach ($tmpArr as $tmp) {
    $ppFeature .= file_get_contents($tmp);
}
$ppFeature = "{$_POST['size']}_" . sha1($ppFeature);
//获取视频列表
$url = SVC_PPTVYUN . '/api/channelcategory/categorylist';
$params = array('username' => $session['username'], 'apitk' => md5($session['apikey'] . $url));
$arr = json_decode(send_get($url . '?' . http_build_query($params)), 1);
if (empty($arr['data'])) {
    ajaxReturn('', 'apikey认证失败', 403);
}
$categoryId = $arr['data'][0]['id'];
if (!empty($_POST['categoryid'])) {
    $categoryId = intval($_POST['categoryid']);
}
//创建视频
$url = SVC_PPTVYUN . '/api/channel/upload';
$postData = array('username' => $session['username'], 'apitk' => md5($session['apikey'] . $url), 'categoryid' => $categoryId, 'name' => isset($_POST['channelname']) ? trim($_POST['channelname']) : '', 'summary' => isset($_POST['summary']) ? trim($_POST['summary']) : '', 'coverimg' => isset($_POST['coverimg']) ? trim($_POST['coverimg']) : '', 'length' => isset($_POST['size']) ? intval($_POST['size']) : 0, 'ppfeature' => $ppFeature);
$arr = json_decode(send_json_post($url, json_encode($postData)), 1);
if (!empty($arr['data'])) {
    $fid = base64_encode(des_encrypt($arr['data']['fId'], $TRIPLEDES_KEY, $TRIPLEDES_IV));
    $arr['data'] = array('nextUrl' => "{$URL_PREFIX}/getRange.php", 'channelWebId' => $arr['data']['channelWebId'], "coverImage" => "http://grocery.pptv.com/lpic/ea7/a31/013/de8660322896b27530d31d82a0aa7bd0.jpg", 'ppfeature' => $ppFeature, 'fid' => urlencode($fid));
}
ajaxReturn($arr['data'], $arr['msg'], 0);