我必须从sippy softswitch的xml-rpc API获取一些帐户信息。 http://support.sippysoft.com/support/solutions/articles/77553-understanding-authentication, http://support.sippysoft.com/support/solutions/articles/107367-get-cdrs-of-an-account但我无法正确构建代码。 文档非常有限,我无法理解。 这是我目前的代码:
$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;`
返回nonce领域qop等。之后我该怎么办再次将此信息发送到服务器?
答案 0 :(得分:0)
请尝试以下操作:
function Callmethod(){
$url = "https://portal.mcginc.com/xmlapi/xmlapi";
$params = "<?xml version="1.0"?> <methodCall><methodName>getAccountCDRs</methodName> <params> <param> <value><struct> <member><name>i_account</name> <value><int>1</int></value> </member> </struct></value> </param> </params> </methodCall>"
$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, $params );
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);
}