为什么我的FedEx包裹寄送时没有收到通知?

时间:2018-07-18 21:01:22

标签: php fedex

我正在使用FedEx Web服务和jeremy-dunn/php-fedex-api-wrapper,并试图在包裹交付时让FedEx向我发送纯文本电子邮件通知。我使用第三方来履行订单,他们拥有并使用了另一个不是我的联邦快递帐户。 (也许这是问题所在?)

我可以很好地跟踪包裹,当我尝试订阅传递通知时,FedEx的响应似乎表明成功。我处于测试模式。以防万一,我目前不处于生产模式。

我的请求使用以下功能:

function fedexWebServicesNotificationSubscription( $trackingNumber, $recipient, $sender )
{
    global $fedexApiMode;

    if( ! is_array( $recipient ) OR ! isset( $recipient['email_addr'] ) )
        return FALSE;

    if( ! is_array( $sender ) OR ! isset( $sender['email_addr'], $sender['name'] ) )
        return FALSE;

    $userCredential = new ComplexType\WebAuthenticationCredential();
    $userCredential->setKey(FEDEX_KEY)
        ->setPassword(FEDEX_PASSWORD);

    $webAuthenticationDetail = new ComplexType\WebAuthenticationDetail();
    $webAuthenticationDetail->setUserCredential($userCredential);

    $clientDetail = new ComplexType\ClientDetail();
    $clientDetail->setAccountNumber(FEDEX_ACCOUNT_NUMBER)
        ->setMeterNumber(FEDEX_METER_NUMBER);

    $version = new ComplexType\VersionId();
    $version->setMajor(5)
        ->setIntermediate(0)
        ->setMinor(0)
        ->setServiceId('trck');

    $localization  = new ComplexType\Localization();
    $localization->setLocaleCode("US")
        ->setLanguageCode("EN");

    $emailRecip = new ComplexType\EMailNotificationRecipient();
    $emailRecip->setEMailNotificationRecipientType(SimpleType\EMailNotificationRecipientType::_SHIPPER)
        ->setEMailAddress( $recipient['email_addr'] )
        ->setLocalization($localization)
        ->setFormat(SimpleType\EMailNotificationFormatType::_TEXT)
        ->setNotificationEventsRequested([
                SimpleType\EMailNotificationEventType::_ON_DELIVERY,
                SimpleType\EMailNotificationEventType::_ON_EXCEPTION,
                SimpleType\EMailNotificationEventType::_ON_SHIPMENT,
                SimpleType\EMailNotificationEventType::_ON_TENDER
            ]);

    $emailNotificationDetail = new ComplexType\EMailNotificationDetail();
    $emailNotificationDetail->setPersonalMessage('Shipment Status Notification')
        ->setRecipients([$emailRecip]);

    $request = new ComplexType\TrackNotificationRequest();
    $request->setWebAuthenticationDetail($webAuthenticationDetail)
        ->setClientDetail($clientDetail)
        ->setVersion($version)
        ->setTrackingNumber( $trackingNumber )
        ->setSenderEMailAddress( $sender['email_addr'] )
        ->setSenderContactName( $sender['name'] )
        ->setNotificationDetail($emailNotificationDetail);

    $trackServiceRequest = new TrackService\Request();
    if( $fedexApiMode == 'production' )
        $trackServiceRequest->getSoapClient()->__setLocation(TrackService\Request::PRODUCTION_URL);
    $response = $trackServiceRequest->getGetTrackNotificationReply($request, TRUE);

    return $response;
}

我这样使用该功能:

$trackingNumber = '781893213291';

$recipient = [
    'email_addr' => 'email@example.com'
];

$sender = [
    'email_addr' => 'email@example.com',
    'name'       => 'My Name'
];

$response = fedexWebServicesNotificationSubscription( $trackingNumber, $recipient, $sender );

echo '<pre>';
var_dump($response);
echo '</pre>';

我的回答如下:

object(stdClass)#28 (6) {
  ["HighestSeverity"]=>
  string(7) "SUCCESS"
  ["Notifications"]=>
  object(stdClass)#29 (5) {
    ["Severity"]=>
    string(7) "SUCCESS"
    ["Source"]=>
    string(4) "trck"
    ["Code"]=>
    string(1) "0"
    ["Message"]=>
    string(35) "Request was successfully processed."
    ["LocalizedMessage"]=>
    string(35) "Request was successfully processed."
  }
  ["Version"]=>
  object(stdClass)#30 (4) {
    ["ServiceId"]=>
    string(4) "trck"
    ["Major"]=>
    int(5)
    ["Intermediate"]=>
    int(0)
    ["Minor"]=>
    int(0)
  }
  ["DuplicateWaybill"]=>
  bool(false)
  ["MoreDataAvailable"]=>
  bool(false)
  ["Packages"]=>
  object(stdClass)#31 (6) {
    ["TrackingNumber"]=>
    string(12) "781893213291"
    ["TrackingNumberUniqueIdentifiers"]=>
    string(23) "12018~781893213291~FDEG"
    ["CarrierCode"]=>
    string(4) "FDXG"
    ["ShipDate"]=>
    string(10) "2018-07-17"
    ["Destination"]=>
    object(stdClass)#32 (4) {
      ["City"]=>
      string(13) "SAN FRANCISCO"
      ["StateOrProvinceCode"]=>
      string(2) "CA"
      ["CountryCode"]=>
      string(2) "US"
      ["Residential"]=>
      bool(false)
    }
    ["RecipientDetails"]=>
    object(stdClass)#33 (1) {
      ["NotificationEventsAvailable"]=>
      array(6) {
        [0]=>
        string(11) "ON_DELIVERY"
        [1]=>
        string(12) "ON_EXCEPTION"
        [2]=>
        string(12) "ON_EXCEPTION"
        [3]=>
        string(12) "ON_EXCEPTION"
        [4]=>
        string(12) "ON_EXCEPTION"
        [5]=>
        string(12) "ON_EXCEPTION"
      }
    }
  }
}

因此,我似乎已经订阅了,并且包裹交付时我应该收到一封电子邮件通知,但电子邮件从未到达。因此,我需要帮助来了解我的代码有什么问题,或我正在做的事情有什么问题。我相信我了解自己在做什么,但没有成功。

2 个答案:

答案 0 :(得分:0)

1)在测试模式下,不发送通知。使用生产密钥(生产模式),发送通知。这就是我所期望的。

2)我的代码和返回的响应都很好。

3)为未通过我的帐户发送的包裹添加跟踪通知就可以了。添加跟踪通知没有任何限制,除了可能总共只有4条。

答案 1 :(得分:0)