Use crul to access the soap server and automatically convert XML into an array, with the tonal logging function

From , 5 Years ago, written in PHP, viewed 101 times.
URL https://pastebin.vip/view/8e930496
  1. <?php
  2.  
  3. class oxylaneSoap
  4. {
  5.  
  6.     var $gwUrl = 'http://preprodid.oxylane.com/wsdispatcher/wsgiftcard.ws';//网关地址
  7.         var $CFG=array(("LOGIN","KEY","LOGIN","WSGiftCard","GIFTCA","2.1.0","CASH");
  8.         var $debug = false;
  9.         var $logdir = '';
  10.         public function soapService($body){
  11.            $xml=$this->xml($body);
  12.            if($this->debug) echo __FILE__.':'.__LINE__.' '.__FUNCTION__.' '.date('Y-m-d H:i:s').'<br>';
  13.            if($this->debug) echo '<textarea cols="50" style="width:100%">'.htmlspecialchars($xml).'</textarea>';
  14.            
  15.        $result = $this->vcurlsoap($this->gwUrl,$xml,'');
  16.       // $result = $this->req($this->gwUrl, $data, $func);
  17.            
  18.            if($this->debug) echo __FILE__.':'.__LINE__.' '.__FUNCTION__.' '.date('Y-m-d H:i:s').'<br>';
  19.            if($this->debug)
  20.                 echo '<textarea cols="50" style="width:100%">'.htmlspecialchars($result).'</textarea><hr>';
  21.                
  22.                 if($this->logdir){
  23.                    $logfile = $this->logdir.'/log_api_'.date('Y-m-d_H_i_s').'_post.xml';
  24.                    file_put_contents($logfile,$xml);
  25.                    file_put_contents(str_replace('_post','_result',$logfile),$result);
  26.                 }
  27.            return $this->xml2array($result);
  28.     }
  29.        
  30.         public function xml($body){
  31.                 $SIGNATURE=$this->ComputeSignature($this->CFG);
  32.                 $xml ='<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
  33. xmlns:com="com.decathlon.wsdispatch.uddi"
  34. xmlns:com1="com.decathlon.wsdispatch.security"
  35. xmlns:urn="urn:giftcard.decathlon.com"
  36. xmlns:data="http://data.webservices.giftcard.decathlon.com">
  37.   <soapenv:Header>
  38.      <com1:LOGIN>'.$this->CFG[0].'</com1:LOGIN>
  39.      <com1:SIGNATURE>'.$SIGNATURE.'</com1:SIGNATURE>
  40.      <com:CLIENT_APP>'.$this->CFG[2].'</com:CLIENT_APP>
  41.      <com:WS_NAME>'.$this->CFG[3].'</com:WS_NAME>
  42.      <com:WS_APP>'.$this->CFG[4].'</com:WS_APP>
  43.      <com:WS_VERSION>'.$this->CFG[5].'</com:WS_VERSION>
  44.      <com:WS_DOMAIN>'.$this->CFG[6].'</com:WS_DOMAIN>
  45.  
  46.   </soapenv:Header>
  47.   <soapenv:Body>
  48.      '.$body.'
  49.   </soapenv:Body>
  50. </soapenv:Envelope>';
  51.                 return $xml;
  52.         }
  53.        
  54.         public function vcurl($url, $post = '', $cookie = '', $cookiejar = '', $referer = ''){
  55.   $tmpInfo = '';
  56.   //用来存放cookie的文件
  57.   $cookiepath = getcwd().'./'.$cookiejar;
  58.   //初始化curl
  59.   $curl = curl_init();
  60.   //设定目标网址
  61.   curl_setopt($curl, CURLOPT_URL, $url);
  62.   //使用目前所用的浏览器代理
  63.   curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
  64.   //curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");                 
  65.   //如果有Ref参数,则设置Referer头,否则自动设置Referer头
  66.   if($referer) {
  67.     curl_setopt($curl, CURLOPT_REFERER, $referer);
  68.   } else {
  69.     curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
  70.   }
  71.   //如果有post数据参数,则方法为POST,并且设置数据,否则为GET
  72.   if($post) {
  73.     //发送一个常规的POST请求,默认类型为:application/x-www-form-urlencoded,表单提交
  74.     curl_setopt($curl, CURLOPT_POST, 1);
  75.     curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
  76.   }
  77.   //如果有cookie参数,则设置
  78.   if($cookie) {
  79.     curl_setopt($curl, CURLOPT_COOKIE, $cookie);
  80.   }
  81.   //如果有cookie文件参数,则设置存取Cookie文件名
  82.   if($cookiejar) {
  83.   curl_setopt($curl, CURLOPT_COOKIEJAR, $cookiepath);
  84.   curl_setopt($curl, CURLOPT_COOKIEFILE, $cookiepath);
  85.   }
  86.   //如果是302转移,则返回转移后的网址及内容
  87.   curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
  88.   //设置执行的最大秒数
  89.   curl_setopt($curl, CURLOPT_TIMEOUT, 100);
  90.   //返回内容中是否包含头信息
  91.   curl_setopt($curl, CURLOPT_HEADER, 0);
  92.   //把返回的结果存在文件或者变量中,而不是直接显示在浏览器
  93.   curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  94.   //执行函数后的返回结果
  95.   $tmpInfo = curl_exec($curl);
  96.   //如果出错,显示错误信息
  97.   if (curl_errno($curl)) {
  98.     $tmpInfo = '<pre><b>错误:</b><br />'.curl_error($curl);
  99.   }
  100.   //关闭curl对象
  101.   curl_close($curl);
  102.   //返回结果
  103.   return $tmpInfo;
  104.         }
  105.        
  106.         public function vcurlsoap($url, $SoapRequest, $SoapAction) {
  107.                 $ch = curl_init (); //initiate the curl session
  108.                 curl_setopt ( $ch, CURLOPT_URL, $url ); //set to url to post to
  109.                 curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 ); // return data in a variable
  110.                 curl_setopt ( $ch, CURLOPT_HEADER, 0 );
  111.                 curl_setopt ( $ch, CURLOPT_POST, 1 );
  112.                 curl_setopt ( $ch, CURLOPT_POSTFIELDS, $SoapRequest ); // post the xml
  113.                 curl_setopt ( $ch, CURLOPT_TIMEOUT, 200 ); // set timeout in seconds
  114.                 curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
  115.                 $header = array ("Content-Type: text/xml" );
  116.                 $header [] = "Content-Length: ".strlen($SoapRequest);
  117.                
  118.                 if (! is_null ( $SoapAction ))
  119.                         $header [] = 'SOAPAction: "' . $SoapAction . '"';
  120.                 curl_setopt ( $ch, CURLOPT_HTTPHEADER, $header );
  121.                
  122.                 $xmlResponse = curl_exec ( $ch );
  123.                 curl_close ( $ch );
  124.                
  125.                 return $xmlResponse;
  126.         }
  127.        
  128.         /**
  129.          * xml转换成数组
  130.          * @param type $contents
  131.          * @param type $get_attributes
  132.          * @param type $priority
  133.          * @return type
  134.          */
  135.         public function xml2array($contents, $get_attributes=1, $priority = 'tag') {
  136.                 if (!$contents)
  137.                         return array();
  138.        
  139.                 if (!function_exists('xml_parser_create')) {
  140.                         //print "'xml_parser_create()' function not found!";
  141.                         return array();
  142.                 }
  143.        
  144.                 //Get the XML parser of PHP - PHP must have this module for the parser to work
  145.                 $parser = xml_parser_create('');
  146.                 xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8"); # http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss
  147.                 xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
  148.                 xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
  149.                 xml_parse_into_struct($parser, trim($contents), $xml_values);
  150.                 xml_parser_free($parser);
  151.        
  152.                 if (!$xml_values)
  153.                         return; //Hmm
  154.        
  155.        
  156.        
  157.        
  158.        
  159.                        
  160.         //Initializations
  161.                 $xml_array = array();
  162.                 $parents = array();
  163.                 $opened_tags = array();
  164.                 $arr = array();
  165.        
  166.                 $current = &$xml_array; //Refference
  167.                 //Go through the tags.
  168.                 $repeated_tag_index = array(); //Multiple tags with same name will be turned into an array
  169.                 foreach ($xml_values as $data) {
  170.                         unset($attributes, $value); //Remove existing values, or there will be trouble
  171.                         //This command will extract these variables into the foreach scope
  172.                         // tag(string), type(string), level(int), attributes(array).
  173.                         extract($data); //We could use the array by itself, but this cooler.
  174.        
  175.                         $result = array();
  176.                         $attributes_data = array();
  177.        
  178.                         if (isset($value)) {
  179.                                 if ($priority == 'tag')
  180.                                         $result = $value;
  181.                                 else
  182.                                         $result['value'] = $value; //Put the value in a assoc array if we are in the 'Attribute' mode
  183.                         }
  184.        
  185.                         //Set the attributes too.
  186.                         if (isset($attributes) and $get_attributes) {
  187.                                 foreach ($attributes as $attr => $val) {
  188.                                         if ($priority == 'tag')
  189.                                                 $attributes_data[$attr] = $val;
  190.                                         else
  191.                                                 $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr'
  192.                                 }
  193.                         }
  194.        
  195.                         //See tag status and do the needed.
  196.                         if ($type == "open") {//The starting of the tag '<tag>'
  197.                                 $parent[$level - 1] = &$current;
  198.                                 if (!is_array($current) or (!in_array($tag, array_keys($current)))) { //Insert New tag
  199.                                         $current[$tag] = $result;
  200.                                         if ($attributes_data)
  201.                                                 $current[$tag . '_attr'] = $attributes_data;
  202.                                         $repeated_tag_index[$tag . '_' . $level] = 1;
  203.        
  204.                                         $current = &$current[$tag];
  205.                                 } else { //There was another element with the same tag name
  206.                                         if (isset($current[$tag][0])) {//If there is a 0th element it is already an array
  207.                                                 $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
  208.                                                 $repeated_tag_index[$tag . '_' . $level]++;
  209.                                         } else {//This section will make the value an array if multiple tags with the same name appear together
  210.                                                 $current[$tag] = array($current[$tag], $result); //This will combine the existing item and the new item together to make an array
  211.                                                 $repeated_tag_index[$tag . '_' . $level] = 2;
  212.        
  213.                                                 if (isset($current[$tag . '_attr'])) { //The attribute of the last(0th) tag must be moved as well
  214.                                                         $current[$tag]['0_attr'] = $current[$tag . '_attr'];
  215.                                                         unset($current[$tag . '_attr']);
  216.                                                 }
  217.                                         }
  218.                                         $last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1;
  219.                                         $current = &$current[$tag][$last_item_index];
  220.                                 }
  221.                         } elseif ($type == "complete") { //Tags that ends in 1 line '<tag />'
  222.                                 //See if the key is already taken.
  223.                                 if (!isset($current[$tag])) { //New Key
  224.                                         $current[$tag] = $result;
  225.                                         $repeated_tag_index[$tag . '_' . $level] = 1;
  226.                                         if ($priority == 'tag' and $attributes_data)
  227.                                                 $current[$tag . '_attr'] = $attributes_data;
  228.                                 } else { //If taken, put all things inside a list(array)
  229.                                         if (isset($current[$tag][0]) and is_array($current[$tag])) {//If it is already an array
  230.                                                 // push the new element into that array.
  231.                                                 $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
  232.        
  233.                                                 if ($priority == 'tag' and $get_attributes and $attributes_data) {
  234.                                                         $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
  235.                                                 }
  236.                                                 $repeated_tag_index[$tag . '_' . $level]++;
  237.                                         } else { //If it is not an array
  238.                                                 $current[$tag] = array($current[$tag], $result); //Make it an array using using the existing value and the new value
  239.                                                 $repeated_tag_index[$tag . '_' . $level] = 1;
  240.                                                 if ($priority == 'tag' and $get_attributes) {
  241.                                                         if (isset($current[$tag . '_attr'])) { //The attribute of the last(0th) tag must be moved as well
  242.                                                                 $current[$tag]['0_attr'] = $current[$tag . '_attr'];
  243.                                                                 unset($current[$tag . '_attr']);
  244.                                                         }
  245.        
  246.                                                         if ($attributes_data) {
  247.                                                                 $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
  248.                                                         }
  249.                                                 }
  250.                                                 $repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken
  251.                                         }
  252.                                 }
  253.                         } elseif ($type == 'close') { //End of tag '</tag>'
  254.                                 $current = &$parent[$level - 1];
  255.                         }
  256.                 }
  257.        
  258.                 return($xml_array);
  259.         }
  260.        
  261.         public function ComputeSignature($args)
  262.     {
  263.                 //var_dump($args);
  264.         $login =                $args[0]; // Login du compte WS Dispatcher fourni par support OxIDString  $key =                $args[1]; // Clé du compte WSDispatcher
  265.         $key   =        $args[1];
  266.         $clientApp =    $args[2]; // Nom de l'application cliente déclaré dans LDAP partner puis géré dans PERMIT
  267.         $wsName =               $args[3]; // WS Cible déclaré dans UDDI
  268.         $wsApp =                (count($args) > 4)?$args[4]:"BUXY";     // l'application Serveur dans UDDI
  269.         $wsVersion =    (count($args) > 5)?$args[5]:"1.0";      // version du WS dans UDDI
  270.         $wsDomain =         (count($args) > 6)?$args[6]:"CASH"; // domaine du WS dans UDDI
  271.         $sb=array();
  272.         $sb['login']    = $login;
  273.         $sb['clientApp']= $clientApp;
  274.         $sb['wsName']   = $wsName;
  275.         $sb['wsApp']    = $wsApp;
  276.         $sb['wsVersion']= $wsVersion;
  277.         $sb['wsDomain'] = $wsDomain;
  278.         $sb['key']      = $key;
  279.         $sb['time']     = $this->getUTCTimeStamp();
  280.  
  281.                 $str=implode("",$sb);
  282.                 $signature=md5($str);
  283. //              echo("<br>LOGIN> .............. " . $login);
  284. //              echo("<br>WSDISPATCHER_KEY> ... " . $key);
  285. //              echo("<br>CLIENT_APP> ......... " . $clientApp);
  286. //              echo("<br>WS_NAME> ............ " . $wsName);
  287. //              echo("<br>WS_APP> ............. " . $wsApp);
  288. //              echo("<br>WS_VERSION> ......... " . $wsVersion);
  289. //              echo("<br>WS_DOMAIN> .......... " . $wsDomain);
  290. //              echo("<br>-----------------------");
  291. //              echo("<br>SIGNATURE> .......... " . $signature);
  292.         return $signature;
  293.  
  294.  
  295.     }
  296.     public function getUTCTimeStamp()
  297.     {
  298.                 //date_default_timezone_set('Asia/Shanghai');
  299.                 date_default_timezone_set('UTC');
  300.                 $NB_DAY_IN_YEAR = 365.25;
  301.                 $NB_MONTH_IN_YEAR = 12;
  302.                 $NB_HOUR_IN_DAY = 24;
  303.                 $NB_MINUTES_IN_HOUR = 60;
  304.                 $year = date('Y');
  305.                 $month = date('m');
  306.                 $day = date('d');
  307.                 $hour = date('H');
  308.                 $min = date('i');
  309.                 // Compute time stamp (minutes)
  310.                 $timestamp = $year * $NB_DAY_IN_YEAR * $NB_HOUR_IN_DAY * $NB_MINUTES_IN_HOUR
  311.                 + $month * ($NB_DAY_IN_YEAR/$NB_MONTH_IN_YEAR) * $NB_HOUR_IN_DAY *
  312.                 $NB_MINUTES_IN_HOUR
  313.                 + $day * $NB_HOUR_IN_DAY *$NB_MINUTES_IN_HOUR
  314.                 + $hour * $NB_MINUTES_IN_HOUR
  315.                 + $min;
  316.                 return $timestamp;
  317.  
  318.     }
  319.        
  320.        
  321.         public function pingOperation($data=array('operation'=>'test')){
  322.                 $body = '<urn:pingOperation>
  323.         <urn:operation>'.$data['operation'].'</urn:operation>
  324.      </urn:pingOperation>';
  325.                 return $this->soapService($body);
  326.         }
  327.         public function getGiftCardInfo($data){
  328.                 $body = '<urn:getGiftCardInfo>
  329.         <urn:voGiftCardInfoRequest>
  330.            <data:cardNumber>'.$data['cardNumber'].'</data:cardNumber>
  331.            <data:currency>'.$data['currency'].'</data:currency>
  332.            <data:language>'.$data['language'].'</data:language>
  333.            <data:merchantId>'.$data['merchantId'].'</data:merchantId>
  334.            <data:subThirdNumber>'.$data['subThirdNumber'].'</data:subThirdNumber>
  335.            <data:thirdNumber>'.$data['thirdNumber'].'</data:thirdNumber>
  336.            <data:thirdTypeNumber>'.$data['thirdTypeNumber'].'</data:thirdTypeNumber>
  337.            <data:eanCode>'.$data['eanCode'].'</data:eanCode>
  338.         </urn:voGiftCardInfoRequest>
  339.      </urn:getGiftCardInfo>';
  340.                 return $this->soapService($body);
  341.         }
  342.         public function getGiftcardHistory($data){
  343.                 $body = '<urn:getGiftcardHistory>
  344.         <urn:voGiftCardHistoryRequest>
  345.            <data:cardNumber>'.$data['cardNumber'].'</data:cardNumber>
  346.            <data:currency>'.$data['currency'].'</data:currency>
  347.            <data:language>'.$data['language'].'</data:language>
  348.            <data:merchantId>'.$data['merchantId'].'</data:merchantId>
  349.         </urn:voGiftCardHistoryRequest>
  350.      </urn:getGiftcardHistory>';
  351.                 return $this->soapService($body);
  352.         }
  353.         public function getInfoPromo($data){
  354.                 $body='<urn:getInfoPromo>
  355.         <urn:infoPromoRequest>
  356.            <data:amountMax>?</data:amountMax>
  357.            <data:amountMin>?</data:amountMin>
  358.            <data:cardType>?</data:cardType>
  359.            <data:code>?</data:code>
  360.            <data:consortiumId>?</data:consortiumId>
  361.            <data:consortiumName>?</data:consortiumName>
  362.            <data:creationDate>?</data:creationDate>
  363.            <data:currencyCode>?</data:currencyCode>
  364.            <data:email1>?</data:email1>
  365.            <data:email2>?</data:email2>
  366.            <data:expirationDate>?</data:expirationDate>
  367.            <data:itemCode>?</data:itemCode>
  368.            <data:maxActivationsNumber>?</data:maxActivationsNumber>
  369.            <data:name>?</data:name>
  370.            <data:supportPaiementCode>?</data:supportPaiementCode>
  371.            <data:useTank>?</data:useTank>
  372.            <data:validityPeriod>?</data:validityPeriod>
  373.         </urn:infoPromoRequest>
  374.      </urn:getInfoPromo>';
  375.                 return $this->soapService($body);
  376.         }
  377.         public function getBatchStatus($data){
  378.                 $body='<urn:getBatchStatus>
  379.         <urn:batchStatus>
  380.            <data:requestNumber>?</data:requestNumber>
  381.            <data:merchantId>?</data:merchantId>
  382.            <data:merchantType>?</data:merchantType>
  383.            <data:requestCode>?</data:requestCode>
  384.            <data:requestDate>?</data:requestDate>
  385.            <data:appCode>?</data:appCode>
  386.            <data:login>?</data:login>
  387.            <data:answerDate>?</data:answerDate>
  388.            <data:sendingDate>?</data:sendingDate>
  389.            <data:reference>?</data:reference>
  390.            <data:freeLabelRefer>?</data:freeLabelRefer>
  391.            <data:batchStatus>?</data:batchStatus>
  392.            <data:batchType>?</data:batchType>
  393.            <data:batchStatusDetails>
  394.               <!--Zero or more repetitions:-->
  395.               <urn:item>
  396.                  <data:requestNumber>?</data:requestNumber>
  397.                  <data:cardNumber>?</data:cardNumber>
  398.                  <data:responseCode>?</data:responseCode>
  399.               </urn:item>
  400.            </data:batchStatusDetails>
  401.         </urn:batchStatus>
  402.      </urn:getBatchStatus>';
  403.                 return $this->soapService($body);
  404.         }
  405.         public function requestBatch($data){
  406.                 $body='';
  407.                 return $this->soapService($body);
  408.         }
  409.         public function actionOnGiftCard($data){
  410.                 $body='
  411.      <urn:actionOnGiftCard>
  412.         <urn:actionOnGiftCard>
  413.            <data:amount>1500</data:amount>
  414.            <data:cardNumber>7777005561694543</data:cardNumber>
  415.            <data:cardType>36</data:cardType>
  416.            <data:cashierNumber>321</data:cashierNumber>
  417.            <data:currency>978</data:currency>
  418.            <data:language>FR</data:language>
  419.            <data:merchantId>97140000001</data:merchantId>
  420.            <data:requestCode>0802</data:requestCode>
  421.            <data:subThirdNumber>118</data:subThirdNumber>
  422.            <data:thirdNumber>118</data:thirdNumber>
  423.            <data:thirdTypeNumber>7</data:thirdTypeNumber>
  424.            <data:tillNumber>5</data:tillNumber>
  425.            <data:transactionNumber>12</data:transactionNumber>
  426.         </urn:actionOnGiftCard>
  427.      </urn:actionOnGiftCard>';
  428.                 return $this->soapService($body);
  429.  
  430.         }
  431.        
  432.         public function requestGiftCards($data){
  433.                 $body='<urn:requestGiftCards>
  434.         <urn:requestGiftCards>
  435.            <data:author>?</data:author>
  436.            <data:freeLabelReference>?</data:freeLabelReference>
  437.            <data:promoCode>?</data:promoCode>
  438.            <data:quantity>?</data:quantity>
  439.            <data:reference>?</data:reference>
  440.         </urn:requestGiftCards>
  441.      </urn:requestGiftCards>';
  442.                 return $this->soapService($body);
  443.  
  444.         }
  445.         //....其他方法
  446.        
  447.  
  448. }
  449.  
  450.  
  451. $oxylaneSoap = new oxylaneSoap();
  452. $oxylaneSoap->gwUrl  = 'http://preprodid.oxylane.com/wsdispatcher/wsgiftcard.ws';
  453. $oxylaneSoap->CFG    = array("LOGIN","KEY","LOGIN","WSGiftCard","GIFTCA","2.1.0","CASH");
  454. $oxylaneSoap->debug  = true;
  455. $oxylaneSoap->logdir = dirname(__FILE__).'/log/';
  456.  
  457. //PING操作
  458. $result = $oxylaneSoap->pingOperation();
  459. echo '<br>Result:<textarea style="width:100%;height:300px">';
  460. print_r($result);
  461. echo '</textarea>';
  462.  
  463.  
  464. //获取cardInfo
  465. $data=array(
  466. 'cardNumber'=>'7777017217539199',
  467. 'currency'=>'978',
  468. 'language'=>'FR',
  469. 'merchantId'=>'97093500007',
  470. 'subThirdNumber'=>'118',
  471. 'thirdNumber'=>'118',
  472. 'thirdTypeNumber'=>'7',
  473. 'eanCode'=>'',
  474. );
  475. $result = $oxylaneSoap->getGiftCardInfo($data);
  476. echo '<br>Result:<textarea style="width:100%;height:300px">';
  477. print_r($result);
  478. echo '</textarea>';
  479.  
  480. //获取GiftcardHistory
  481. $data=array(
  482. 'cardNumber'=>'7777017217539199',
  483. 'currency'=>'978',
  484. 'language'=>'FR',
  485. 'merchantId'=>'97093500007',
  486. );
  487. $result = $oxylaneSoap->getGiftcardHistory($data);
  488. echo '<br>Result:<textarea style="width:100%;height:300px">';
  489. print_r($result);
  490. echo '</textarea>';

