I have to make a SOAP-Request with PHP to the DHL Carrier Service to generate batch labels. Somehow, I can't understand how it works. I wrote this code:
<?php
require_once('lib/Zend/Soap/Client.php');
require_once('lib/Zend/Soap/Client/Common.php');
$client = new Zend_Soap_Client('http://test-intraship.dhl.com/ws/1_0/ISService/DE.wsdl',
array(
'soap_version'=>SOAP_1_1
,'encoding' => 'UTF-8'
,'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_DEFLATE
,'location'=>'https://test-intraship.dhl.com/intraship.57/jsp/Login_WS.jsp'
)
);
$location = 'https://test-intraship.dhl.com/intraship.57/jsp/Login_WS.jsp';
$request = '
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:cis="http://dhl.de/webservice/cisbase" xmlns:de="http://de.ws.intraship">
<soap:Header><cis:Authentification><cis:user>magento</cis:user><cis:signature>m1a2$!</cis:signature><cis:accountNumber>5000000000</cis:accountNumber><cis:type>0</cis:type></cis:Authentification>
</soap:Header>
<soap:Body><de:CreateShipmentDDRequest>
<cis:Version>
<cis:majorRelease>1</cis:majorRelease>
<cis:minorRelease>0</cis:minorRelease></cis:Version><ShipmentOrder><SequenceNumber>1</SequenceNumber><Shipment><ShipmentDetails><ProductCode>EPN</ProductCode><ShipmentDate>2012-10-03</ShipmentDate><DeclaredValueOfGoods>10.2</DeclaredValueOfGoods><DeclaredValueOfGoodsCurrency>EUR</DeclaredValueOfGoodsCurrency><cis:EKP>5000000000</cis:EKP><Attendance><cis:partnerID>01</cis:partnerID></Attendance><CustomerReference>Auftrag 12883884</CustomerReference><ShipmentItem><WeightInKG>12</WeightInKG><LengthInCM>1</LengthInCM><WidthInCM>1</WidthInCM><HeightInCM>10</HeightInCM><PackageType>PK</PackageType></ShipmentItem><Service><ShipmentServiceGroupIdent><ReturnReceipt>false</ReturnReceipt></ShipmentServiceGroupIdent></Service><Service><ShipmentServiceGroupIdent><Personally>false</Personally></ShipmentServiceGroupIdent></Service><Service><ServiceGroupDHLPaket><Multipack>False</Multipack></ServiceGroupDHLPaket></Service><BankData><cis:accountOwner>DHL.de</cis:accountOwner><cis:accountNumber>1234567891</cis:accountNumber><cis:bankCode>87050000</cis:bankCode><cis:bankName>Sparkasse Chemnitz</cis:bankName><cis:iban>DE34870500001234567891</cis:iban><cis:note>Notiz Bank</cis:note><cis:bic>CHEKDE81XXX</cis:bic></BankData></ShipmentDetails><Shipper><Company><cis:Person><cis:firstname></cis:firstname><cis:lastname>Deutsche Post IT BRIEF GmbH</cis:lastname></cis:Person></Company><Address><cis:streetName>Heinrich-Brüning-Str.</cis:streetName><cis:streetNumber>7</cis:streetNumber><cis:Zip><cis:germany>53113</cis:germany></cis:Zip><cis:city>Bonn</cis:city><cis:Origin><cis:countryISOCode>DE</cis:countryISOCode></cis:Origin></Address><Communication><cis:phone>3935644</cis:phone><cis:email>dhl#dhl.com</cis:email><cis:contactPerson>IT Systeme Marketing Vertrieb</cis:contactPerson></Communication></Shipper><Receiver><Company><cis:Company><cis:name1>DHL Vertriebs GmbH Co. OHG</cis:name1></cis:Company></Company><Address><cis:streetName>Neue Poststr.</cis:streetName><cis:streetNumber>1</cis:streetNumber><cis:Zip><cis:other>08496</cis:other></cis:Zip><cis:city>Neumark</cis:city><cis:Origin><cis:countryISOCode>DE</cis:countryISOCode></cis:Origin></Address><Communication><cis:phone>3935655</cis:phone><cis:email>dhl#dhl.com</cis:email><cis:contactPerson>CIS 1J4</cis:contactPerson></Communication></Receiver><ExportDocument><InvoiceType>proforma</InvoiceType><InvoiceDate>2012-10-03</InvoiceDate><InvoiceNumber>444444</InvoiceNumber><ExportType>1</ExportType><ExportTypeDescription>für Sonstiges</ExportTypeDescription><CommodityCode>8888888</CommodityCode><TermsOfTrade>CIP</TermsOfTrade><Amount>2000</Amount><Description>777777</Description><CountryCodeOrigin>DE</CountryCodeOrigin><AdditionalFee>3.12</AdditionalFee><CustomsValue>2.23</CustomsValue><CustomsCurrency>EUR</CustomsCurrency><PermitNumber>666666</PermitNumber><AttestationNumber>?</AttestationNumber><ExportDocPosition><Description>Harddisk</Description><CountryCodeOrigin>DE</CountryCodeOrigin><CommodityCode>123456</CommodityCode><Amount>200</Amount><NetWeightInKG>1</NetWeightInKG><GrossWeightInKG>1.2</GrossWeightInKG><CustomsValue>200</CustomsValue><CustomsCurrency>EUR</CustomsCurrency></ExportDocPosition></ExportDocument></Shipment><LabelResponseType>URL</LabelResponseType></ShipmentOrder></de:CreateShipmentDDRequest></soap:Body></soap:Envelope>
';
$clientCommon = new Zend_Soap_Client_Common($client, 'http://test-intraship.dhl.com/ws/1_0/ISService/DE.wsdl',
array(
'soap_version'=>SOAP_1_1
,'encoding' => 'UTF-8'
,'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_DEFLATE
,'location'=>'https://test-intraship.dhl.com/intraship.57/jsp/Login_WS.jsp'
));
$response = $client->_doRequest($clientCommon, trim($request), $location, 'createShipmentDD', SOAP_1_1);
print_r($response);
?>
The XML code is copied from the DHL test tool, the access data are standard test data, which should actually always work. But I always become a "Wrong login data"-message. Why can it be?
I tried to find something out with the SoapUI programm but I don't seem to understand how all this stuff work.
Can you please give me some help?
The URL you are trying sending your SOAP-Request to (https://test-intraship.dhl.com/intraship.57/jsp/Login_WS.jsp) is not used as an Web Service endpoint - it is the Single-Sign-On URL for logging in your customer to the DHL Intraship Customer Portal (you can submit parceldata manually there).
The endpoint for the Web Service is http://test-intraship.dhl.com/ws/1_0/de/ISService (Source: https://entwickler.dhl.de/group/ep/webservices/intraship/quick-start)
You may need more information from DHL
https://test-intraship.dhl.com/intraship.57/jsp/Login_WS.jsp
To Login this URL you need User name and password, This information is other than cis:Authentification section you passed in soap:Header node.
This new User name and password you need to set in new "Zend_Soap_Client_Common" object.
Related
I am trying to develop an e-commerce website.
To manage multi-currency, I would like to use webservice for automatic conversions.
so I tried this webservice: http://www.webservicex.com/CurrencyConvertor.asmx?WSDL with this code :
try
{
$wsdl="http://www.webservicex.com/CurrencyConvertor.asmx?WSDL";
$webservice = new \SoapClient( $wsdl );
$country=array();
// Set the country variable to the country codes.
$country['FromCurrency']= 'USD';
$country['ToCurrency'] = 'EUR';
$webservice->ConversionRate($country);
echo $response->ConversionRateResult;*/
}catch(Exception $oException)
{
printf(
'<h4 style="color: Red">Exception</h4>
<p>%s</p>',
$oException->getMessage()
);
} `
Unfortunately, the service returns me - 1
is there a problem with my code or it's the service that no longer works!!
you know another web service that is stable?
thank you very much
Have a look at
https://openexchangerates.org/
http://fixer.io/
They both have a straight forward API you can integrate to.
I wrote very simple code to retrieve soap data:
$wsdl = 'https://...';
$client = new SoapClient($wsdl, ['trace' => true]);
$soap_parameters = [
'leveranciernaam' => 'xxx',
'leveranciersleutel' => 'yyy',
'brinnummer' => 'zzzz',
'schooljaar' => 2012
];
$response = $client->getLeerlingen($soap_parameters);
To my huge surprise, the return was different from the return i received while using a Java based GUI application.
Some fields in PHP SoapClient's response were consistently missing.
Just to make sure that things were not lost in translation to stdObjects, I used trace option to and extracted actual XMl from $client->__getLastResponse();
Still those fields were not there - very consistently over hundreds of records.
Windows Java based client's response:
<return>
<leerlingen>
<leerling>
<id>353226866</id>
<roepnaam>Evline</roepnaam>
...
<achternaam>Staalstra</achternaam>
<inschrijvingen>
<inschrijving>
<id>353226867</id>
<datumInschrijving>2007-08-20T00:00:00+02:00</datumInschrijving>
<schoolVanHerkomst>7138</schoolVanHerkomst>
<vervolgSchool>7138</vervolgSchool>
<onderwijsSoortBestemming>
<id>4085</id>
</onderwijsSoortBestemming>
</inschrijving>
</inschrijvingen>
</leerling>
...
</leerlingen>
<brins>
<brin>
<id>47187537</id>
<brinNummer>02YN02</brinNummer>
<schoolNaam>De Ambelt School V LZK</schoolNaam>
</brin>
...
</brins>
</return>
Response i get:
<return>
<leerlingen>
<leerling>
<id>353226866</id>
<roepnaam>Evline</roepnaam>
...
<achternaam>Staalstra</achternaam>
<inschrijvingen>
<inschrijving>
<id>353226867</id>
<datumInschrijving>2007-08-20T00:00:00+02:00</datumInschrijving>
<inschrijvingType>1766564</inschrijvingType>
</inschrijving>
</inschrijvingen>
</leerling>
...
</leerlingen>
</return>
PHP client does not get (or does not properly parse) any elements schoolVanHerkomst, vervolgSchool and onderwijsSoortBestemming in element inschrijving and it misses brins completely.
For brevity, I omitted other deeply nested elements that work just fine
Because expected results are dynamic, WDSL ( https://acceptatie.parnassys.net/bao/services/cxf/v1/generic?wsdl ) does not define ouput.
What is going on? It seems that PHP Soap client is less reliable than Java Soap clients
I am trying to code some PHP for an outbound call conference room. The point of the conference room is to make a temporary solution for our customers calling one of our call centers, who need to be transferred, and automatically placed in a call with the other call center. This is exactly what we need, but having this error.
I already tried SMS and standard calls and those work fine. When I run the code below for conference calls, I get this error.
Fatal error: Call to undefined method Services_Twilio::request()
I have my conference.xml file already, like so.
<?xml version="1.0" encoding="UTF-8" ?>
<Response>
<Dial>
<Conference>i2c</Conference>
</Dial>
</Response>
And my conference.php file looks like this:
<?php
// The PHP Twilio helper library. Get it here http://www.twilio.com/docs/libraries/
require('twilio-php/Services/Twilio.php');
$API_VERSION = '2010-04-01';
$ACCOUNT_SID = 'my sid #';
$AUTH_TOKEN = 'my auth_token';
$client = new Services_Twilio($ACCOUNT_SID, $AUTH_TOKEN);
// The phone numbers of the people to be called
$participants = array('customer#', 'call-center#');
// Go through the participants array and call each person.
foreach ($participants as $participant)
{
$vars = array(
'From' => 'my #',
'To' => $participant,
'Url' => 'conference.xml');
$response = $client->request("/$API_VERSION/Accounts/$ACCOUNT_SID/Calls", "POST", $vars);
}
?>
It's getting an error on line 23, which is the line with the $response on it. Can you tell what's going wrong? I'm working off this code that Twilio provided. The part that says "Reach Out and Call Somebody". I changed TwilioRestClient to Services_Twilio because that is the newer version.
https://www.twilio.com/blog/2011/07/easy-conference-calling-twilio.html
Anyone see where I'm messing up?
I am using the tmOAuth library.
With the new 1.1 API, the following is returning an error code 400 - but authentication was done (same authentication for statuses works)! The library I am using works fine for all calls, except this one!
$tmhOAuth->request(
'POST', $tmhOAuth->url('https://api.twitter.com/1.1/statuses/destroy/MYIDHERE.json'),
array(
'id' => MYIDHERE
)
);
The twitter API documentation states that you don't have to send the id in post - but this doesn't make any difference.
I have tested this today with two different libraries, and neither work.
Any suggestions - does anyone know if there is an issue with it??
According to your comment, you have tested this in two libraries for the 1.1 API.
You haven't tested it in this one though. Instructions here, although you seem to already have your credentials in hand.
This basically proves that the library you are using has the issue, not the twitter API. So either submit a bug report on github (how else are they to know?), or use another library like the one above.
The exact code required using the above library (and it works, I just tested it):
// Require the library file
require_once('TwitterAPIExchange.php');
// Set up your credentials
$settings = array(
'oauth_access_token' => "YOUR_TOKEN",
'oauth_access_token_secret' => "YOUR_TOKEN_SECRET",
'consumer_key' => "YOUR_CONSUMER_KEY",
'consumer_secret' => "YOUR_CONSUMER_SECRET"
);
// Put the correct ID in the URL
$url = 'https://api.twitter.com/1.1/statuses/destroy/YOURIDHERE.json';
// Set the request type
$requestMethod = 'POST';
// Set the post fields
$postfields = array('id' => 'YOURIDHERE');
// Make the request
$twitter = new TwitterAPIExchange($settings);
$json = $twitter->buildOauth($url, $requestMethod)
->setPostfields($postfields)
->performRequest();
// Dump the response
$result = json_decode($json);
var_dump($result);
If you're using the twitteroauth php library from Abraham Williams and trying to delete old tweets/retweets you need to construct the post() query as such:
$response = $connection->post('statuses/destroy/'.$tweetID, array()); //Curl url output = statuses/destroy/$tweetID.json
I am trying to make a web service call from PHP to a SOAP web service with a sample request which looks like this:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.somedomain.com/">
<soapenv:Header/>
<soapenv:Body>
<ws:SearchMarketplaceSku>
<ws:Request>
<ws:Security>
<ws:PartnerKey>[suppressed]</ws:PartnerKey>
<ws:Password>[suppressed]</ws:Password>
</ws:Security>
<ws:AvailableOnDate>2012-04-03T00:00:00</ws:AvailableOnDate>
<ws:IncludeStateDetails>true</ws:IncludeStateDetails>
<ws:State>CA</ws:State>
</ws:Request>
</ws:SearchMarketplaceSku>
</soapenv:Body>
</soapenv:Envelope>
The PHP code being used is:
$soapClient = new SoapClient($wsdlUrl);
$ap_param = array('PartnerKey' => $PartnerKey, 'Password' => $metapackPassword, 'AvailableOnDate' => '2012-04-03T00:00:00','IncludeStateDetails'=>true, 'State'=>'CA');
$info = $soapClient->__call("SearchMarketplaceSku", $ap_param);
The web service call results in an "Request was not specified properly; server unable to deserialize request" error? What is the problem? Does the $ap_param array need to include all the nested nodes coressponding with the XML? Is there an easier way to make this call using "WSDL" mode?
Thanks for your help
PartnerKey and Password has to be in an Array under the key Security:
$ap_param = array(
'Security' => array(
'PartnerKey' => $PartnerKey,
'Password' => $metapackPassword
),
'AvailableOnDate' => '2012-04-03T00:00:00',
'IncludeStateDetails'=>true, 'State'=>'CA'
);