zoukankan      html  css  js  c++  java
  • PHP处理SOAP

    1。获取functions

    try {
        $client = new SoapClient("http://www.fangbei.org/services/inquiryTracingAndOpcCode?wsdl");
        print_r($client->__getFunctions());
        print_r($client->__getTypes());  
    } catch (SOAPFault $e) {
        print $e;
    }

    返回

    Array
    (
        [0] => getTracingAndOpcCodeResponse getTracingAndOpcCode(getTracingAndOpcCode $parameters)
    )
    Array
    (
        [0] => struct tracingAndOpcCodeResult {
            string opcCode;
            string tracingNo;
        }
        [1] => struct getTracingAndOpcCode {
            string logisticCode;
        }
        [2] => struct getTracingAndOpcCodeResponse {
            tracingAndOpcCodeResult return;
        }
    )

    2. 调用接口

    $logisticCode = "3696116566481503";
    
    try {
        $client = new SoapClient('http://www.fangbei.org/services/inquiryTracingAndOpcCode?wsdl');
        $param = array("logisticCode"=>$logisticCode); 
        $result = $client->getTracingAndOpcCode($param);
        var_dump($result);
    
        if (isset($result->return->opcCode) || !empty($result->return->opcCode)){
            $opcCode = $result->return->opcCode;
            $tracingNo = $result->return->tracingNo;
            var_dump($opcCode);
            var_dump($tracingNo);
        }
        
        $new_logisticCode   = str_pad($logisticCode, 50, "0", STR_PAD_RIGHT);
        $new_opcCode        = str_pad($opcCode, 20, "0", STR_PAD_RIGHT);
        $new_tracingNo      = str_pad($tracingNo, 15, "0", STR_PAD_RIGHT);
        
        
        $data = array(  "trackno"       => $tracingNo,
                        "opccode"       => $opcCode,
                        "logisticscode" => $logisticCode,
                        "secret"       => md5($new_tracingNo.$new_opcCode.$new_logisticCode),
                        );
    
        $url = "http://wechat.fangbei.org/WeChat/WeChartInterface.ashx";
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        var_dump($output);
        $response = simplexml_load_string($output, 'SimpleXMLElement', LIBXML_NOCDATA);
        var_dump($response);
        var_dump($response->Response);
        
    } catch (SOAPFault $e) {
        print_r('Exception:'.$e);
    }
  • 相关阅读:
    回溯法---哈密顿回路(5)
    回溯法---n皇后问题(4)
    回溯法---n-着色问题(3)
    回溯法--算法框架(2)
    创建二叉树的所有深度上的节点链表
    笔试
    笔试 (2)
    LeetCode278-第一个错误的版本(二分查找)
    LeetCode46-全排列(递归)
    LeetCode258-各位相加(猜想公式)
  • 原文地址:https://www.cnblogs.com/txw1958/p/11148068.html
Copyright © 2011-2022 走看看