Reply to "Use crul to access the soap server and automatically convert XML into an array, with the tonal logging function"

Here you can reply to the paste above

'; $result = $this->vcurlsoap($this->gwUrl,$xml,''); // $result = $this->req($this->gwUrl, $data, $func); if($this->debug) echo __FILE__.':'.__LINE__.' '.__FUNCTION__.' '.date('Y-m-d H:i:s').'
'; if($this->debug) echo '
'; if($this->logdir){ $logfile = $this->logdir.'/log_api_'.date('Y-m-d_H_i_s').'_post.xml'; file_put_contents($logfile,$xml); file_put_contents(str_replace('_post','_result',$logfile),$result); } return $this->xml2array($result); } public function xml($body){ $SIGNATURE=$this->ComputeSignature($this->CFG); $xml =' '.$this->CFG[0].' '.$SIGNATURE.' '.$this->CFG[2].' '.$this->CFG[3].' '.$this->CFG[4].' '.$this->CFG[5].' '.$this->CFG[6].' '.$body.' '; return $xml; } public function vcurl($url, $post = '', $cookie = '', $cookiejar = '', $referer = ''){ $tmpInfo = ''; //用来存放cookie的文件 $cookiepath = getcwd().'./'.$cookiejar; //初始化curl $curl = curl_init(); //设定目标网址 curl_setopt($curl, CURLOPT_URL, $url); //使用目前所用的浏览器代理 curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); //curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"); //如果有Ref参数,则设置Referer头,否则自动设置Referer头 if($referer) { curl_setopt($curl, CURLOPT_REFERER, $referer); } else { curl_setopt($curl, CURLOPT_AUTOREFERER, 1); } //如果有post数据参数,则方法为POST,并且设置数据,否则为GET if($post) { //发送一个常规的POST请求,默认类型为:application/x-www-form-urlencoded,表单提交 curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $post); } //如果有cookie参数,则设置 if($cookie) { curl_setopt($curl, CURLOPT_COOKIE, $cookie); } //如果有cookie文件参数,则设置存取Cookie文件名 if($cookiejar) { curl_setopt($curl, CURLOPT_COOKIEJAR, $cookiepath); curl_setopt($curl, CURLOPT_COOKIEFILE, $cookiepath); } //如果是302转移,则返回转移后的网址及内容 curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); //设置执行的最大秒数 curl_setopt($curl, CURLOPT_TIMEOUT, 100); //返回内容中是否包含头信息 curl_setopt($curl, CURLOPT_HEADER, 0); //把返回的结果存在文件或者变量中,而不是直接显示在浏览器 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //执行函数后的返回结果 $tmpInfo = curl_exec($curl); //如果出错,显示错误信息 if (curl_errno($curl)) { $tmpInfo = '
错误:
'.curl_error($curl); } //关闭curl对象 curl_close($curl); //返回结果 return $tmpInfo; } public function vcurlsoap($url, $SoapRequest, $SoapAction) { $ch = curl_init (); //initiate the curl session curl_setopt ( $ch, CURLOPT_URL, $url ); //set to url to post to curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 ); // return data in a variable curl_setopt ( $ch, CURLOPT_HEADER, 0 ); curl_setopt ( $ch, CURLOPT_POST, 1 ); curl_setopt ( $ch, CURLOPT_POSTFIELDS, $SoapRequest ); // post the xml curl_setopt ( $ch, CURLOPT_TIMEOUT, 200 ); // set timeout in seconds curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, 0 ); $header = array ("Content-Type: text/xml" ); $header [] = "Content-Length: ".strlen($SoapRequest); if (! is_null ( $SoapAction )) $header [] = 'SOAPAction: "' . $SoapAction . '"'; curl_setopt ( $ch, CURLOPT_HTTPHEADER, $header ); $xmlResponse = curl_exec ( $ch ); curl_close ( $ch ); return $xmlResponse; } /** * xml转换成数组 * @param type $contents * @param type $get_attributes * @param type $priority * @return type */ public function xml2array($contents, $get_attributes=1, $priority = 'tag') { if (!$contents) return array(); if (!function_exists('xml_parser_create')) { //print "'xml_parser_create()' function not found!"; return array(); } //Get the XML parser of PHP - PHP must have this module for the parser to work $parser = xml_parser_create(''); xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8"); # http://minutillo.com/steve/weblog/2004/6/17/php-xml-and-character-encodings-a-tale-of-sadness-rage-and-data-loss xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); xml_parse_into_struct($parser, trim($contents), $xml_values); xml_parser_free($parser); if (!$xml_values) return; //Hmm //Initializations $xml_array = array(); $parents = array(); $opened_tags = array(); $arr = array(); $current = &$xml_array; //Refference //Go through the tags. $repeated_tag_index = array(); //Multiple tags with same name will be turned into an array foreach ($xml_values as $data) { unset($attributes, $value); //Remove existing values, or there will be trouble //This command will extract these variables into the foreach scope // tag(string), type(string), level(int), attributes(array). extract($data); //We could use the array by itself, but this cooler. $result = array(); $attributes_data = array(); if (isset($value)) { if ($priority == 'tag') $result = $value; else $result['value'] = $value; //Put the value in a assoc array if we are in the 'Attribute' mode } //Set the attributes too. if (isset($attributes) and $get_attributes) { foreach ($attributes as $attr => $val) { if ($priority == 'tag') $attributes_data[$attr] = $val; else $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr' } } //See tag status and do the needed. if ($type == "open") {//The starting of the tag '' $parent[$level - 1] = &$current; if (!is_array($current) or (!in_array($tag, array_keys($current)))) { //Insert New tag $current[$tag] = $result; if ($attributes_data) $current[$tag . '_attr'] = $attributes_data; $repeated_tag_index[$tag . '_' . $level] = 1; $current = &$current[$tag]; } else { //There was another element with the same tag name if (isset($current[$tag][0])) {//If there is a 0th element it is already an array $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result; $repeated_tag_index[$tag . '_' . $level]++; } else {//This section will make the value an array if multiple tags with the same name appear together $current[$tag] = array($current[$tag], $result); //This will combine the existing item and the new item together to make an array $repeated_tag_index[$tag . '_' . $level] = 2; if (isset($current[$tag . '_attr'])) { //The attribute of the last(0th) tag must be moved as well $current[$tag]['0_attr'] = $current[$tag . '_attr']; unset($current[$tag . '_attr']); } } $last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1; $current = &$current[$tag][$last_item_index]; } } elseif ($type == "complete") { //Tags that ends in 1 line '' //See if the key is already taken. if (!isset($current[$tag])) { //New Key $current[$tag] = $result; $repeated_tag_index[$tag . '_' . $level] = 1; if ($priority == 'tag' and $attributes_data) $current[$tag . '_attr'] = $attributes_data; } else { //If taken, put all things inside a list(array) if (isset($current[$tag][0]) and is_array($current[$tag])) {//If it is already an array // push the new element into that array. $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result; if ($priority == 'tag' and $get_attributes and $attributes_data) { $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data; } $repeated_tag_index[$tag . '_' . $level]++; } else { //If it is not an array $current[$tag] = array($current[$tag], $result); //Make it an array using using the existing value and the new value $repeated_tag_index[$tag . '_' . $level] = 1; if ($priority == 'tag' and $get_attributes) { if (isset($current[$tag . '_attr'])) { //The attribute of the last(0th) tag must be moved as well $current[$tag]['0_attr'] = $current[$tag . '_attr']; unset($current[$tag . '_attr']); } if ($attributes_data) { $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data; } } $repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken } } } elseif ($type == 'close') { //End of tag '' $current = &$parent[$level - 1]; } } return($xml_array); } public function ComputeSignature($args) { //var_dump($args); $login = $args[0]; // Login du compte WS Dispatcher fourni par support OxIDString $key = $args[1]; // Clé du compte WSDispatcher $key = $args[1]; $clientApp = $args[2]; // Nom de l'application cliente déclaré dans LDAP partner puis géré dans PERMIT $wsName = $args[3]; // WS Cible déclaré dans UDDI $wsApp = (count($args) > 4)?$args[4]:"BUXY"; // l'application Serveur dans UDDI $wsVersion = (count($args) > 5)?$args[5]:"1.0"; // version du WS dans UDDI $wsDomain = (count($args) > 6)?$args[6]:"CASH"; // domaine du WS dans UDDI $sb=array(); $sb['login'] = $login; $sb['clientApp']= $clientApp; $sb['wsName'] = $wsName; $sb['wsApp'] = $wsApp; $sb['wsVersion']= $wsVersion; $sb['wsDomain'] = $wsDomain; $sb['key'] = $key; $sb['time'] = $this->getUTCTimeStamp(); $str=implode("",$sb); $signature=md5($str); // echo("
LOGIN> .............. " . $login); // echo("
WSDISPATCHER_KEY> ... " . $key); // echo("
CLIENT_APP> ......... " . $clientApp); // echo("
WS_NAME> ............ " . $wsName); // echo("
WS_APP> ............. " . $wsApp); // echo("
WS_VERSION> ......... " . $wsVersion); // echo("
WS_DOMAIN> .......... " . $wsDomain); // echo("
-----------------------"); // echo("
SIGNATURE> .......... " . $signature); return $signature; } public function getUTCTimeStamp() { //date_default_timezone_set('Asia/Shanghai'); date_default_timezone_set('UTC'); $NB_DAY_IN_YEAR = 365.25; $NB_MONTH_IN_YEAR = 12; $NB_HOUR_IN_DAY = 24; $NB_MINUTES_IN_HOUR = 60; $year = date('Y'); $month = date('m'); $day = date('d'); $hour = date('H'); $min = date('i'); // Compute time stamp (minutes) $timestamp = $year * $NB_DAY_IN_YEAR * $NB_HOUR_IN_DAY * $NB_MINUTES_IN_HOUR + $month * ($NB_DAY_IN_YEAR/$NB_MONTH_IN_YEAR) * $NB_HOUR_IN_DAY * $NB_MINUTES_IN_HOUR + $day * $NB_HOUR_IN_DAY *$NB_MINUTES_IN_HOUR + $hour * $NB_MINUTES_IN_HOUR + $min; return $timestamp; } public function pingOperation($data=array('operation'=>'test')){ $body = ' '.$data['operation'].' '; return $this->soapService($body); } public function getGiftCardInfo($data){ $body = ' '.$data['cardNumber'].' '.$data['currency'].' '.$data['language'].' '.$data['merchantId'].' '.$data['subThirdNumber'].' '.$data['thirdNumber'].' '.$data['thirdTypeNumber'].' '.$data['eanCode'].' '; return $this->soapService($body); } public function getGiftcardHistory($data){ $body = ' '.$data['cardNumber'].' '.$data['currency'].' '.$data['language'].' '.$data['merchantId'].' '; return $this->soapService($body); } public function getInfoPromo($data){ $body=' ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? '; return $this->soapService($body); } public function getBatchStatus($data){ $body=' ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? '; return $this->soapService($body); } public function requestBatch($data){ $body=''; return $this->soapService($body); } public function actionOnGiftCard($data){ $body=' 1500 7777005561694543 36 321 978 FR 97140000001 0802 118 118 7 5 12 '; return $this->soapService($body); } public function requestGiftCards($data){ $body=' ? ? ? ? ? '; return $this->soapService($body); } //....其他方法 } $oxylaneSoap = new oxylaneSoap(); $oxylaneSoap->gwUrl = 'http://preprodid.oxylane.com/wsdispatcher/wsgiftcard.ws'; $oxylaneSoap->CFG = array("LOGIN","KEY","LOGIN","WSGiftCard","GIFTCA","2.1.0","CASH"); $oxylaneSoap->debug = true; $oxylaneSoap->logdir = dirname(__FILE__).'/log/'; //PING操作 $result = $oxylaneSoap->pingOperation(); echo '
Result:'; //获取cardInfo $data=array( 'cardNumber'=>'7777017217539199', 'currency'=>'978', 'language'=>'FR', 'merchantId'=>'97093500007', 'subThirdNumber'=>'118', 'thirdNumber'=>'118', 'thirdTypeNumber'=>'7', 'eanCode'=>'', ); $result = $oxylaneSoap->getGiftCardInfo($data); echo '
Result:'; //获取GiftcardHistory $data=array( 'cardNumber'=>'7777017217539199', 'currency'=>'978', 'language'=>'FR', 'merchantId'=>'97093500007', ); $result = $oxylaneSoap->getGiftcardHistory($data); echo '
Result:';
captcha

https://burned.cc - Burn After Reading Website