donglu2008 2016-06-04 08:38
浏览 51

xml-rpc API请求客户端

I have to get some account information from xml-rpc API at sippy softswitch. http://support.sippysoft.com/support/solutions/articles/77553-understanding-authentication, http://support.sippysoft.com/support/solutions/articles/107367-get-cdrs-of-an-account but I can't construct my code correctly. The documentation is very limited and I can't understand a lot. This is my current code:

$urlCdr = "https://portal.mcginc.com/xmlapi/xmlapi";
$post_data = array(
      'username'=> $USER,
      'password'=> $PASS,
);

$options = array(
      CURLOPT_URL            => $urlCdr,
      CURLOPT_HEADER         => true,    
      CURLOPT_VERBOSE        => true,
      CURLOPT_RETURNTRANSFER => true,
      CURLOPT_FOLLOWLOCATION => true,
      CURLOPT_SSL_VERIFYPEER => false,    // for https
      CURLOPT_USERPWD        => $USER . ":" . $PASS,
      CURLOPT_HTTPAUTH       => CURLAUTH_DIGEST,
      CURLOPT_POST           => true,
      CURLOPT_POSTFIELDS     => http_build_query($post_data) 
);

$ch = curl_init();

curl_setopt_array( $ch, $options );

try {
$raw_response  = curl_exec( $ch );

} catch(Exception $ex) {
  if ($ch != null) curl_close($ch);
  throw new Exception($ex);
}

if ($ch != null) curl_close($ch);

$cdr = "raw response: " . $raw_response;`

It returns nonce realm qop and so on. What should I do after that. Sending this info again to the server?

  • 写回答

1条回答 默认 最新

  • dony39517 2019-07-27 12:57
    关注

    Please try this:

    function Callmethod(){
        $url = "https://portal.mcginc.com/xmlapi/xmlapi";
    
        $method = "getAccountCDRs";
        $params = array('i_account'=>1);//1 is id account
    
        $post = xmlrpc_encode_request($method, $params); 
    
        $ch= curl_init();
        curl_setopt($ch,CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE);
        curl_setopt($ch, CURLOPT_USERPWD, 'user' . ':' . 'password');
        curl_setopt($ch, CURLOPT_POST, true );
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post );
        curl_setopt($ch,CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT    5.0');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
    
    
    
        $response = curl_exec($ch);
        $response_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $curl_error_no = curl_errno($ch);
        $curl_error = curl_error($ch);
        curl_close($ch);
    
        if ($curl_error_no !=0){
            die("CURL Error {$curl_error_no} - {$curl_error}n");
        }
    
        if ($response_code != 200){
    
            die("ERROR response code:{$response_code} - {$response}n");
    
        }
    
        return xmlrpc_decode($response);
    
    }
    
    评论

报告相同问题?