WordPress中针对联邦快递收件请求的SOAP请求

时间:2016-09-02 作者:rudtek

我正试图为wordpress网站创建一个联邦快递取货请求。当我在wordpress之外创建代码时,api和工具运行良好,但当我将相同的代码放入wordpress时,我得到的错误是

警告:非法字符串偏移量“警告:在/home/xd/public\\u html/test/wp-content/themes/dev/template-pickup-confirm中非法字符串偏移量“WebAuthenticationDetail”。php第33行注意:数组到字符串转换in/home/xd/public\\u html/test/wp content/themes/dev/template pickup confirm。php在线33

需要4个文件:pickupform。php(发布到pickup request.php的表单)pickup request。php(处理soap)联邦快递通用。php(处理常见的联邦快递功能,以防我使用其他联邦快递工具,如评级、发货、退款或取消)PickupService\\u v13。wsdl。(联邦快递webservices图书馆)

我将两个主要的php表单嵌入到wordpress的模板中。

我在(pickupform.php)one上填写表单,它会发布到取货请求。php

所以它以pickuprequest的形式停在这一行:

$request[\'WebAuthenticationDetail\'] = array(
    \'ParentCredential\' => array(
        \'Key\' => getProperty(\'parentkey\'),
        \'Password\' => getProperty(\'parentpassword\')
    ),
    \'UserCredential\' => array(
        \'Key\' => getProperty(\'key\'), 
        \'Password\' => getProperty(\'password\')
    )
);
其中getProperty()在fedexcommon中引用此函数。php:

function getProperty($var){

  if($var == \'key\') Return \'vB12a89Q25xwv\'; 
    if($var == \'password\') Return \'FFAz8EEYEEfEZufZxu4pJc\'; 
    if($var == \'shipaccount\') Return \'510087\';
    if($var == \'billaccount\') Return \'510087\';
    if($var == \'dutyaccount\') Return \'XXX\'; 
    if($var == \'freightaccount\') Return \'XXX\';  
    if($var == \'trackaccount\') Return \'XXX\'; 
    if($var == \'dutiesaccount\') Return \'XXX\';
    if($var == \'importeraccount\') Return \'XXX\';
    if($var == \'brokeraccount\') Return \'XXX\';
    if($var == \'distributionaccount\') Return \'XXX\';
    if($var == \'locationid\') Return \'PLBA\';
    if($var == \'printlabels\') Return true;
    if($var == \'printdocuments\') Return true;
    if($var == \'packagecount\') Return \'4\';
    if($var == \'validateaccount\') Return \'XXX\';
    if($var == \'meter\') Return \'118593060\';
);
    }
因此,wordpress似乎出于某种原因不知道或没有将WebAuthenticationDetail更改为数组?

对于wordpress数组,是否应该以不同的方式编写代码?

或者这需要写在插件中吗?

应以下要求添加其他代码:

require_once(\'library/fedex-common.php5\');

//The WSDL is not included with the sample code.
//Please include and reference in $path_to_wsdl variable.
$path_to_wsdl = "wsdl/PickupService_v13.wsdl";

ini_set("soap.wsdl_cache_enabled", "0");

$client = new SoapClient($path_to_wsdl, array(\'trace\' => 1)); // Refer to http://us3.php.net/manual/en/ref.soap.php for more information
date_default_timezone_set(\'America/Los_Angeles\');
$cdate = $_POST["txtPickupDate"]. " ". $_POST["txtPickupTime"];
$datetime = new DateTime($cdate);
$tdate = $datetime->format(\'c\');

$request[\'WebAuthenticationDetail\'] = array(   //LINE 33
    \'ParentCredential\' => array(
        \'Key\' => getProperty(\'parentkey\'),
        \'Password\' => getProperty(\'parentpassword\')
    ),
    \'UserCredential\' => array(
        \'Key\' => getProperty(\'key\'), 
        \'Password\' => getProperty(\'password\')
    )
);
$request[\'ClientDetail\'] = array(
    \'AccountNumber\' => getProperty(\'shipaccount\'), 
    \'MeterNumber\' => getProperty(\'meter\')
);
$request[\'TransactionDetail\'] = array(\'CustomerTransactionId\' => \'*** Create Pickup Request using PHP ***\');
$request[\'Version\'] = array(
    \'ServiceId\' => \'disp\', 
    \'Major\' => 13, 
    \'Intermediate\' => 0, 
    \'Minor\' => 0
);
$request[\'OriginDetail\'] = array(
    \'PickupLocation\' => array(
        \'Contact\' => array(
            \'PersonName\' => $_POST["txtFromName"],
            \'CompanyName\' => \'\',
            \'PhoneNumber\' => $_POST["txtFromPhone"]
        ),
        \'Address\' => array(
            \'StreetLines\' => array($_POST["txtFromAddress1"]),
            \'City\' => $_POST["txtFromCity"],
            \'StateOrProvinceCode\' => $_POST["txtFromState"],
            \'PostalCode\' => $_POST["txtFromZip"],
            \'CountryCode\' => \'US\')
        ),
    \'PackageLocation\' => $_POST["selPickupPoint"], // valid values NONE, FRONT, REAR and SIDE
    \'BuildingPartCode\' => \'\', // valid values APARTMENT, BUILDING, DEPARTMENT, SUITE, FLOOR and ROOM
    \'BuildingPartDescription\' => $_POST["txtFromAddress1"],
    \'ReadyTimestamp\' => $tdate, // Replace with your ready date time
    \'CompanyCloseTime\' => $_POST["txtCloseTime"]
);
$request[\'PackageCount\'] = $_POST["txtPackageCount"];
$request[\'TotalWeight\'] = array(
    \'Value\' => $_POST["txtTPackWeight"], 
    \'Units\' => \'LB\' // valid values LB and KG
); 
$request[\'CarrierCode\'] = \'FDXE\'; // valid values FDXE-Express, FDXG-Ground, FDXC-Cargo, FXCC-Custom Critical and FXFR-Freight
//$request[\'OversizePackageCount\'] = \'0\';
$request[\'CourierRemarks\'] = \'This is a test.  Do not pickup\';

1 个回复
最合适的回答,由SO网友:rudtek 整理而成

看起来这是我最初的设想。我把所有的代码都放进函数中,然后制作了一个插件,一切都很好。主要的障碍是,因为它是在两页纸上处理的,而外部功能wordpress似乎不知道它/我在做什么。

再次感谢@tomjnowell的尝试。我真的很感激。