DHL Rate calculation - php

In my website(php based) I want implement a rate calculator of DHL. I want to add 3 fields-1.Origin, 2.Destination and 3.Weight. These 3 values will be sent to DHL server and in return I want to have the RATE. How can I do that?
In another section, I will add more field (address, product hts code, etc.) with those 3 to get the RATE. How can it be done also??

Below is DHL rate calculator code: You need to change siteid and password with your DHL siteid and password.
<?php
$data = '<?xml version="1.0" encoding="UTF-8"?>
<p:DCTRequest xmlns:p="http://www.dhl.com" xmlns:p1="http://www.dhl.com/datatypes" xmlns:p2="http://www.dhl.com/DCTRequestdatatypes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.dhl.com DCT-req.xsd ">
<GetQuote>
<Request>
<ServiceHeader>
<MessageTime>'.date('c').'</MessageTime>
<MessageReference>1234567890123456789012345678901</MessageReference>
<SiteID>YOUR_DHL_SITE_ID</SiteID>
<Password>YOUR_DHL_PASSWORD</Password>
</ServiceHeader>
</Request>
<From>
<CountryCode>GB</CountryCode>
<Postalcode>WC1A</Postalcode>
</From>
<BkgDetails>
<PaymentCountryCode>US</PaymentCountryCode>
<Date>2011-06-06</Date>
<ReadyTime>PT10H21M</ReadyTime>
<ReadyTimeGMTOffset>+01:00</ReadyTimeGMTOffset>
<DimensionUnit>CM</DimensionUnit>
<WeightUnit>KG</WeightUnit>
<Pieces><Piece>
<PieceID>1</PieceID>
<Height>20</Height>
<Depth>20</Depth>
<Width>20</Width>
<Weight>19</Weight>
</Piece></Pieces>
<IsDutiable>N</IsDutiable>
<NetworkTypeCode>AL</NetworkTypeCode>
</BkgDetails>
<To>
<CountryCode>US</CountryCode>
<Postalcode>10101</Postalcode>
</To>
</GetQuote>
</p:DCTRequest>';
$tuCurl = curl_init();
curl_setopt($tuCurl, CURLOPT_URL, "https://xmlpitest-ea.dhl.com/XMLShippingServlet");
curl_setopt($tuCurl, CURLOPT_PORT , 443);
curl_setopt($tuCurl, CURLOPT_VERBOSE, 0);
curl_setopt($tuCurl, CURLOPT_HEADER, 0);
curl_setopt($tuCurl, CURLOPT_POST, 1);
curl_setopt($tuCurl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($tuCurl, CURLOPT_POSTFIELDS, $data);
curl_setopt($tuCurl, CURLOPT_HTTPHEADER, array("Content-Type: text/xml","SOAPAction: \"/soap/action/query\"", "Content-length: ".strlen($data)));
$tuData = curl_exec($tuCurl);
curl_close($tuCurl);
$xml = simplexml_load_string($tuData);
print "<pre>";
print_r($xml);
?>
For more reference click on below link:
http://xmlpitest-ea.dhl.com/serviceval/jsps/main/Main_menu.jsp

Related

UIDAI Adhaar API in PHP

$curl = curl_init();
$xml_data = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Auth uid=”999999990019” tid=”public” ac=”public” sa=”public” ver=”1.6”txn=”AuthDemoClient:public:20160616070338756” lk=”MBFWjkJHNFfLidl8oOHtUwgL5p1ZjDbWrqsMEVEJLVEDpnlNj_CZTg”>
<Uses pi=”y” pa=”n” pfa=”n” bio=”n” bt=”n” pin=”” otp=”n”/>
<Tkn type=”” value=””/>
<Meta udc=”” fdc=”” idc=”” pip=”” lot=”G|P” lov=””/>
<Skey ci=”” ki=””></Skey>
<Data type=”X|P”>encrypted PID block</Data>
<Hmac>SHA-256 Hash of Pid block, encrypted and then encoded</Hmac
<Signature>Digital signature of AUA</Signature>
</Auth>
</xml>';
curl_setopt($curl, CURLOPT_URL,"http://auth.uidai.gov.in/1.6/public/9/9/MH4hSkrev2h_Feu0lBRC8NI-iqzT299_qPSSstOFbNFTwWrie29ThDo");
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: text/xml','Content-Length:length'));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $xml_data);
$result = curl_exec($curl);
curl_close($curl);
print_r($result);
This is the sample code which I wrote.Needs test data for some of the left out attributes like udc,fdc,idc etc. When I try to fire this API gets 400-Bad Request.Help would be appriciated.

Want to execute url with Port number

Dear all please help me how can i execute following url using cURL using php?
https://telenorcsms.com.pk:27677/corporate_sms2/api/auth.jsp?msisdn=923468211085&password=Javed1212
i am tring this but no result found.
$tuCurl = curl_init();
curl_setopt($tuCurl, CURLOPT_URL, "https://telenorcsms.com.pk/corporate_sms2/api/auth.jsp?msisdn=923468211085&password=Javed1212");
curl_setopt($tuCurl, CURLOPT_PORT , 27677);
curl_setopt($tuCurl, CURLOPT_VERBOSE, 0);
curl_setopt($tuCurl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($tuCurl, CURLOPT_CONNECTTIMEOUT, 5); // 5 seconds timeout
$tuData = curl_exec($tuCurl);
curl_close($tuCurl);
echo $tuData;
It seems that your request is at the "middle" of authentication process. Perhaps, you need to consider some credentials over the request to access the needed resource.At first, set CURLOPT_VERBOSE in active mode : true(1) (to obtain the details of the request processing).Secondly, that site returns an XML response back. Use var_dump to get more details about response.Here is how it looks now:
$tuCurl = curl_init();
curl_setopt($tuCurl, CURLOPT_URL, "https://telenorcsms.com.pk/corporate_sms2/api/auth.jsp?msisdn=923468211085&password=Javed1212");
curl_setopt($tuCurl, CURLOPT_PORT , 27677);
curl_setopt($tuCurl, CURLOPT_VERBOSE, true);
curl_setopt($tuCurl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($tuCurl, CURLOPT_CONNECTTIMEOUT, 5); // 5 seconds timeout
$tuData = curl_exec($tuCurl);
curl_close($tuCurl);
var_dump($tuData);
The output:
'<?xml version="1.0" encoding="UTF-8" ?>
<corpsms>
<command>Auth_request</command>
<data>8c22d08be9bd492ea06bef31af4d62f3</data>
<response>OK</response>
</corpsms >
'

Amazon MWS SubmitFeed error: Keys may not contain <

I'm having problems submitting a feed to Amazon MWS. I keep receiving the following error: "Invalid query string provided - Keys may not contain <"
This is my code:
$apicall = $this->build_url($function, $params);
$ch = curl_init($apicall);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
if ($this->xml) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, (string)$this->xml);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: text/xml"));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-MD5: " . base64_encode(md5($this->xml))));
}
else {
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: text/xml'));
}
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
$response = curl_exec($ch);
$info = print_r(curl_getinfo($ch), true);
curl_close($ch);
$apicall is formed on-the-fly and comes in the form:
https://mws.amazonservices.com/Feeds/2009-01-01?ASINList.ASIN.1=B00C5XBAOA&AWSAccessKeyId=***&Action=SubmitFeed&FeedType=_POST_PRODUCT_PRICING_DATA_&MWSAuthToken=***&SellerId=***&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2015-06-09T09%3A58%3A01.000Z&Version=2009-01-01&Signature=***
(which works fine with other calls to Reports or to Orders)
$this->xml is kept as a "TEXT" field in the MySQL db; this is a sample XML (I added lines to make it readable):
<?xml version="1.0"?>
<AmazonEnvelope xsi="http://www.w3.org/2001/XMLSchema-instance" noNamespaceSchemaLocation="amzn-envelope.xsd">
<Header>
<DocumentVersion>1.01</DocumentVersion>
<MerchantIdentifier>***</MerchantIdentifier>
</Header>
<MessageType>Price</MessageType>
<Message>
<MessageID>1</MessageID>
<OperationType>Update</OperationType>
<Price>
<SKU>***</SKU>
<StandardPrice currency="USD">33.5</StandardPrice>
</Price>
</Message>
</AmazonEnvelope>
I seem to review every single relevant link on the internet and cannot find the answer.
Maybe someone can give me a hint what may go wrong in the above code?
Thanks.
Found the solutions myself (after digging more that a day):
1) Content-MD5 must be calculated in the following way:
base64_encode(md5($this->xml, **true**));
(thanks to this answer: https://sellercentral.amazon.com/forums/message.jspa?messageID=2767745)
2) passing header parameters to cUrl must be one-time operation, that is - all headers have to be passed as an array.

