309 lines
14 KiB
Perl
309 lines
14 KiB
Perl
|
|
#!/usr/bin/perl
|
||
|
|
|
||
|
|
BEGIN { use lib '/usr/home/cfg' ; require push_inc ; }
|
||
|
|
|
||
|
|
require cfg ;
|
||
|
|
|
||
|
|
use CGI::Carp qw(fatalsToBrowser);
|
||
|
|
|
||
|
|
print "Content-type: text/html\n\n";
|
||
|
|
|
||
|
|
use LWP::UserAgent;
|
||
|
|
use HTTP::Request;
|
||
|
|
use XML::Simple ;
|
||
|
|
use DBI;
|
||
|
|
use SOAP::Lite ;
|
||
|
|
|
||
|
|
#-------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
@ARGV = split(/\\*\&/, $ENV{'QUERY_STRING'});
|
||
|
|
our $debug = $ARGV[0];
|
||
|
|
my $suburb = $ARGV[1];
|
||
|
|
|
||
|
|
$suburb =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
|
||
|
|
|
||
|
|
# https://itvadmin.co.za/cgi-bin/scripts/admin/oneoff/dcb_soap_test.pl?1
|
||
|
|
|
||
|
|
#-------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
&today;
|
||
|
|
|
||
|
|
&send_it ;
|
||
|
|
&parse_it ;
|
||
|
|
&read_it ;
|
||
|
|
|
||
|
|
# &dcd_set_parameters ;
|
||
|
|
# &dcb_send_xml ;
|
||
|
|
|
||
|
|
exit;
|
||
|
|
|
||
|
|
#-------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
sub send_it {
|
||
|
|
|
||
|
|
|
||
|
|
# <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
|
||
|
|
# <Body>
|
||
|
|
# <savewabill xmlns="http://tempuri.org/">
|
||
|
|
# <!-- Optional -->
|
||
|
|
# <request>
|
||
|
|
# <AccNr xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">DCBDEVLP</AccNr>
|
||
|
|
# <AddressLine1 xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">15 SIM ROAD</AddressLine1>
|
||
|
|
# <AddressLine2 xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">,</AddressLine2>
|
||
|
|
# <AddressLine3 xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">POMONA</AddressLine3>
|
||
|
|
# <AddressLine4 xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">GAUTENG</AddressLine4>
|
||
|
|
# <ContactNumber xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">0</ContactNumber>
|
||
|
|
# <ContactPerson xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">DEV</ContactPerson>
|
||
|
|
# <CustomerReferenceNumber xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">DEV</CustomerReferenceNumber>
|
||
|
|
# <Date xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">2023-01-26</Date>
|
||
|
|
# <DestHub xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">JNB</DestHub>
|
||
|
|
# <Number xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">APITEST23</Number>
|
||
|
|
# <OriginHub xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">JNB</OriginHub>
|
||
|
|
# <PostalCode xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">1619</PostalCode>
|
||
|
|
# <Reciever xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">DEV SERVICE</Reciever>
|
||
|
|
# <RouteCode xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">JNBKMPE</RouteCode>
|
||
|
|
# <SpecialInstructions xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request"> </SpecialInstructions>
|
||
|
|
# <serviceType xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">1</serviceType>
|
||
|
|
# <!-- Optional -->
|
||
|
|
# <waybillInvoices xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">
|
||
|
|
# <!-- Optional -->
|
||
|
|
# <WaybillInvoices xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Entities">
|
||
|
|
# <InvAmount></InvAmount>
|
||
|
|
# <InvDescription></InvDescription>
|
||
|
|
# <InvNum></InvNum>
|
||
|
|
# <InvUnits></InvUnits>
|
||
|
|
# <WaybillId>0</WaybillId>
|
||
|
|
# </WaybillInvoices>
|
||
|
|
# </waybillInvoices>
|
||
|
|
# <!-- Optional -->
|
||
|
|
# <waybillparcels xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">
|
||
|
|
# <!-- Optional -->
|
||
|
|
# <WaybillParcels xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Entities">
|
||
|
|
# <LoadType>STD</LoadType>
|
||
|
|
# <RateType>G</RateType>
|
||
|
|
# <WaybillId>0</WaybillId>
|
||
|
|
# <breadth>40</breadth>
|
||
|
|
# <description>DEV</description>
|
||
|
|
# <height>32</height>
|
||
|
|
# <length>32</length>
|
||
|
|
# <mass>32</mass>
|
||
|
|
# <qty>1</qty>
|
||
|
|
# </WaybillParcels>
|
||
|
|
# </waybillparcels>
|
||
|
|
# </request>
|
||
|
|
# </savewabill>
|
||
|
|
# </Body>
|
||
|
|
# </Envelope>
|
||
|
|
|
||
|
|
|
||
|
|
# <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/">
|
||
|
|
# <Body>
|
||
|
|
# <savewabill xmlns="http://tempuri.org/">
|
||
|
|
# <!-- Optional -->
|
||
|
|
# <request>
|
||
|
|
# <AccNr xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">DCBDEVLP</AccNr>
|
||
|
|
# <AddressLine1 xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">15 SIM ROAD</AddressLine1>
|
||
|
|
# <AddressLine2 xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">,</AddressLine2>
|
||
|
|
# <AddressLine3 xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">POMONA</AddressLine3>
|
||
|
|
# <AddressLine4 xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">GAUTENG</AddressLine4>
|
||
|
|
# <ContactNumber xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">0</ContactNumber>
|
||
|
|
# <ContactPerson xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">DEV</ContactPerson>
|
||
|
|
# <CustomerReferenceNumber xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">DEV</CustomerReferenceNumber>
|
||
|
|
# <Date xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">2023-01-26</Date>
|
||
|
|
# <DestHub xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">JNB</DestHub>
|
||
|
|
# <Number xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">APITEST23</Number>
|
||
|
|
# <OriginHub xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">JNB</OriginHub>
|
||
|
|
# <PostalCode xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">1619</PostalCode>
|
||
|
|
# <Reciever xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">DEV SERVICE</Reciever>
|
||
|
|
# <RouteCode xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">JNBKMPE</RouteCode>
|
||
|
|
# <SpecialInstructions xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request"> </SpecialInstructions>
|
||
|
|
# <serviceType xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">1</serviceType>
|
||
|
|
# <!-- Optional -->
|
||
|
|
# <waybillInvoices xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">
|
||
|
|
# <!-- Optional -->
|
||
|
|
# <WaybillInvoices xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Entities">
|
||
|
|
# <InvAmount></InvAmount>
|
||
|
|
# <InvDescription></InvDescription>
|
||
|
|
# <InvNum></InvNum>
|
||
|
|
# <InvUnits></InvUnits>
|
||
|
|
# <WaybillId>0</WaybillId>
|
||
|
|
# </WaybillInvoices>
|
||
|
|
# </waybillInvoices>
|
||
|
|
# <!-- Optional -->
|
||
|
|
# <waybillparcels xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">
|
||
|
|
# <!-- Optional -->
|
||
|
|
# <WaybillParcels xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Entities">
|
||
|
|
# <LoadType>STD</LoadType>
|
||
|
|
# <RateType>G</RateType>
|
||
|
|
# <WaybillId>0</WaybillId>
|
||
|
|
# <breadth>40</breadth>
|
||
|
|
# <description>DEV</description>
|
||
|
|
# <height>32</height>
|
||
|
|
# <length>32</length>
|
||
|
|
# <mass>32</mass>
|
||
|
|
# <qty>1</qty>
|
||
|
|
# </WaybillParcels>
|
||
|
|
# </waybillparcels>
|
||
|
|
# </request>
|
||
|
|
# </savewabill>
|
||
|
|
# </Body>
|
||
|
|
# </Envelope>
|
||
|
|
# <PostalCode xmlns="http://tempuri.org/">
|
||
|
|
# <request>
|
||
|
|
# <PostalCode xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request"></PostalCode>
|
||
|
|
# <Suburb xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$suburb</Suburb>
|
||
|
|
# </request>
|
||
|
|
# </PostalCode>
|
||
|
|
|
||
|
|
my $message = qq~<?xml version="1.0" encoding="utf-8"?>
|
||
|
|
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
|
||
|
|
<soap:Body>
|
||
|
|
<PostalCode xmlns="http://tempuri.org/">
|
||
|
|
<request>
|
||
|
|
<PostalCode xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request"></PostalCode>
|
||
|
|
<Suburb xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">$suburb</Suburb>
|
||
|
|
</request>
|
||
|
|
</PostalCode>
|
||
|
|
</soap:Body>
|
||
|
|
</soap:Envelope>~ ;
|
||
|
|
|
||
|
|
if ($debug) {
|
||
|
|
# print $message;
|
||
|
|
}
|
||
|
|
|
||
|
|
my $userAgent = LWP::UserAgent->new();
|
||
|
|
my $request = HTTP::Request->new(POST => 'https://dcboms.co.za/APIUAT/OMSIntegrate.svc');
|
||
|
|
# $request->header(SOAPAction => '"https://dcboms.co.za/APIUAT/OMSIntegrate.svc"');
|
||
|
|
$request->header(SOAPAction => '"http://tempuri.org/IOMSIntegrate/PostalCode"');
|
||
|
|
$request->content($message);
|
||
|
|
$request->content_type("text/xml; charset=utf-8");
|
||
|
|
my $response = $userAgent->request($request);
|
||
|
|
|
||
|
|
# Check response
|
||
|
|
my $response_code = $response -> code ;
|
||
|
|
my $response_content = $response -> content ;
|
||
|
|
|
||
|
|
$returnxml = $response_content ;
|
||
|
|
|
||
|
|
# print $returnxml ;
|
||
|
|
|
||
|
|
} #-------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
sub parse_it {
|
||
|
|
|
||
|
|
# use Data::Dumper;
|
||
|
|
# print Dumper(\$returnxml);
|
||
|
|
# exit;
|
||
|
|
|
||
|
|
$returnxml =~ s/[\x80-\xFF]/?/g ;
|
||
|
|
my $xml = new XML::Simple or die "Cant instantiate object XML::Simple $!" ;
|
||
|
|
# my $xmldata = $xml->XMLin($returnxml) or die "Cant open xmldata $!" ;
|
||
|
|
$xmldata = $xml->XMLin($returnxml, forcearray => 1) or die "Cant open xmldata $!";
|
||
|
|
|
||
|
|
if ($debug) {
|
||
|
|
use Data::Dumper;
|
||
|
|
print Dumper(\$xmldata);
|
||
|
|
# exit ;
|
||
|
|
}
|
||
|
|
|
||
|
|
} #-------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
sub read_it {
|
||
|
|
|
||
|
|
foreach my $hashref ( @{$xmldata->{'s:Body'}->[0]->{'PostalCodeResponse'}->[0]->{'PostalCodeResult'}->[0]->{'a:ArrayOfpostalCode'} } ) {
|
||
|
|
# unless (lc ${$hashref}{'Name'}->[0] eq lc $search) { next ; }
|
||
|
|
# print ${$hashref}{'ContentEntityId'}->[0] ;
|
||
|
|
|
||
|
|
# unless (exists $exists{${$hashref}{'a:postalCode'}->[0]}) {
|
||
|
|
foreach $address ( @{$hashref}{'a:postalCode'}) {
|
||
|
|
# print $address . "<br>" ;
|
||
|
|
# print Dumper(\$address);
|
||
|
|
# print Dumper(\$address{'a:city'}->[0]);
|
||
|
|
# print 'a:city=' . ${$hashref}{'a:postalCode'}->[0]->{'a:city'}->[0] . "\n" ;
|
||
|
|
# print 'a:suburb=' . ${$hashref}{'a:postalCode'}->[0]->{'a:suburb'}->[0] . "\n" ;
|
||
|
|
# print 'a:code=' . ${$hashref}{'a:postalCode'}->[0]->{'a:code'}->[0] . "\n" ;
|
||
|
|
# print 'a:routeCode=' . ${$hashref}{'a:postalCode'}->[0]->{'a:routeCode'}->[0] . "\n" ;
|
||
|
|
# print ${$address}->[0] . "\n" ;
|
||
|
|
# print 'a:city=' . ${$address}{'a:city'}->[0] . "<br>" ;
|
||
|
|
# print 'a:routeCode=' . ${$address}{'a:routeCode'}->[0] . "<br>" ;
|
||
|
|
# print 'a:suburb=' . ${$address}{'a:suburb'}->[0] . "<br>" ;
|
||
|
|
# print 'a:code=' . ${$address}{'a:code'}->[0] . "<br>" ;
|
||
|
|
|
||
|
|
# $i{dcb_id} = ${$hashref}{'ContentEntityId'}->[0] ;
|
||
|
|
# $i{latitude} = ${$hashref}{'Latitude'}->[0] ;
|
||
|
|
# $i{longitude} = ${$hashref}{'Longitude'}->[0] ;
|
||
|
|
# $i{country} = ${$hashref}{'Country'}->[0] ;
|
||
|
|
# $i{area} = ${$hashref}{'Area'}->[0] ;
|
||
|
|
|
||
|
|
# # unless (ref(${$hashref}{'Area'}->[0] eq 'HASH')) { $i{area} = ${$hashref}{'Area'}->[0] ; }
|
||
|
|
# # unless (ref(${$hashref}{'Location'}->[0] eq 'HASH')) { $i{location} = ${$hashref}{'Location'}->[0] ; }
|
||
|
|
|
||
|
|
# $i{location} = ${$hashref}{'Location'}->[0] unless (ref(${$hashref}{'Location'}->[0]) eq 'HASH');
|
||
|
|
|
||
|
|
# $i{lastupdate} = "$now_ccyy_mm_dd $now_hour:$now_min:$now_sec" ;
|
||
|
|
# &common_db_insert('dcb_places') ;
|
||
|
|
}
|
||
|
|
# last ;
|
||
|
|
}
|
||
|
|
|
||
|
|
} #-------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
sub dcd_set_parameters {
|
||
|
|
|
||
|
|
# use SOAP::Lite ;
|
||
|
|
# +trace => [ transport => sub { print $_[0]->as_string } ];
|
||
|
|
|
||
|
|
$dcb_param{'uri'} = 'https://dcboms.co.za/APIUAT/OMSIntegrate.svc' ;
|
||
|
|
$dcb_param{'proxy'} = 'https://dcboms.co.za/APIUAT/OMSIntegrate.svc' ;
|
||
|
|
# $dcb_param{'username'} = 'res@followme2africa.com' ;
|
||
|
|
# $dcb_param{'password'} = 'moby602' ;
|
||
|
|
|
||
|
|
} #----------------------------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
sub dcb_send_xml {
|
||
|
|
|
||
|
|
$dcb_param{'method'} = 'PostalCode' ;
|
||
|
|
|
||
|
|
&dcb_create_soap ;
|
||
|
|
|
||
|
|
# if (lc $username eq 'groz000'){
|
||
|
|
# print "Content-type: text/html\n\n";
|
||
|
|
# use Data::Dumper;
|
||
|
|
# print Dumper(\$xml_out_save_itinerary);
|
||
|
|
# }
|
||
|
|
|
||
|
|
$xml_out = qq~
|
||
|
|
<request>
|
||
|
|
<PostalCode xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request"></PostalCode>
|
||
|
|
<Suburb xmlns="http://schemas.datacontract.org/2004/07/OMSIntegrate.Request">POMONA</Suburb>
|
||
|
|
</request>
|
||
|
|
~ ;
|
||
|
|
|
||
|
|
$xml_out_dcb_soap = SOAP::Data->type('xml' => $xml_out);
|
||
|
|
|
||
|
|
$dcb_response = $dcb_soap -> call ($dcb_method => $xml_out_dcb_soap) ;
|
||
|
|
|
||
|
|
&common_debug ("dcb_send_xml : dcb_response [ $dcb_response ]") ;
|
||
|
|
|
||
|
|
} #----------------------------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
sub dcb_create_soap {
|
||
|
|
|
||
|
|
$dcb_soap = SOAP::Lite
|
||
|
|
->proxy( $dcb_param{'proxy'} )
|
||
|
|
->autotype(0)
|
||
|
|
->outputxml(1)
|
||
|
|
->on_action( sub { join '/', @_ } )
|
||
|
|
;
|
||
|
|
|
||
|
|
$dcb_method = SOAP::Data -> name( $dcb_param{'method'} ) -> attr({ 'xmlns' => $dcb_param{'uri'} } ) ;
|
||
|
|
|
||
|
|
} #----------------------------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
use common ;
|
||
|
|
use today ;
|
||
|
|
|
||
|
|
1;
|