Php保利威点播示例 发表于 2021-12-30 | 更新于: 2022-05-13 | 分类于 学习 字数统计: 533 | 阅读时长 ≈ 2 前言: 参考地址 代码:123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119/** * User: 謝雲虎 * DateTime: 2021/12/13 14:35 * Desc:post请求curl * @param string $url * @param array $post_data */ public function post_curl($url = '',$post_data = array()){ $ch = curl_init(); $timeout = 360; curl_setopt( $ch, CURLOPT_URL, $url); curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt( $ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); $output = curl_exec( $ch ); curl_close( $ch ); print_r($output); } /** * User: 謝雲虎 * DateTime: 2021/12/13 14:36 * Desc:get请求curl * @param string $url */ public function get_curl($url = ''){ $ch = curl_init();//初始化cURL curl_setopt($ch,CURLOPT_URL,$url);//抓取指定网页 curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);//要求结果为字符串并输出到屏幕上 curl_setopt($ch, CURLOPT_HEADER, 0);//设置header $output = curl_exec($ch);//执行并获得HTML内容 curl_close($ch);//释放cURL句柄 print_r($output); } /** * User: 謝雲虎 * DateTime: 2021/12/13 12:50 * Desc:返回当前的毫秒时间戳 * @return float */ public function msectime() { list($msec, $sec) = explode(' ', microtime()); $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000); return $msectime; } /** * User: 謝雲虎 * DateTime: 2021/12/13 19:11 * Desc:生成SHA1签名,保利威获取加密等信息 * @param array $params * @return string */ public function get_sign_str($params = array()){ if(request()->isPost()) { //按照参数名字典顺序排列,采用HTTP GET请求参数连接方式(key=value&key=value&key=value)拼接参数名与参数值 $str = $this->get_url_str($params); //在字符串尾部加上secretkey $config = config('common.polyv'); $str .= $config['secretkey']; //然后计算SHA1,将SHA1结果转为大写字母,作为sign; return strtoupper(sha1($str)); } } /** * User: 謝雲虎 * DateTime: 2021/12/13 16:21 * Desc:处理url参数 * @param $params * @return bool|string */ public function get_url_str($params){ ksort($params); $str = ''; foreach ($params as $k => $val) { $str .= "{$k}={$val}&"; } $str = substr($str,0,strlen($str)-1); return $str; } /** * User: 謝雲虎 * DateTime: 2021/12/13 19:36 * Desc:查询视频信息 * @param $param */ public function get_video_time($param){ $config = config('common.polyv'); $params['vid'] = $param; $params['ptime'] = $this->msectime(); $params['userId'] = $config['userid']; $params['sign'] = $this->get_sign_str($params); $url = 'http://api.polyv.net/v2/video/'.$config['userid'].'/get-video-info'; return $this->post_curl($url,$params); } /** * User: 謝雲虎 * DateTime: 2021/12/13 19:36 * Desc:批量查询视频时长和大小 */ public function get_video_info(){ if(request()->isPost()) { $config = config('common.polyv'); $params['vids'] = '保利威存储中的vids'; $params['ptime'] = $this->msectime(); $params['userid'] = $config['userid']; $params['sign'] = $this->get_sign_str($params); $url = 'http://api.polyv.net/v2/video/'.$config['userid'].'/getSizeByCata?'; $url .= $this->get_url_str($params); $this->get_curl($url); } } Share