Tracking details not updating via eBay's API

I am currently trying to send information to eBay to set the orders shipment/tracking details. At the moment I am getting a 'success' message but no information is update on eBay's website.
I have been using the links below to guide me on implementing this change:
http://developer.ebay.com/devzone/large-merchant-services/Concepts/MakingACall.html
http://developer.ebay.com/devzone/merchant-data/CallRef/SetShipmentTrackingInfo.html#Samples
The format of the XML I am sending back is in the exact format as described, please see below the details I am sending and the PHP used to send via CURL through eBay's API.
XML:
<?xml version="1.0" encoding="UTF-8"?>
<BulkDataExchangeRequests>
<Header>
<Version>591</Version>
<SiteID>0</SiteID>
</Header>
<SetShipmentTrackingInfoRequest xmlns="urn:ebay:apis:eBLBaseComponents">
<OrderID>261671515555-0</OrderID>
<OrderLineItemID>261672341232</OrderLineItemID>
<Shipment>
<ShipmentTrackingNumber>JD0002250296232332</ShipmentTrackingNumber>
<ShippedTime>2014-11-27T14:41:27\Z</ShippedTime>
<ShippingCarrierUsed>Yodel</ShippingCarrierUsed>
</Shipment>
</SetShipmentTrackingInfoRequest>
</BulkDataExchangeRequests>
PHP:
$xml_request = "";
$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, $ebay_url);
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($connection, CURLOPT_HTTPHEADER, $headers);
curl_setopt($connection, CURLOPT_POST, 1);
curl_setopt($connection, CURLOPT_POSTFIELDS, $xml_request);
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($connection);
curl_close($connection);
var_dump($response);
The issue was the provider of the API was having intermittant issuses.

