I'am new hand about soap
I've a client.php code witch send a xml to server.php.
How to read xml to array in my server.php?
I always get the value without the key
Do I using wsdl to parse xml?
But I'm not good at wsdl...
Can someone help me? Thx a lot.
client.php
<?php
$data = '<?xml version = "1.0" encoding = "UTF-8"?>
<inputMessage>
<ns0:BankCollStatusAdviseRq xmlns:ns0 = "http://ns.tcb.com.tw/XSD/TCB/BC/Message/BankCollStatusAdviseRq/01">
<ns0:SeqNo>00000000</ns0:SeqNo>
<ns0:TxnCode>ARROWAPAN095912 </ns0:TxnCode>
<ns0:CollInfo>
<ns0:CollId>006</ns0:CollId>
<ns0:CurAmt>
<ns0:Amt>1000</ns0:Amt>
</ns0:CurAmt>
</ns0:CollInfo>
<ns0:SettlementInfo>
<ns0:SettlementId>0063201924</ns0:SettlementId>
</ns0:SettlementInfo>
</ns0:BankCollStatusAdviseRq>
<headers>
<Header.PartyInfo>
<ns0:PartyInfo xmlns:ns0 = "http://www.tibco.com/namespaces/bc/2002/04/partyinfo.xsd">
<from>
<name>BANK006</name>
</from>
<operationID>BankColl/1.0/BankCollStatusAdvise</operationID>
</ns0:PartyInfo>
</Header.PartyInfo>
</headers>
<ns0:_configData xmlns:ns0 = "http://tibco.com/namespaces/tnt/plugins/soap">
<endpointURL>https://dev.admin.roombook.com.tw/automsgclient_tc.php?wsdl</endpointURL>
<soapAction>/BankColl</soapAction>
</ns0:_configData>
</inputMessage>';
$url = "http://localhost:8080/test/soap/demo2/server.php";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
"Content-Type: application/soap+xml",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
?>
server.php
<?php
if(strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0){
header($_SERVER["SERVER_PROTOCOL"]." 405 Method Not Allowed", true, 405);
exit;
}
$postData = trim(file_get_contents('php://input'));
echo "<pre>";print_r($postData);echo "</pre>";
libxml_use_internal_errors(true);
$xml = simplexml_load_string($postData);
if($xml === false) {
header($_SERVER["SERVER_PROTOCOL"]." 400 Bad Request", true, 400);
foreach(libxml_get_errors() as $xmlError) {
echo $xmlError->message . "\n";
}
exit;
}
?>
Related
in my code, I am making curl call and after getting response I am calling current file if proper response does not get. like this,
<?php
include 'fauxapi_client.php';
$obj = new Fauxapi_client;
$url=$obj->base_url.'/Fauxapi_client/device_version_update';
$version = trim(file_get_contents('/usr/local/www/version.txt'));
$iso_version = trim(file_get_contents('/usr/local/www/iso_version.txt'));
$temp = array('device_ip'=>$obj->current_device_ip,'version'=>$version,'iso_version'=>$iso_version);
$temp = http_build_query($temp);
$headers[] = 'Content-Type: application/x-www-form-urlencoded; charset=utf-8';
$ch = curl_init();
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,0);
curl_setopt($ch, CURLOPT_TIMEOUT, 40);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $temp);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
$output = curl_exec ($ch);
curl_close ($ch);
if ($output === false) {
echo 'Curl Call Fail';
}
else{
$response = json_decode($output,true);
if (isset($response['data']['next_version'])) {
file_put_contents('/usr/local/www/version.txt', trim($response['data']['next_version']));
if (floatval($response['data']['max_updatable_version']) > floatval($response['data']['next_version'])) {
shell_exec("/usr/local/bin/php /usr/local/www/version_update.php");
}
}
else{
echo 'next_version is not in response ';
}
}
var_dump($output);
?>
in the above code
shell_exec("/usr/local/bin/php /usr/local/www/version_update.php");
is a current file call.
when I echo something there it will echo but not calling a current file. so, how to call current file there?
Are you sure the extra space after php? bin/php /
And if /usr/local/bin/php /usr/local/www/version_update.php is current file you can use __FILE__ instead it.
And please make sure sufficient permissions.
My request functions from PUBG official API
<?php
function getProfile($profile, $div){
$pubgapikey = 'xxxxxxxxxxxxx';
$id = getID($profile);
$url = "https://api.pubg.com/shards/pc-na/players/$id/seasons/$div";
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $pubgapikey, 'Accept: application/vnd.api+json'));
curl_setopt($ch, CURLOPT_URL,$url);
$result=curl_exec($ch);
curl_close($ch);
$json = json_decode($result, true);
if($json["data"]["type"] == "playerSeason"){
return $json["data"]["attributes"];
}else {
return false;
}
}
function getID($name){
$pubgapikey = 'xxxxxxxxxxxxxxxxxxx';
$url = "https://api.pubg.com/shards/pc-na/players?filter[playerNames]=$name";
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer ' . $pubgapikey, 'Accept: application/vnd.api+json'));
curl_setopt($ch, CURLOPT_URL,$url);
$result=curl_exec($ch);
curl_close($ch);
$json = json_decode($result, true);
return $json["data"][0]["id"];
}
So That's my function for requesting the data. I'll include the ways I call this.
// My index.php file (All requests go through here)
$page = explode("/", trim($_SERVER["REQUEST_URI"], "/"));
switch($page[0]){
case "profile":
require("controllers/search_controller.php");
$data = getProfile($page[1], "division.bro.official.2018-09");
if($data != false){
include("pages/profile.php");
}else{
include("pages/home.php");
echo '<script> document.getElementById("error").innerHTML = "Cannot find user. Remember To Be Capital Sensitive!"; </script>';
}
break;
}
I know that I'm using a really dumb way to include pages and what not but I don't wanna use or build my own php framework atm and this works just fine for what I'm doing
// Here is my php for calling the function
<?php
if (isset($_POST['username'])) {
$user = $_POST['username'];
if($user != ""){
header("Location: http://www.statstreak.us/profile/$user");
die();
}
}
?>
That's pretty much it. The form is just a basic html form.
For some reason this keeps using up my 25 requests/minute that I got from PUBG which is annoying as I can't find a reason why it would use up more than 2 requests per user
I can't make it work.. :( I have this function (for create passthrough transcoder), when I run I see NULL in the web. If I test directly from the browser with the url, it does notify me that there is a problem an auth (apikey and acceskey)
function createPassthrough($name, $source_url, $recording = null)
{
$url = "https://sandbox.cloud.wowza.com/api/v1/transcoders";
$json = '{
"transcoder":{
"billing_mode":"pay_as_you_go",
"broadcast_location":"eu_belgium",
"delivery_method":"pull",
"name":"prueba",
"protocol":"rtsp",
"source_url":"url_camara",
"transcoder_Type":"passthrough",
"low_latency":true,
"buffer_size":0,
"play_maximum_connections":100,
"stream_smoother":false
}
}';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Accept:application/json; charset=utf-8',
'Content-Type: application/json; charset=utf-8',
'wsc-api-key:' . $apiKey,
'wsc-access-key:' . $accessKey,
));
$result = curl_exec($ch);
curl_close($ch);
$obj = json_decode($result);
var_dump($obj);
}
What am I doing wrong? Thanks in advance.
You should check for curl errors after $result = curl_exec($ch);.
// Check for errors and display the error message
if($errno = curl_errno($ch)) {
$error_message = curl_strerror($errno);
echo "cURL error ({$errno}):\n {$error_message}";
}
I have some problem that related to HTTP_HEADERS in curl php in opencart. The code below is caller.
$ch = curl_init();
$url = 'http://aaa.com/index.php?route=common/home/getTotalCustomer';
$url2 = 'http://bbb.com/index.php?route=common/home/getTotalCustomer';
$url3 = 'http://ccc.com/index.php?route=common/home/getTotalCustomer';
$header = array('Authorization:Basic ' . base64_encode('user:password'));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_HEADER, false);
$results = curl_exec($ch);
echo '<pre>';
print_r(json_decode($results, true));
echo '</pre>';
The receiver code like below:
public function getTotalCustomer(){
$json = array();
$this->load->model('account/customer');
if(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])){
if(($_SERVER['PHP_AUTH_PW'] == 'password') && ($_SERVER['PHP_AUTH_USER'] == 'user')){
$json['total_customer'] = $this->model_account_customer->getTotalCustomer();
}
} else{
$json['message'] = 'failed';
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
I had tried in multiple domain with different servers. Some server can return the data but some server cannot return the data. Why?
Your header that you're sending is incorrect.
You're passing
Authorization:Basic <username:password>
it should be
Authorization: Basic <username:password>
note the space.
I have built a custom api using php, its a simple api that works by posting xml data.
The code that I have working to post to the api is:
<?php
$xml_data = '<document>
<first>'.$first.'</first>
<last>'.$last.'</last>
<email>'.$email.'</email>
<phone>'.$phone.'</phone>
<body>TEST</body>
</document>';
$URL = "url";
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
$Response = curl_exec($ch);
curl_close($ch);
echo "Responce= ".$responce;
?>
On the other side, the code the above posts to:
<?php
$postdata = file_get_contents("php://input");
$xml = simplexml_load_string($postdata);
$first = $xml->first;
$last = $xml->last;
$email = $xml->email;
$phone = $xml->phone;
?>
Then I take those php variables and send to a database.. ALL THIS CODE IS WORKING!!
But my questions is: How do I send a response back to the posting side?
How do I use curl_init to send to curl_exec?
Any help would be great! Thank you
Jason
I think you want:
echo "Responce= ".$Response;
^^^
To return a response you'd do the same as you would for any other content, set a header and echo your output. For example, to return an xml response, from the script handling the post data do the following
<?php
$postdata = file_get_contents("php://input");
$xml = simplexml_load_string($postdata);
$first = $xml->first;
$last = $xml->last;
$email = $xml->email;
$phone = $xml->phone;
// do your db stuff
// format response
$response = '<response>
<success>Hello World</success>
</response>';
// set header
header('Content-type: text/xml');
// echo xml identifier and response back
echo chr(60).chr(63).'xml version="1.0" encoding="utf-8" '.chr(63).chr(62);
echo $response;
exit;
?>
You should see the response returned from curl_exec()