代码之家  ›  专栏  ›  技术社区  ›  Brian Gottier

为什么我的联邦快递包裹送达时没有收到通知?

  •  0
  • Brian Gottier  · 技术社区  · 7 年前

    我在使用联邦快递的网络服务 jeremy-dunn/php-fedex-api-wrapper 试图让联邦快递在包裹送达后给我发送一封明文电子邮件通知我正在使用第三方完成订单,他们有并使用不同的联邦快递帐户,而不是我的。(也许这就是问题所在?)

    我可以很好地跟踪包裹,当我尝试订阅送货通知时,联邦快递的回复似乎表明成功了我在测试模式中我现在还没有进入生产模式,以防万一。

    我的请求使用以下功能:

    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 回复  |  直到 7 年前
        1
  •  0
  •   Jordan Havins    7 年前
        2
  •  0
  •   Brian Gottier    7 年前

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

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

    3)为未通过我的帐户发送的包添加跟踪通知非常好添加跟踪通知没有限制,只是总共可能只有4个。

    推荐文章