Not able to add a contact into google in PHP curl

I want to add a contact with data to google contacts.i am getting error as "There was an error in your request. That's all we know."
The code is as follows
<?php
$contact_detail='<?xml version="1.0"?>
<atom:entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:gd="http://schemas.google.com/g/2005">
<gd:name>
<gd:firstName>John</gd:firstName>
<gd:additionalName> test</gd:additionalName>
<gd:givenName>Doe</gd:givenName>
</gd:name>
<gd:email address="john#doe.com" rel="http://schemas.google.com/g/2005#work"/>
<gd:email address="john2#doe.com" rel="http://schemas.google.com/g/2005#home"/>
<gd:organization rel="http://schemas.google.com/g/2005#work">
<gd:orgName>John Deere</gd:orgName>
<gd:orgTitle>Owner</gd:orgTitle>
</gd:organization>
</atom:entry>';
$url="https://www.google.com/m8/feeds/contacts/default/full";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_POSTFIELDS, "$contact_detail");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
print($output);
curl_close($ch);
https://developers.google.com/google-apps/contacts/v2/developers_guide_protocol
To publish this entry, send it to the contact-list post URL as follows. First, place your Atom element in the body of a new POST request, using the application/atom+xml content type. Then send it to the post URL. For example, to add a contact to the contact list belonging to liz#gmail.com, post the new entry to the following URL: https://www.google.com/m8/feeds/contacts/liz%40gmail.com/full

Categories