Skip to content

Instantly share code, notes, and snippets.

@aanoaa
Created May 11, 2010 10:57
Show Gist options
  • Save aanoaa/397179 to your computer and use it in GitHub Desktop.
Save aanoaa/397179 to your computer and use it in GitHub Desktop.

Synopsis

xmlquery req.xml
xmlquery req1.xml req2.xml req3.xml
echo xml | xmlquery

Install

## local::lib, cpanminus install
wget -O - http://cpanmin.us/ | perl - local::lib App::cpanminus && echo 'eval $(perl -I$HOME/perl5/lib/perl5 -Mlocal::lib)' >> ~/.bashrc && . ~/.bashrc
perl Makefile.PL
make
make install
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:cash_apply_inputamountActn xmlns:ns1="urn:ServiceOrderFetcher" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<serviceOrder xsi:type="ns1:serviceOrder">
<sessionInitialDatas xmlns:ns2="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:Array" ns2:arrayType="ns1:sessionInitialDatas[3]">
<item xsi:type="ns1:sessionInitialDatas">
<name xsi:type="xsd:string">account</name> <!-- 아이디 -->
<value xsi:type="xsd:string"></value>
</item>
<item xsi:type="ns1:sessionInitialDatas">
<name xsi:type="xsd:string">memid</name> <!-- UCUSRINFO memid -->
<value xsi:type="xsd:string"></value>
</item>
<item xsi:type="ns1:sessionInitialDatas">
<name xsi:type="xsd:string">phone_num</name> <!-- 휴대전화번호 -->
<value xsi:type="xsd:string"></value>
</item>
</sessionInitialDatas>
<parameterDatas xmlns:ns3="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns3:Array" ns3:arrayType="ns1:parameterDatas[3]">
<item xsi:type="ns1:parameterDatas">
<name xsi:type="xsd:string">card_kind</name> <!-- 카드종류 조회자료 -->
<value xsi:type="xsd:string"></value>
</item>
<item xsi:type="ns1:parameterDatas">
<name xsi:type="xsd:string">inputmoney</name> <!-- 신청금액 -->
<value xsi:type="xsd:string"></value>
</item>
<item xsi:type="ns1:parameterDatas">
<name xsi:type="xsd:string">remain_amt</name> <!-- 한도잔액 조회자료 -->
<value xsi:type="xsd:string"></value>
</item>
</parameterDatas>
</serviceOrder>
</ns1:cash_apply_inputamountActn>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
#!/usr/bin/env perl
use strict;
use warnings;
use 5.008001;
use Getopt::Long;
use Pod::Usage;
use HTTP::Request;
use LWP::UserAgent;
use File::Slurp qw/slurp/;
my %options;
GetOptions(\%options, "--help");
run(\%options, @ARGV);
sub run {
my($opts, @args) = @_;
if ($opts->{help}) {
pod2usage(0);
}
my @xmls = setup_xmls($opts, @args);
my $url = "http://localhost:3000/wafservice"; #상용
my $res = req_to_WAS($url, \@xmls);
}
sub setup_xmls {
my ($opts, @args) = @_;
my @xmls;
if (@args == 0 or $args[0] eq '-') {
my $content = join '', <STDIN>;
push @xmls, { name => '', content => $content };
} else {
for my $arg (@args) {
push @xmls, { name => $arg , content => scalar slurp($arg) };
}
}
return @xmls;
}
sub req_to_WAS {
my ($url, $xmls) = @_;
my $req = HTTP::Request->new(POST=>"$url");
$req->content_type('application/x-www-form-urlencoded');
my $agent = LWP::UserAgent->new(
env_proxy => 1,
keep_alive => 1,
timeout => 30,
);
for my $xml (@{ $xmls }) {
$req->content($xml->{content});
my $res = $agent->request($req);
print "[ $xml->{name} ]\n";
print "[ HEADER ]\n";
print $res->headers_as_string();
print "[ CONTENT ]\n";
print $res->content();
}
}
__END__
=head1 NAME
xmlquery - Build cash service request xml message and query to dev WAS at BC card
=head1 SYNOPSIS
xmlquery req.xml
xmlquery req1.xml req2.xml req3.xml
echo xml | xmlquery
=head1 DESCRIPTION
See L<README.mkdn> for details.
=head1 LICENSE
same as Perl.
=head1 AUTHOR
hshong
=cut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment