예제 #1
0
 /**
  * @description 签名方法实现,并构造一个参数串
  * 
  * @access private
  * @param mixed $params
  * @return void
  */
 public function signRequest($params)
 {
     if ($this->access_token) {
         $params['access_token'] = $this->access_token;
     }
     $keys = open56Client::urlencodeRfc3986(array_keys($params));
     $values = open56Client::urlencodeRfc3986(array_values($params));
     if ($keys and $values) {
         $params = array_combine($keys, $values);
     } else {
         try {
             throw new Exception("signRequest need params exits!");
         } catch (Exception $e) {
             echo $e->getMessage();
         }
     }
     /**
      * 先去除系统级参数
      */
     unset($params['appkey']);
     unset($params['ts']);
     ksort($params);
     /**
      * 第一轮md5字符串
      * */
     $req = md5(http_build_query($params));
     $ts = time();
     /**当次请求的时间戳**/
     /**第二轮md5字符串,得到最后的签名变量,注意里面的顺序不可以改变否则结果错误!**/
     $params['sign'] = md5($req . '#' . $this->appkey . '#' . $this->secret . '#' . $ts);
     $params['appkey'] = $this->appkey;
     $params['ts'] = $ts;
     return http_build_query($params);
 }
 /**
  * 56网
  * http://www.56.com/u73/v_NTkzMDcwNDY.html
  * http://player.56.com/v_NTkzMDcwNDY.swf
  */
 private static function _parse56($url)
 {
     preg_match("#https?://(?:www\\.)?56\\.com/[a-z0-9]+/(?:play_album\\-aid\\-[0-9]+_vid\\-(?<video_id1>[a-z0-9_=\\-]+)|v_(?<video_id2>[a-z0-9_=\\-]+))#i", $url, $matches);
     $cnt = count($matches);
     if ($cnt > 0) {
         $cid = $matches["video_id1"] != "" ? $matches["video_id1"] : $matches["video_id2"];
     } else {
         return false;
     }
     include "56sdk.php";
     $c = new open56Client(APPKEY, APPSECRET);
     $cexecute = $c->getVideoInfoApp($cid);
     if ($cexecute) {
         $result = json_decode($cexecute, true);
         $json = $result[0];
         $data['img'] = $json['img'];
         $data['title'] = $json['title'];
         $data['url'] = $json['vid'];
         $data['swf'] = $json['swf'];
         return $data;
     } else {
         return false;
     }
 }