API Documentation RunningExamples server.order server PHP
Aus EUserv Wiki
(Unterschied zwischen Versionen)
Root (Diskussion | Beiträge) |
Root (Diskussion | Beiträge) |
||
Zeile 3: | Zeile 3: | ||
<nowiki> | <nowiki> | ||
<?php | <?php | ||
+ | |||
//includes the class library | //includes the class library | ||
include_once("lib/xmlrpc.inc"); | include_once("lib/xmlrpc.inc"); | ||
$xmlrpc_internalencoding = 'UTF-8'; | $xmlrpc_internalencoding = 'UTF-8'; | ||
+ | |||
$host="api.test.euserv.net"; | $host="api.test.euserv.net"; | ||
$port=443; | $port=443; | ||
Zeile 14: | Zeile 16: | ||
$accept_terms_and_conditions=1; | $accept_terms_and_conditions=1; | ||
$accept_special_terms_and_conditions_rootserver=1; | $accept_special_terms_and_conditions_rootserver=1; | ||
+ | |||
//defines the function | //defines the function | ||
- | function server_order_server($host,$port,$username,$password,$api_path,$item_id,$accept_terms_and_conditions, | + | function server_order_server($host,$port,$username,$password,$api_path,$item_id,$accept_terms_and_conditions,$accept_special_terms_and_conditions_rootserver) |
- | $accept_special_terms_and_conditions_rootserver) | + | |
{ | { | ||
- | //creates the serverurl | + | |
- | $serverurl = 'https://'.$host.':'.$port.'/'.$api_path; | + | //creates the serverurl |
- | //----------creates the message which will be send to the server---------- | + | $serverurl = 'https://'.$host.':'.$port.'/'.$api_path; |
- | //creates the request for the XML-RPC Server | + | |
- | $request = new xmlrpcmsg('server.order_server'); | + | //----------creates the message which will be send to the server---------- |
- | $keys = array_keys($item_id); | + | |
- | //adds parameters to the request | + | //creates the request for the XML-RPC Server |
- | $request->addParam | + | $request = new xmlrpcmsg('server.order_server'); |
- | ( | + | $keys = array_keys($item_id); |
- | //creates a value of type struct which contains an array with the username and password | + | //adds parameters to the request |
- | new xmlrpcval | + | $request->addParam |
- | ( | + | ( |
- | array | + | |
- | ( | + | //creates a value of type struct which contains an array with the username and password |
- | //creates a value of type string which contains the "$username" | + | new xmlrpcval |
- | 'login' => new xmlrpcval($username, 'string'), | + | ( |
- | //creates a value of type string which contains the "$password" | + | array |
- | 'password' => new xmlrpcval($password, 'string'), | + | |
- | //creates a value of type string which contains the "$srv_id" | + | ( |
- | $keys[0] => new xmlrpcval($item_id[$keys[0]]), | + | //creates a value of type string which contains the "$username" |
- | //creates a value of type string which contains the "$srv_id" | + | 'login' => new xmlrpcval($username, 'string'), |
- | $keys[1] => new xmlrpcval($item_id[$keys[1]]), | + | |
- | //creates a value of type string which contains the "$srv_id" | + | //creates a value of type string which contains the "$password" |
- | 'accept_terms_and_conditions' => new xmlrpcval($accept_terms_and_conditions), | + | 'password' => new xmlrpcval($password, 'string'), |
- | //creates a value of type string which contains the "$srv_id" | + | |
- | 'accept_special_terms_and_conditions_rootserver' => new xmlrpcval($accept_special_terms_and_conditions_rootserver), | + | //creates a value of type string which contains the "$srv_id" |
- | ) | + | $keys[0] => new xmlrpcval($item_id[$keys[0]]), |
- | ,'struct' | + | |
- | ) | + | //creates a value of type string which contains the "$srv_id" |
- | ); | + | $keys[1] => new xmlrpcval($item_id[$keys[1]]), |
- | //----------creates the XML-RPC client which represent a client of an XML-RPC server---------- | + | |
- | //creates the client | + | //creates a value of type string which contains the "$srv_id" |
- | $client = new xmlrpc_client($serverurl); | + | 'accept_terms_and_conditions' => new xmlrpcval($accept_terms_and_conditions), |
- | //disable SSL Keycheck | + | |
- | $client->setSSLVerifyPeer(0); | + | //creates a value of type string which contains the "$srv_id" |
- | //----------sends the request to the server and gets the response---------- | + | 'accept_special_terms_and_conditions_rootserver' => new xmlrpcval($accept_special_terms_and_conditions_rootserver), |
- | //sends the request via https and writes it into $response. timeout is set to 0 | + | |
- | $response = $client->send($request,0,'https'); | + | ) |
- | //generates a storable representation of $response and writes it into $result_xml | + | ,'struct' |
- | //echo $response->serialize(); | + | ) |
- | //checks the response. if the method "faultCode" returns zero, the response was succesfull | + | ); |
- | if (0==$response->faultCode()) | + | |
- | { | + | //----------creates the XML-RPC client which represent a client of an XML-RPC server---------- |
- | //returns the value sent by the server | + | |
- | $value = $response->value(); | + | //creates the client |
- | //returns the actual PHP-language value of "value" | + | $client = new xmlrpc_client($serverurl); |
- | $result_obj = $value->scalarval(); | + | |
- | //destroys "value" | + | //disable SSL Keycheck |
- | unset($value); | + | $client->setSSLVerifyPeer(0); |
- | } | + | |
- | else | + | //----------sends the request to the server and gets the response---------- |
- | { | + | |
- | //returns the faultCode and the faultString | + | //sends the request via https and writes it into $response. timeout is set to 0 |
- | return $error = array ( 'faultCode' => $response->faultCode(), 'faultString' => $response->faultString()); | + | $response = $client->send($request,0,'https'); |
- | } | + | |
- | //destroys "client" | + | //generates a storable representation of $response and writes it into $result_xml |
- | unset($client); | + | //echo $response->serialize(); |
- | //destroys "response" | + | |
- | unset($response); | + | //checks the response. if the method "faultCode" returns zero, the response was succesfull |
- | //----------reads the result_obj---------- | + | if (0==$response->faultCode()) |
- | //if result_obj is set then it returns the actual PHP-language value of "result_obj" | + | { |
- | if (isset($result_obj['status'])) | + | //returns the value sent by the server |
- | { | + | $value = $response->value(); |
- | $value['status'] = $result_obj['status']->scalarval(); | + | |
- | } | + | //returns the actual PHP-language value of "value" |
- | if (isset($result_obj['total_amount'])) | + | $result_obj = $value->scalarval(); |
- | { | + | |
- | $value['total_amount'] = $result_obj['total_amount']->scalarval(); | + | //destroys "value" |
- | } | + | unset($value); |
- | return $value; | + | } |
+ | else | ||
+ | { | ||
+ | //returns the faultCode and the faultString | ||
+ | return $error = array ( 'faultCode' => $response->faultCode(), 'faultString' => $response->faultString()); | ||
+ | } | ||
+ | |||
+ | //destroys "client" | ||
+ | unset($client); | ||
+ | |||
+ | //destroys "response" | ||
+ | unset($response); | ||
+ | |||
+ | |||
+ | //----------reads the result_obj---------- | ||
+ | |||
+ | //if result_obj is set then it returns the actual PHP-language value of "result_obj" | ||
+ | |||
+ | if (isset($result_obj['status'])) | ||
+ | { | ||
+ | $value['status'] = $result_obj['status']->scalarval(); | ||
+ | } | ||
+ | |||
+ | if (isset($result_obj['total_amount'])) | ||
+ | { | ||
+ | $value['total_amount'] = $result_obj['total_amount']->scalarval(); | ||
+ | } | ||
+ | |||
+ | return $value; | ||
} | } | ||
+ | |||
//calls the function | //calls the function | ||
- | $result = server_order_server($host,$port,$username,$password,$api_path,$item_id,$accept_terms_and_conditions, | + | $result = server_order_server($host,$port,$username,$password,$api_path,$item_id,$accept_terms_and_conditions,$accept_special_terms_and_conditions_rootserver); |
- | $accept_special_terms_and_conditions_rootserver); | + | |
if(0==$result['faultCode']) | if(0==$result['faultCode']) | ||
{ | { | ||
- | echo "Status: ".$result['status']."<br><br>".$result['total_amount']; | + | echo "Status: ".$result['status']."<br><br>".$result['total_amount']; |
} | } | ||
else | else | ||
{ | { | ||
- | echo "faultCode: ".$result['faultCode']." faultString: ".$result['faultString']; | + | echo "faultCode: ".$result['faultCode']." faultString: ".$result['faultString']; |
} | } | ||
?> | ?> | ||
</nowiki> | </nowiki> |
Aktuelle Version vom 07:47, 6. Sep. 2012
back to API Documentation
server.order_server
<?php //includes the class library include_once("lib/xmlrpc.inc"); $xmlrpc_internalencoding = 'UTF-8'; $host="api.test.euserv.net"; $port=443; $username="<API_USER>"; $password="<API_USER_PASSWORD>"; $api_path="/"; $item_id=array('1337' => '1' , '1338' => '2'); $accept_terms_and_conditions=1; $accept_special_terms_and_conditions_rootserver=1; //defines the function function server_order_server($host,$port,$username,$password,$api_path,$item_id,$accept_terms_and_conditions,$accept_special_terms_and_conditions_rootserver) { //creates the serverurl $serverurl = 'https://'.$host.':'.$port.'/'.$api_path; //----------creates the message which will be send to the server---------- //creates the request for the XML-RPC Server $request = new xmlrpcmsg('server.order_server'); $keys = array_keys($item_id); //adds parameters to the request $request->addParam ( //creates a value of type struct which contains an array with the username and password new xmlrpcval ( array ( //creates a value of type string which contains the "$username" 'login' => new xmlrpcval($username, 'string'), //creates a value of type string which contains the "$password" 'password' => new xmlrpcval($password, 'string'), //creates a value of type string which contains the "$srv_id" $keys[0] => new xmlrpcval($item_id[$keys[0]]), //creates a value of type string which contains the "$srv_id" $keys[1] => new xmlrpcval($item_id[$keys[1]]), //creates a value of type string which contains the "$srv_id" 'accept_terms_and_conditions' => new xmlrpcval($accept_terms_and_conditions), //creates a value of type string which contains the "$srv_id" 'accept_special_terms_and_conditions_rootserver' => new xmlrpcval($accept_special_terms_and_conditions_rootserver), ) ,'struct' ) ); //----------creates the XML-RPC client which represent a client of an XML-RPC server---------- //creates the client $client = new xmlrpc_client($serverurl); //disable SSL Keycheck $client->setSSLVerifyPeer(0); //----------sends the request to the server and gets the response---------- //sends the request via https and writes it into $response. timeout is set to 0 $response = $client->send($request,0,'https'); //generates a storable representation of $response and writes it into $result_xml //echo $response->serialize(); //checks the response. if the method "faultCode" returns zero, the response was succesfull if (0==$response->faultCode()) { //returns the value sent by the server $value = $response->value(); //returns the actual PHP-language value of "value" $result_obj = $value->scalarval(); //destroys "value" unset($value); } else { //returns the faultCode and the faultString return $error = array ( 'faultCode' => $response->faultCode(), 'faultString' => $response->faultString()); } //destroys "client" unset($client); //destroys "response" unset($response); //----------reads the result_obj---------- //if result_obj is set then it returns the actual PHP-language value of "result_obj" if (isset($result_obj['status'])) { $value['status'] = $result_obj['status']->scalarval(); } if (isset($result_obj['total_amount'])) { $value['total_amount'] = $result_obj['total_amount']->scalarval(); } return $value; } //calls the function $result = server_order_server($host,$port,$username,$password,$api_path,$item_id,$accept_terms_and_conditions,$accept_special_terms_and_conditions_rootserver); if(0==$result['faultCode']) { echo "Status: ".$result['status']."<br><br>".$result['total_amount']; } else { echo "faultCode: ".$result['faultCode']." faultString: ".$result['faultString']; } ?>