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

Why am I Not receiving a notification when my FedEx package is delivered?

我正在使用 FedEx 网络服务和 jeremy-dunn/php-fedex-api-wrapper 并尝试让 FedEx 在包裹送达后向我发送纯文本电子邮件通知。我正在使用第三方来履行订单,他们拥有并使用不是我的另一个 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"
      }
    }
  }
}

看来我已经订阅了,我应该会在包裹送达时收到一封电子邮件通知,但电子邮件从未到达。所以我需要帮助来了解我的代码有什么问题,或者我正在做的事情有什么问题。我相信我明白我在做什么,但没有成功。

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

2) 我的代码和我得到的回复都很好。

3) 为不是通过我的帐户发送的包裹添加跟踪通知效果很好。添加曲目通知没有限制,但总共只能有 4 个。

https://www.fedex.com/us/developer/WebHelp/ws/2014/dvg/WS_DVG_WebHelp/26_Shipment_Notification_in_the_Ship_Request.htm

这里说在测试环境中收不到邮件