1. 程式人生 > 實用技巧 >PHP 使用soap呼叫webservice介面

PHP 使用soap呼叫webservice介面

        header("content-type:text/html;charset=utf-8");
        try {
            $client = new SoapClient("http://xxx?wsdl"
            );
//            print_r($client->__getFunctions());
//            print_r($client->__getTypes());
            $customerCode = 'wwggr';
            $sign = Md5(date
('Ymd',time()).$customerCode); $param = array( 'factoryCode' => '1244', .... 'product'=>['quantity'=>1,'sku'=>'4D5100126005'], .... ); $param = json_encode($param,JSON_UNESCAPED_UNICODE);
print_r($param); // die; // $result = $client->__soapCall('AddOEMOrder',array("parameters"=>$param)); $result = $client->AddOEMOrder(['model'=>$param]); //print_r($result); //將stdclass object的$result轉換為array $result = get_object_vars
($result); //輸出結果 echo $result["AddOEMOrderResult"]; } catch (SOAPFault $e) { print $e; }

伺服器無法處理請求。 ---> 值不能為 null。
引數名: value

1.傳入的引數為空

通過列印print_r($client->__getFunctions());print_r($client->__getTypes());得知呼叫AddOEMOrder 函式需要傳入string型別的model變數,如果沒有傳入model變數則會出現上述問題

Array
(
    [0] => AddOEMOrderResponse AddOEMOrder(AddOEMOrder $parameters)
    [1] => AddOEMOrderResponse AddOEMOrder(AddOEMOrder     $parameters)
)
Array
(
    [0] => struct AddOEMOrder {
        string model;
    }
    [1] => struct AddOEMOrderResponse {
        string AddOEMOrderResult;
    }
)        

例如:$result = $client->AddOEMOrder(['model'=>$param]); 是呼叫成功的,

  而$result = $client->AddOEMOrder(['modl'=>$param]);則會出現上述問題