I'm using a webservice in php here :
http://cdt33.tourinsoft.com/soft/RechercheDynamique/Syndication/controle/syndication2.asmx
You can test for example getListing with idModule = dafda774-317d-4b5f-bb8b-33e5977dc13c, and click on invoke
I'm trying to retrieve this result (XML) in php. But i have no idea how to do this.
If i use getListing like :
$client = new SoapClient("http://cdt33.tourinsoft.com/soft/RechercheDynamique/Syndication/controle/syndication2.asmx?wsdl");
echo "GET LISTING";
$getListing = $client->getListing(
array (
'idModule' => "dafda774-317d-4b5f-bb8b-33e5977dc13c"));
echo("<pre>");
print_r($getListing);
echo("</pre>");
Result is something like that :
stdClass Object
(
[getListingResult] => stdClass Object
(
[schema] =>
[any] =>
HOTAQU03301V3EZB2005-06-29T00:00:00.0000000+02:002012-06-28T14:43:44.0000000+02:0074HOTHôtellerie1e9eb500-e0c9-4a53-b6a5-0b36faa63ed4true 2 étoiles Français www.hotel-lenovel.com +33 5 57 52 26 47 7 oui En centre ville$ Au bord de la mer Ascenseur$ Salon 22 -1.164866 Au coeur d'Arcachon, à deux pas de la gare, du théâtre de l'Olympia et de l'Office du Tourisme, le Novel bénéficie d'une situation privilégiée. Les chambres sont chaleureuses et douillettes pour un séjour....... ETC
How can i retieve XML ?? Thanks you !
Here is sometihng to try out, run it and check the source code for the page, it should contain the xml file. SOAP is just a fancy way of doing a post.
<?php
function smartpost($type,$host,$port='80',$path='/',$data='') {
$d="";
$str="";
$_err = 'lib sockets::'.__FUNCTION__.'(): ';
switch($type) { case 'http': $type = ''; case 'ssl': continue; default: die($_err.'bad $type'); } if(!ctype_digit($port)) die($_err.'bad port');
if(!empty($data)) foreach($data AS $k => $v) $str .= urlencode($k).'='.urlencode($v).'&'; $str = substr($str,0,-1);
$fp = fsockopen($host,$port,$errno,$errstr,$timeout=30);
if(!$fp) die($_err.$errstr.$errno); else {
fputs($fp, "POST $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ".strlen($str)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $str."\r\n\r\n");
while(!feof($fp)) $d .= fgets($fp,4096);
fclose($fp);
$result = explode("\r\n\r\n", $d, 2);
$header = isset($result[0]) ? $result[0] : '';
$content = isset($result[1]) ? $result[1] : '';
} return array($header, $content);
}
list($header, $content) = smartpost('http','cdt33.tourinsoft.com','80','/soft/RechercheDynamique/Syndication/controle/syndication2.asmx/getListingByIDs',array('idModule'=>'dafda774-317d-4b5f-bb8b-33e5977dc13c','ObjetTourCode' => '','IDs' => ''));
print($content);
?>
assuming you are using standard PHP SoapClient, try using
$client->__getLastRequestHeaders()
(http://www.php.net/manual/en/soapclient.getlastresponse.php)
According to maual, you should also set trace option to true on SoapClient:
$client = new SoapClient("http://cdt33.tourinsoft.com/soft/RechercheDynamique/Syndication/controle/syndication2.asmx?wsdl", array('trace' => true));
Regards, Jakub Derda
class ABRSoapClient extends SoapClient
{
$result = "";
function __doRequest($request, $location, $action, $version)
{
$result = parent::__doRequest($request, $location, $action, $version);
return $result;
}
}
Instead of creating object of SoapClient, Create object of ABRSoapClient, Here $result is your XML string from Web-Service.
You can access that variable using $client->result;
Related
I created a wordpress plugin to retrieve the information of a token on pancakeswap. I don't understand why it doesn't show me the data. if someone can look at my code and tell me what's wrong that will be super nice. thank you in advance.
<?php
/*
Plugin name: WP PancakeSwap
Description: Ce plugin nous permet de dialoguer avec l' api PancakeSwap
Author: Jean Philippe Faucon
Version : 1.0
*/
/* Copyright 2021 Jean Philippe Faucon (email : jpfaucon81#hotmail.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// Utilisation de l'API Pancakeswap.
// https://github.com/pancakeswap/pancake-info-api/blob/develop/v2-documentation.md
// Source : https://api.pancakeswap.info/api/v2/tokens/0xdb72feadd4a0734d62fa5a078551986519dca19d
// 1 étape : récupérer les infos auprès de PancakeSwap
function _get_wp_pancakeswap_datas () {
$args = array (
'timeout' => 120,
'httpversion' => '1.1'
);
$url = "https://api.pancakeswap.info/api/v2/tokens/0xdb72feadd4a0734d62fa5a078551986519dca19d";
$call = wp_remote_get($url, $args);
$response = wp_remote_retrieve_body($call);
return $response;
}
// 2 étape : mettre en forme les données
add_shortcode('pancakeswap','output_pancakeswap');
function output_pancakeswap() {
$datas = _get_wp_pancakeswap_datas () ;
//Nom et prix du token
$output = 'Nom du token : '.$datas->name;
$output .= '<br>';
$output .= 'Valeur du token : '.$datas->price;
$output .= ' $';
$output .= '<br>';
$output .= 'Valeur du token en BNB : '.$datas->price_BNB;
return $output;
}
First of all you have to json decode the response.
If this function return the body json decoded as the name suggest wp_remote_retrieve_body($call);
try to "return $response->data" in the function _get_wp_pancakeswap_datas ()
{"updated_at":1636744974029,"data":{"name":"Alfcoin","symbol":"ALF","price":"0.1937757238779150782534763119032","price_BNB":"0.000314980409577114948657924847012"}}
If not you have to do something like this in the function _get_wp_pancakeswap_datas()
$response = json_decode(wp_remote_retrieve_body($call));
return $response->data;
This is essentially right out of the Wordpress manual.
You need to convert the json response to a php object.
You need to access the embedded object from the json response
Alternatively, you could opt for the json_decode() 2nd parameter that returns a php array instead of a php object.
function _get_wp_pancakeswap_datas () {
$args = array (
'timeout' => 120,
'httpversion' => '1.1'
);
$url = "https://api.pancakeswap.info/api/v2/tokens/0xdb72feadd4a0734d62fa5a078551986519dca19d";
$call = wp_remote_get($url, $args);
$response = json_decode(wp_remote_retrieve_body($call));
return $response;
}
add_shortcode('pancakeswap','output_pancakeswap');
function output_pancakeswap() {
$response = _get_wp_pancakeswap_datas();
//Nom et prix du token
$datas = $response->data;
$updateAt = $response->updated_at;
$output = 'Nom du token : '.$datas->name;
$output .= '<br>';
$output .= 'Valeur du token : '.$datas->price;
$output .= ' $';
$output .= '<br>';
$output .= 'Valeur du token en BNB : '.$datas->price_BNB;
return $output;
}
I create a PHP script that receive an hooks from WooCommerce, makes PDF with received data and send an e-mail, but I have a problem parsing the JSON data...
This is the JSON:
{"id":128705,"parent_id":0,"number":"128705","order_key":"wc_order_5ae3648deddcd","created_via":"checkout","version":"3.3.5","status":"on-hold","currency":"EUR","date_created":"2018-04-27T19:57:33","date_created_gmt":"2018-04-27T17:57:33","date_modified":"2018-04-27T19:57:34","date_modified_gmt":"2018-04-27T17:57:34","discount_total":"0","discount_tax":"0","shipping_total":"0","shipping_tax":"0","cart_tax":"0","total":"50","total_tax":"0","prices_include_tax":false,"customer_id":7,"customer_ip_address":"79.43.191.213","customer_user_agent":"mozilla\/5.0 (x11; linux x86_64) applewebkit\/537.36 (khtml, like gecko) chrome\/62.0.3202.89 safari\/537.36","customer_note":"","billing":{"first_name":"Nicola","last_name":"Giada","company":"","address_1":"V","address_2":"","city":"CANIC","state":"RA","postcode":"48018","country":"IT","email":"ggggggg#gmail.com","phone":"30002222"},"shipping":{"first_name":"","last_name":"","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":""},"payment_method":"bacs","payment_method_title":"Bonifico bancario","transaction_id":"","date_paid":null,"date_paid_gmt":null,"date_completed":null,"date_completed_gmt":null,"cart_hash":"dba69b53a4a39c58c83b3e557e818bb7","meta_data":[{"id":1383502,"key":"_billing_data","value":"00\/00\/1990"},{"id":1383503,"key":"_billing_codice_fiscale","value":"GDDLLLL333232"},{"id":1383504,"key":"_billing_socio","value":"Sono gi\u00e0 Socio"},{"id":1383505,"key":"_billing_dati","value":"Acconsento"},{"id":1383506,"key":"billing_data","value":"00\/00\/1990"},{"id":1383507,"key":"billing_codice_fiscale","value":"GDDLLLL333232"},{"id":1383508,"key":"billing_socio","value":"Sono gi\u00e0 Socio"},{"id":1383509,"key":"billing_dati","value":"Acconsento"}],"line_items":[{"id":94,"name":"Object buyed XXXX 2018","product_id":128683,"variation_id":128684,"quantity":1,"tax_class":"","subtotal":"40","subtotal_tax":"0","total":"40","total_tax":"0","taxes":[],"meta_data":[{"id":883,"key":"corso","value":"Object NUED"}],"sku":"","price":40},{"id":95,"name":"SECOND OBJECT","product_id":126454,"variation_id":0,"quantity":1,"tax_class":"","subtotal":"10","subtotal_tax":"0","total":"10","total_tax":"0","taxes":[],"meta_data":[],"sku":"","price":10}],"tax_lines":[],"shipping_lines":[],"fee_lines":[],"coupon_lines":[],"refunds":[]}
And this is the piece of my PHP where I retrieve information from the JSON:
/* Gestione dei dati via JSON */
$year = date('Y'); //Anno validità associativa
$secret = 'xxxxx'; //La chiave per il Webhook generata da Woocommerce
$JSON = file_get_contents('php://input');
$data = json_decode($JSON);
$sig = base64_encode(hash_hmac('sha256', $data, $secret, true));
if ($sig != $header_sig) print 'Firma invalida'; //Controllo la firma di sicurezza. Mettere die invece di print.
$nome = $data->billing->first_name;
$cognome = $data->billing->last_name;
$nato_luogo = '';
$prov = $data->billing->state;
$cap = $data->billing->postcode;
$indirizzo = $data->billing->address_1;
//$indirizzo .= $data->billing->address_2;
$tel = $data->billing->phone;
$email = $data->billing->email;
$data = date('d/m/Y'); //Data sottoscrizione scheda
$residenza = $data->billing->city;
//Valori dentro i meta_data personalizzati
foreach ($data->meta_data as $datum) {
if ($datum->key == "_billing_data") $nato_data = $datum->value;
if ($datum->key == "_billing_codice_fiscale") $CF = $datum->value;
if ($datum->key == "_billing_socio") $checksocio = $datum->value;
}
if($check_socio == 'S\u00ec') print 'Giá socio';
My problem is getting values inside "meta_data", the: foreach isn't working at all.
Thanks.
The error was in naming the variable $data ... TYPO error. Thanks.
I need to write a code that allows me to send an specific link within an array. This is a short idea of what I'm trying to do. Depending on the country code I'll send a brochure in the specific language. I also want to know if I can do it by switch...
This is the code I got so far...
<?php
$de_brochure = ('https://ruta/de-brochure.pdf');
$en_brochure = ('https://ruta/en-brochure.pdf');
$es_brochure = ('https://ruta/es-brochure.pdf');
$country_code = 'ES'; // Normally I get this code from a form.
$brochure = array ( $de_brochure, $en_brochure, $es_brochure );
$brochure_link = '';
if ( $country_code == 'ES' ) {
$to = 'info#kazzabe.com.es';
$subject = 'Ejemplo';
$txt = 'El dossier a enviar es' . $brochure_link[$brochure];
$headers = 'De: sample#sample.com' . '\r\n' .
'CC: anothersample#sample.com';
mail ($to, $subject, $txt, $headers );
} else {
echo $country_code . 'no es el código de españa';
}
When I run my code, this is the output I GET:
WARNING Illegal offset type on line number 17
NOTICE Uninitialized string offset: 1 on line number 17
You make your array and a unused "link" variable
$brochure = array ( $de_brochure, $en_brochure, $es_brochure );
$brochure_link = '';
And then access this link variable instead of the array:
$txt = 'El dossier a enviar es' . $brochure_link[$brochure];
^^^^^^^^^^^^^^^^^^^^^^^^^
This is where it fails. Using an array with named keys (a.k.a. hash) would make it easier:
$brochures = [
'DE' => 'https://ruta/de-brochure.pdf',
'EN' => 'https://ruta/en-brochure.pdf',
'ES' => 'https://ruta/es-brochure.pdf'
];
$country_code = 'ES';
# ...
$txt = 'El dossier a enviar es' . $brochures[$country_code];
do something like this
$brochure_link_arr= array(
"DE"=>'https://ruta/de-brochure.pdf',
"EN" =>'https://ruta/en-brochure.pdf',
"ES"=> 'https://ruta/es-brochure.pdf'
);
if ( $country_code == 'ES' ) {
..
$txt = 'El dossier a enviar es' . $brochure_link_arr[$country_code];
I have this method:
protected function _sendRequest($url, $method, Busca_Cxense_Data $data, $get = null) {
if (! isset ( $this->_urls [$url] )) {
throw new Busca_Cxense_Exception_Argument ( "El tipo de url enviado no es valido. (type: {$url})" );
}
$url = $this->_urls [$url] . $data->getUrlKey () . ($get ? "$get" : '');
$httpConfig = array ('http' => array ('method' => $method, 'request_fulluri' => $url, 'ignore_errors' => false ) );
if ($data->getSendJson ()) {
$json = $this->_setJson ( $data );
$header = "Content-Type: application/json\r\nContent-Length: " . strlen ( $json );
$httpConfig ['http'] ['content'] = $json;
} else {
$header = "Content-Type: text/html";
}
$httpConfig ['http'] ['header'] = $header;
$context = stream_context_create ( $httpConfig );
$stream = fopen ($url, 'r', false, $context);
$result = stream_get_contents($stream);
$headers = stream_get_meta_data($stream);
fclose($stream);
if (! $result) {
print_r ( $data );
var_dump ( $url );
print_r ( $httpConfig );
throw new Busca_Cxense_Exception_MethodCall ( "Bad call. \nString: $json\n" );
}
var_dump($result); exit;
return array ('json' => json_decode ( $result ), 'string' => $result, 'headers' => $headers );
}
As you can see, it create a context and open an stream. However, I have a error very strange. If I send this url:
http://sandbox.cxsearch.cxense.com/api/search/levelup?p_aq=query%28category^1:%22preview%20trailer%22,token-op=or%29&p_sm=idobject:desc&p_s=0&p_c=20&p_dr=title
it throws a bad request error, but if I send this other one:
http://sandbox.cxsearch.cxense.com/api/search/levelup?p_q=test&p_sm=idobject:desc&p_s=0&p_c=20&p_dr=title
it works as expected. Do I have to encode the url or something?
FIXED
I was able to figure what the problem was. I Only need to change the space for %20. And that was all...
400 response is returned by remote server, so you want to see specs/contact people on that side on how to build correct query.
The urls you provide look very different and remote system might have own validation rules on values, list of provided parameters, etc. Also it might require some specific headers and/or request body.
I was able to figure what the problem was. I Only need to change the space for %20. And that was all...
$httpsock = #socket_create_listen("9090");
if (!$httpsock) {
print "Socket creation failed!\n";
exit;
}
while (1) {
$client = socket_accept($httpsock);
$input = trim(socket_read ($client, 4096));
$input = explode(" ", $input);
$input = $input[1];
$fileinfo = pathinfo($input);
switch ($fileinfo['extension']) {
default:
$mime = "text/html";
}
if ($input == "/") {
$input = "index.html";
}
$input = ".$input";
if (file_exists($input) && is_readable($input)) {
echo "Serving $input\n";
$contents = file_get_contents($input);
$output = "HTTP/1.0 200 OK\r\nServer: APatchyServer\r\nConnection: close\r\nContent-Type: $mime\r\n\r\n$contents";
} else {
//$contents = "The file you requested doesn't exist. Sorry!";
//$output = "HTTP/1.0 404 OBJECT NOT FOUND\r\nServer: BabyHTTP\r\nConnection: close\r\nContent-Type: text/html\r\n\r\n$contents";
function openfile()
{
$filename = "a.pl";
$file = fopen($filename, 'r');
$filesize = filesize($filename);
$buffer = fread($file, $filesize);
$array = array("Output"=>$buffer,"filesize"=>$filesize,"filename"=>$filename);
return $array;
}
$send = openfile();
$file = $send['filename'];
$filesize = $send['filesize'];
$output = 'HTTP/1.0 200 OK\r\n';
$output .= "Content-type: application/octet-stream\r\n";
$output .= 'Content-Disposition: attachment; filename="'.$file.'"\r\n';
$output .= "Content-Length:$filesize\r\n";
$output .= "Accept-Ranges: bytes\r\n";
$output .= "Cache-Control: private\n\n";
$output .= $send['Output'];
$output .= "Content-Transfer-Encoding: binary";
$output .= "Connection: Keep-Alive\r\n";
}
socket_write($client, $output);
socket_close ($client);
}
socket_close ($httpsock);
Hello, I am snikolov i am creating a miniwebserver with php and i would like to know how i can send the client a file to download with his browser such as firefox or internet explore i am sending a file to the user to download via sockets, but the cleint is not getting the filename and the information to download can you please help me here,if i declare the file again i get this error in my server
Fatal error: Cannot redeclare openfile() (previously declared in C:\User
s\fsfdsf\sfdsfsdf\httpd.php:31) in C:\Users\hfghfgh\hfghg\httpd.php on li
ne 29, if its possible, i would like to know if the webserver can show much banwdidth the user request via sockets, perl has the same option as php but its more hardcore than php i dont understand much about perl, i even saw that a miniwebserver can show much the client user pulls from the server would it be possible that you can assist me with this coding, i much aprreciate it thank you guys.
You are not sending the filename to the client, so how should it know which filename to use?
There is a drawback, you can provide the desired filename in the http header, but some browsers ignore that and always suggest the filename based on the last element in URL.
For example http://localhost/download.php?help.me would result in the sugested filename help.me in the file download dialogue.
see: http://en.wikipedia.org/wiki/List_of_HTTP_headers
Everytime you run your while (1) loop you declare openfile function. You can declare function only once. Try to move openfile declaration outside loop.
$httpsock = #socket_create_listen("9090");
if (!$httpsock) {
print "Socket creation failed!\n";
exit;
}
while (1) {
$client = socket_accept($httpsock);
$input = trim(socket_read ($client, 4096));
$input = explode(" ", $input);
$input = $input[1];
$fileinfo = pathinfo($input);
switch ($fileinfo['extension']) {
default:
$mime = "text/html";
}
if ($input == "/") {
$input = "index.html";
}
$input = ".$input";
if (file_exists($input) && is_readable($input)) {
echo "Serving $input\n";
$contents = file_get_contents($input);
$output = "HTTP/1.0 200 OK\r\nServer: APatchyServer\r\nConnection: close\r\nContent-Type: $mime\r\n\r\n$contents";
} else {
//$contents = "The file you requested doesn't exist. Sorry!";
//$output = "HTTP/1.0 404 OBJECT NOT FOUND\r\nServer: BabyHTTP\r\nConnection: close\r\nContent-Type: text/html\r\n\r\n$contents";
$filename = "dada";
$file = fopen($filename, 'r');
$filesize = filesize($filename);
$buffer = fread($file, $filesize);
$send = array("Output"=>$buffer,"filesize"=>$filesize,"filename"=>$filename);
$file = $send['filename'];
$output = 'HTTP/1.0 200 OK\r\n';
$output .= "Content-type: application/octet-stream\r\n";
$output .= "Content-Length: $filesize\r\n";
$output .= 'Content-Disposition: attachment; filename="'.$file.'"\r\n';
$output .= "Accept-Ranges: bytes\r\n";
$output .= "Cache-Control: private\n\n";
$output .= $send['Output'];
$output .= "Pragma: private\n\n";
// $output .= "Content-Transfer-Encoding: binary";
//$output .= "Connection: Keep-Alive\r\n";
}
socket_write($client, $output);
socket_close ($client);
}
socket_close ($httpsock);