Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- make a class file ::
- ====================
- <?php
- /**
- * Created by PhpStorm.
- * User: selimreza
- * Date: 5/3/16
- * Time: 10:29 PM
- */
- namespace App\Helpers;
- class TntExpress
- {
- /**
- * Submit XML to the TNT
- * server via a Stream instead
- * of cURL.
- *
- * @Returns String (XML)
- **/
- public static function sendToTNTServer( $Xml ) {
- $postdata = http_build_query(
- array(
- //For Future reference
- //the xml_in= ( the = ) is appended
- //Automatically by PHP
- 'xml_in' => $Xml
- )
- );
- $opts = array('http' =>
- array(
- 'method' => 'POST',
- 'header' => 'Content-type: application/x-www-form-urlencoded',
- 'content' => $postdata
- )
- );
- $context = stream_context_create( $opts );
- $output = file_get_contents(
- 'https://express.tnt.com/expressconnect/pricing/getprice',
- false,
- $context
- );
- return $output;
- }
- }
- call the method in controller::
- ===============================
- public function xml_data(){
- $XmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
- <PRICEREQUEST>
- <LOGIN>
- <COMPANY>Asim</COMPANY>
- <PASSWORD>tnt12345</PASSWORD>
- <APPID>IN</APPID>
- </LOGIN>
- <PRICECHECK>
- <RATEID>rate1</RATEID>
- <ORIGINCOUNTRY>GB</ORIGINCOUNTRY>
- <ORIGINTOWNNAME>Atherstone</ORIGINTOWNNAME>
- <ORIGINPOSTCODE>CV9 2RY</ORIGINPOSTCODE>
- <ORIGINTOWNGROUP/>
- <DESTCOUNTRY>ES</DESTCOUNTRY>
- <DESTTOWNNAME>Alicante</DESTTOWNNAME>
- <DESTPOSTCODE>03006</DESTPOSTCODE>
- <DESTTOWNGROUP/>
- <CONTYPE>N</CONTYPE>
- <CURRENCY>GBP</CURRENCY>
- <WEIGHT>0.2</WEIGHT>
- <VOLUME>0.1</VOLUME>
- <ACCOUNT/>
- <ITEMS>1</ITEMS>
- </PRICECHECK>
- </PRICEREQUEST>";
- $tnt = TntExpress::sendToTNTServer($XmlString);
- print_r($tnt);
- echo "OK";
- }
- OutPut::
- ========
- "login details not recognised"
Advertisement
Add Comment
Please, Sign In to add comment