|
@@ -14,7 +14,7 @@ use Mts\Request\V20140618 as Mts;
|
|
|
*/
|
|
|
class Eyemargin extends Common
|
|
|
{
|
|
|
- protected $noNeedLogin = ['mpsvideo'];
|
|
|
+ protected $noNeedLogin = ['mpsvideo', 'getencoderesult'];
|
|
|
protected $noNeedRight = '*';
|
|
|
|
|
|
public function _initialize()
|
|
@@ -383,4 +383,92 @@ class Eyemargin extends Common
|
|
|
// print 'Error: ' . $e->getErrorCode() . ' Message: ' . $e->getMessage() . "\n";
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ //阿里云查询视频转码结果
|
|
|
+ public function getencoderesult()
|
|
|
+ {
|
|
|
+ set_time_limit(0);
|
|
|
+
|
|
|
+ $where = array(
|
|
|
+ 'eye_type' => 1,
|
|
|
+ 'jobid' => ['neq', ''],
|
|
|
+ 'encode_status' => 0,
|
|
|
+ );
|
|
|
+ $eyemargin = Db::name('eyemargin');
|
|
|
+ $list = $eyemargin->where($where)->limit(100)->select();
|
|
|
+
|
|
|
+ if (!$list) {
|
|
|
+ echo 'mei shu ju';
|
|
|
+ die;
|
|
|
+ }
|
|
|
+
|
|
|
+ //构建转码查询数据
|
|
|
+ $data['Format'] = 'JSON';
|
|
|
+ $data['Version'] = '2014-06-18';
|
|
|
+ $data['AccessKeyId'] = config('oss.secretId');
|
|
|
+ $data['SignatureMethod'] = 'HMAC-SHA1';
|
|
|
+ $data['SignatureVersion'] = '1.0';
|
|
|
+ $data['Action'] = 'QueryJobList';
|
|
|
+
|
|
|
+ foreach ($list as &$v) {
|
|
|
+ $data['Timestamp'] = str_replace('+00:00', 'Z', gmdate('c', time()));
|
|
|
+ $data['SignatureNonce'] = md5(uniqid(mt_rand(), true));
|
|
|
+ $data['JobIds'] = $v['jobid'];
|
|
|
+ $data['Signature'] = $this->computeSignature($data, config('oss.secretKey'));
|
|
|
+
|
|
|
+ $url = 'http://mts.cn-hangzhou.aliyuncs.com/?';
|
|
|
+ foreach ($data as $apiParamKey => $apiParamValue) {
|
|
|
+ $url .= "$apiParamKey=" . urlencode($apiParamValue) . '&';
|
|
|
+ }
|
|
|
+ $url = substr($url, 0, -1);
|
|
|
+
|
|
|
+ $result = file_get_contents($url);
|
|
|
+ $result = json_decode($result, true);
|
|
|
+ $_data = [];
|
|
|
+ if ($result['JobList']['Job'][0]['Percent'] == 100 && $result['JobList']['Job'][0]['State'] == 'TranscodeSuccess') {
|
|
|
+ $_data['video'] = str_replace('uploads', 'output', $v['video']);
|
|
|
+ $_data['encode_status'] = 1;
|
|
|
+ $eyemargin->where(['id' => $v['id'], 'encode_status' => 0])->setField($_data);
|
|
|
+ } elseif ($result['JobList']['Job'][0]['State'] == 'TranscodeFail') {
|
|
|
+ $_data['encode_status'] = 2;
|
|
|
+ $eyemargin->where(['id' => $v['id'], 'encode_status' => 0])->setField($_data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param $parameters
|
|
|
+ * @param $accessKeySecret
|
|
|
+ * @param $iSigner
|
|
|
+ *
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ protected function computeSignature($parameters, $accessKeySecret)
|
|
|
+ {
|
|
|
+ ksort($parameters);
|
|
|
+ $canonicalizedQueryString = '';
|
|
|
+ foreach ($parameters as $key => $value) {
|
|
|
+ $canonicalizedQueryString .= '&' . $this->percentEncode($key) . '=' . $this->percentEncode($value);
|
|
|
+ }
|
|
|
+ $stringToBeSigned = 'GET&%2F&' . $this->percentEncode(substr($canonicalizedQueryString, 1));
|
|
|
+ return $this->signString($stringToBeSigned, $accessKeySecret . '&');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param $str
|
|
|
+ *
|
|
|
+ * @return string|string[]|null
|
|
|
+ */
|
|
|
+ protected function percentEncode($str)
|
|
|
+ {
|
|
|
+ $res = urlencode($str);
|
|
|
+ $res = str_replace(array('+', '*'), array('%20', '%2A'), $res);
|
|
|
+ $res = preg_replace('/%7E/', '~', $res);
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function signString($source, $accessSecret)
|
|
|
+ {
|
|
|
+ return base64_encode(hash_hmac('sha1', $source, $accessSecret, true));
|
|
|
+ }
|
|
|
}
|