致命错误:未捕获错误:找不到类“SoapClient”

问题描述 投票:0回答:2

您好,我正在尝试使用适用于加拿大的 UPS API 进行构建。该文档非常粗糙,我很难理解它......

我的代码如下:

<?php

//Configuration
$outputFileName = "XOLTResult.xml";
$access = "XXXX";
$userid = "XXXX";
$passwd = 'XXXX';
$wsdl = file_get_contents("RateWS.WSDL");
$operation = "ProcessRate";
$endpointurl = 'https://wwwcie.ups.com/webservices/FreightRate';

//create soap request
$option['RequestOption'] = 'RateChecking Option';
$request['Request'] = $option;
$shipfrom['Name'] = 'Good Incorporation';
$addressFrom['AddressLine'] = '2010 WARSAW ROAD';
$addressFrom['City'] = 'Roswell';
$addressFrom['StateProvinceCode'] = 'GA';
$addressFrom['PostalCode'] = '30076';
$addressFrom['CountryCode'] = 'US';
$shipfrom['Address'] = $addressFrom;
$request['ShipFrom'] = $shipfrom;

$shipto['Name'] = 'Sony Company Incorporation';
$addressTo['AddressLine'] = '2311 YORK ROAD';
$addressTo['City'] = 'TIMONIUM';
$addressTo['StateProvinceCode'] = 'MD';
$addressTo['PostalCode'] = '21093';
$addressTo['CountryCode'] = 'US';
$shipto['Address'] = $addressTo;
$request['ShipTo'] = $shipto;

$payer['Name'] = 'Payer inc';
$addressPayer['AddressLine'] = '435 SOUTH STREET';
$addressPayer['City'] = 'RIS TOWNSHIP';
$addressPayer['StateProvinceCode'] = 'NJ';
$addressPayer['PostalCode'] = '07960';
$addressPayer['CountryCode'] = 'US';
$payer['Address'] = $addressPayer;
$shipmentbillingoption['Code'] = '10';
$shipmentbillingoption['Description'] = 'PREPAID';
$paymentinformation['Payer'] = $payer;
$paymentinformation['ShipmentBillingOption'] = $shipmentbillingoption;
$request['PaymentInformation'] = $paymentinformation;

$service['Code'] = '02';
$service['Description'] = '2nd Day Air';
$request['Service'] = $service;

$commodity['CommodityID'] = '';
$commodity['Description'] = 'No Description';
$commodity['Weight'] = array
(
   'UnitOfMeasurement' => array
   (
       'Code' => 'LBS',
       'Description' => 'Pounds'
   ),
   'Value' => '11'
);
$commodity['Dimensions'] = array
(
    'UnitOfMeasurement' => array
    (
        'Code' => 'IN',
        'Description' => 'Inches'
    ),
    'Length' => '23',
    'Width' => '17',
    'Height' => '45'
);
$commodity['NumberOfPieces'] = '1';
$commodity['DangerousGoodsIndicator'] = '';
$commodity['CommodityValue'] = array
(
     'CurrencyCode' => 'CAD',
     'MonetaryValue' => '500'
);
$request['Commodity'] = $commodity;

$shipmentserviceoptions['PickupOptions'] = array
    (
          'HolidayPickupIndicator' => '',
        'InsidePickupIndicator' => '',
      'ResidentialPickupIndicator' => '',
      'WeekendPickupIndicator' => '',
      'LiftGateRequiredIndicator' => ''
  );

try
{

  $mode = array
  (
       'soap_version' => 'SOAP_1_1',  // use soap 1.1 client
       'trace' => 1
  );

  // initialize soap client
  $client = new SoapClient($wsdl , $mode);

  //set endpoint url
  $client->__setLocation($endpointurl);


  //create soap header
  $usernameToken['Username'] = $userid;
  $usernameToken['Password'] = $passwd;
  $serviceAccessLicense['AccessLicenseNumber'] = $access;
  $upss['UsernameToken'] = $usernameToken;
  $upss['ServiceAccessToken'] = $serviceAccessLicense;

  $header = new SoapHeader('http://www.ups.com/XMLSchema/XOLTWS/UPSS/v1.0','UPSSecurity',$upss);
  $client->__setSoapHeaders($header);


  //get response
  $resp = $client->__soapCall($operation ,array(processFreightRate()));

  //get status
  echo "Response Status: " . $resp->Response->ResponseStatus->Description ."\n";

  //save soap request and response to file
  $fw = fopen($outputFileName , 'w');
  fwrite($fw , "Request: \n" . $client->__getLastRequest() . "\n");
  fwrite($fw , "Response: \n" . $client->__getLastResponse() . "\n");
  fclose($fw);

}
catch(Exception $ex)
{
  print_r ($ex);
}
?>

我收到以下错误:

致命错误:未捕获错误:在 C:\xampp\htdocs\upsapi\RatingPACKAGE\PACKAGEWebServices\CodeSamples\Rate\PHP\SoapRateClient.php:121 中找不到类“SoapClient”堆栈跟踪:#0 {main} thrown in C: \xampp\htdocs\upsapi\RatingPACKAGE\PACKAGEWebServices\CodeSamples\Rate\PHP\SoapRateClient.php 第 121 行

任何帮助将不胜感激。

soap 客户端似乎不在服务器上,但我相信这已经解决了

SoapFault 对象 ( [message:protected] => SOAP-ERROR: 解析 WSDL: 无法从 ' ' 加载:无法加载外部实体 " " [string:Exception:private] => [code:protected] => 0 [file:protected] => C:\xampp\htdocs\upsapi\ShippingPACKAGE\PACKAGEWebServices\CodeSamples\Ship\PHP\SoapShipClient.php [line:protected] => 185 [trace:Exception:private] => Array ( [0 ] => 数组 ( [文件] => C:\xampp\htdocs\upsapi\ShippingPACKAGE\PACKAGEWebServices\CodeSamples\Ship\PHP\SoapShipClient.php [行] => 185 [函数] => __construct [类] => SoapClient [type] => -> [args] => Array ( [0] => [1] => Array ( [soap_version] => SOAP_1_1 [trace] => 1 ) ) ) ) [previous:Exception:private] = > [faultstring] => SOAP-ERROR:解析 WSDL:无法从“”加载:无法加载外部实体“” [faultcode] => WSDL [faultcodens] => [faultactor] => [detail] => [ _name] => [headerfault] => )

php api soap
2个回答
1
投票

在 XAMPP 控制面板中

  1. 停止 Apache 服务器

  2. 点击 Apache 旁边的

    Config

  3. 从下拉列表中选择

    PHP (php.ini)

  4. Ctrl+F 查找

    ;extension=soap
    从行中删除
    ;

  5. Ctrl+S 保存文件。

  6. 再次启动Apache。

    扩展=肥皂


0
投票

我删除';'但不工作 在我重新启动 pc 和 apachi 但在 xamp、localhost 中还不能工作后

© www.soinside.com 2019 - 2024. All rights reserved.