Ejemplo n.º 1
0
 public function testContentNegotiationOnMultipleRequests()
 {
     $client = new Net_Http_Client();
     $client->setHeader('Accept', 'application/xml');
     $client->get(self::HOST . '/basic/content');
     $this->assertEquals(200, $client->getStatus());
     $this->assertContains('<title>Hello World</title>', $client->getBody());
     $client->setHeader('Accept', 'text/javascript');
     $client->get(self::HOST . '/basic/content');
     $this->assertEquals(200, $client->getStatus());
     $this->assertContains('{message:"Hello World"}', $client->getBody());
 }
Ejemplo n.º 2
0
 /**
  * 按id获取专辑 
  * 
  * @param int $id, 专辑id 
  */
 public function album($id)
 {
     $url = $this->server . 'album/' . $id . '/?id=' . $id . '&csrf_token=';
     $http = new \Net_Http_Client();
     // Set referer header
     $http->setHeader('Referer', 'http://music.163.com');
     $body = $http->get($url)->getBody();
     $res = json_decode($body, true);
     if (!isset($res['code']) || $res['code'] != 200) {
         $msg = isset($res['message']) ? $res['message'] : 'Failed to connect the api server.';
         $res['status'] = 0;
         $res['message'] = $msg;
         //throw new \UnexpectedValueException($msg);
     }
     $artist = array();
     foreach ($res['album']['artists'] as $v) {
         $artist[] = array('id' => $v['id'], 'name' => $v['name'], 'pic' => $v['picUrl']);
     }
     $songs = array();
     foreach ($res['album']['songs'] as $v) {
         $songs[] = array('id' => $v['id'], 'name' => $v['name'], 'duration' => $v['duration'], 'mp3' => $v['mp3Url']);
     }
     // return data
     $return = array('id' => $res['album']['id'], 'name' => $res['album']['name'], 'cover' => $res['album']['picUrl'], 'releaseTime' => $res['album']['publishTime']);
     $return['artist'] = $artist;
     $return['songs'] = $songs;
     return $return;
 }