简体   繁体   English

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

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

I'm using FedEx web services and jeremy-dunn/php-fedex-api-wrapper and attempting to have FedEx send me a plaintext email notification when a package has been delivered. 我正在使用FedEx Web服务和jeremy-dunn / php-fedex-api-wrapper,并试图在包裹交付后让FedEx向我发送明文电子邮件通知。 I am using a third party for order fulfillment, and they have and use a different FedEx account that is not mine. 我使用第三方来履行订单,他们拥有并使用了另一个不是我的联邦快递帐户。 (Maybe this is the problem?) (也许这是问题吗?)

I can track the packages just fine, and when I attempt to subscribe to the delivery notification, the response from FedEx seems to indicate success. 我可以很好地跟踪包裹,当我尝试订阅传递通知时,FedEx的响应似乎表明成功。 I am in testing mode. 我处于测试模式。 I'm NOT currently in production mode, in case that matters. 以防万一,我目前不处于生产模式。

My request uses the following function: 我的请求使用以下功能:

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;
}

I use that function like this: 我这样使用该功能:

$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>';

And my response looks like this: 我的回答如下:

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"
      }
    }
  }
}

So it appears that I have subscribed, and that I should receive an email notification when the package is delivered, but the email never arrives. 看来我已经订阅了,并且包裹交付时我应该收到一封电子邮件通知,但是电子邮件从未到达。 So I need help to know what's wrong with my code, or what's wrong with what I'm doing. 因此,我需要帮助来了解我的代码有什么问题,或我正在做的事情有什么问题。 I believe I understand what I'm doing, but no success. 我相信我了解自己在做什么,但没有成功。

1) In test mode, notifications are not sent. 1)在测试模式下,不发送通知。 With the production key (production mode), notifications are sent. 使用生产密钥(生产模式),发送通知。 This is what I was expecting. 这就是我所期望的。

2) My code and the response I am getting back are fine. 2)我的代码和返回的响应都很好。

3) Adding a track notification for a package that was not sent through my account works just fine. 3)为未通过我的帐户发送的包裹添加跟踪通知就可以了。 There is no restriction to adding track notifications, other than there may only be a total of 4. 添加跟踪通知没有任何限制,但总共可能只有4个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM