UPS ShipmentRequest API JSON 通知运送到接入点
UPS ShipmentRequest API JSON Notification shipping to access point
我现在不知所措,我正在尝试添加将包裹发送到 UPS 接入点的选项,文档告诉我我需要为 UAP (013) 添加通知对象,并且日常活动 (012)
当我阅读文档时,通知对象最多允许出现 3 次,通常在 xml 中它看起来像:
<ShipmentServiceOptions>
<Notification>
<NotificationCode>012</NotificationCode>
some other values ( here..)
</Notification>
<Notification>
<NotificationCode>013</NotificationCode>
some other values ( here..)
</Notification>
</ShipmentServiceOptions>
但是由于我使用的是 JSON,所以我创建了一个对象数组:
$Shipment['ShipmentServiceOptions']['Notification'][] = ['NotificationCode' => '012'];
$Shipment['ShipmentServiceOptions']['Notification'][] = ['NotificationCode' => '013'];
当我 json 解码这个完整的数组时,它看起来像:
{
"Notification": [{
"NotificationCode": "013",
"EmailMessage": {
"EMailAddress": "info@tom-it.nl",
"UndeliverableEMailAddr": "info@tom-it.nl",
"FromEMailAddress ": "fromemail@test.com",
"FromName": "From Email"
},
"Locale": {
"Language": "ENG",
"Dialect": "US"
}
}, {
"NotificationCode": "012",
"EmailMessage": {
"EMailAddress": "info@tom-it.nl",
"UndeliverableEMailAddr": "info@tom-it.nl",
"FromEMailAddress ": "From Email",
"FromName": "From Name"
},
"Locale": {
"Language": "ENG",
"Dialect": "US"
}
}]
}
这是一个有效的 json 对象,但由于某种原因我不断收到错误消息:
ADL notification code (012) and notification data (email or phone number) is required for hold for pickup at access point location shipment.
当我翻转数组值时,我会得到错误:
UAP shipper notification code (013) and notification data (email or phone number) is required for UPS Access Point Delivery.
在我看来,这似乎只从数组中读取了 1 个值,阅读文档让我相信它需要多个 Notification 键,但我真的不知道如何在 json,这将使 json 对象无效。任何帮助将不胜感激
编辑
当我将 JSON 对象转换为如下所示时:
"ShipmentServiceOptions": [{
"Notification": {
"NotificationCode": "013",
"EmailMessage": {
"EMailAddress": "info@tom-it.nl",
"UndeliverableEMailAddr": "info@tom-it.nl",
"FromEMailAddress ": "fromemail",
"FromName": "From Name"
},
"Locale": {
"Language": "ENG",
"Dialect": "US"
}
}
}, {
"Notification": {
"NotificationCode": "012",
"EmailMessage": {
"EMailAddress": "info@tom-it.nl",
"UndeliverableEMailAddr": "info@tom-it.nl",
"FromEMailAddress ": "fromemail",
"FromName": "From Name"
},
"Locale": {
"Language": "ENG",
"Dialect": "US"
}
}
}],
它给了我这个错误:
ADL notification code (012) and notification data (email or phone number) is required for hold for pickup at access point location shipment.
交换项目不会改变错误
我知道这会很简单,如果需要一个多小时才能修复,你就知道这很简单 ;-)
我将 xml 文档与 Web 服务文档交换,在 xml 中添加通知电子邮件数据的节点称为:
/ShipmentConfirmRequest/Shipment/ShipmentServiceOptions/Notification/EMailMessage/
在 JSON 文档中,保存邮件数据的同一节点称为:
/ShipmentConfirmRequest/Shipment/ShipmentServiceOptions/Notification/EMail/
为了完整性,这是通知对象的正确 json 部分:
{
"Notification": [{
"NotificationCode": "013",
"EMail": {
"EMailAddress": "info@tom-it.nl",
"UndeliverableEMailAddr": "info@tom-it.nl",
"FromEMailAddress ": "fromemail",
"FromName": "fromemail"
},
"Locale": {
"Language": "ENG",
"Dialect": "US"
}
}, {
"NotificationCode": "012",
"EMail": {
"EMailAddress": "info@tom-it.nl",
"UndeliverableEMailAddr": "info@tom-it.nl",
"FromEMailAddress ": "fromname",
"FromName": "From Name"
},
"Locale": {
"Language": "ENG",
"Dialect": "US"
}
}]
}
我也想实现UPS的异常通知。 API 是:/ShipmentRequest/Shipment/ShipmentServiceOptions/Notification & /ShipmentRequest/Shipment/ShipmentServiceOptions/Notification/NotificationCode
我尝试在结帐事件中这样做,但未找到响应 302。
代码:
public function execute(\Magento\Framework\Event\Observer $observer) {
$event = $observer->getEvent();
$orderIds = $event->getOrderIds();
$order_id = $orderIds[0];
// echo $order_id;
$writer = new Stream(BP . '/var/log/upsnotification.log');
$logger = new Logger();
$logger->addWriter($writer);
$logger->info("UPS Exception Notification");
$shippingEmail = 'rashi.goyal@netsmartz.net';
/* $post = [
'NotificationCode' => '7',
'EMailAddress' => 'rashi.goyal@netsmartz.net',
'OrderId' => $order_id
]; */
$request = $this->createExceptionNotificationXmlRequest($shippingEmail);
$endpointurl = $this->_helper->getConfig('bizzarro/auth/endpoint').'/ShipmentRequest/Shipment/ShipmentServiceOptions/Notification/NotificationCode';
$outputFileName = BP."/var/UPSExceptionNotification_".$order_id.".xml";
/* $post['ShipmentServiceOptions']['Notification'][] = ['NotificationCode' => '7'];
$post['ShipmentServiceOptions']['Notification'][] = ['NotificationCode' => '8'];
$data_string = json_encode($post); */
/* $shippingEmail = array(
"EMailAddress" => $shipping["email"]
); */
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $endpointurl );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($ch);
//print_r($response);die;
curl_close($ch);
if ($response == false) {
throw new Exception ( "Bad data." );
} else {
// save request and response to file
$fw = fopen ( $outputFileName, 'w' );
fwrite ( $fw, "TEST FROM OBSERVER\n\n" );
fwrite ( $fw, "Response: \n" . json_encode($response) . "\n" );
fclose ( $fw );
}
$writer = new Stream(BP . '/var/log/upsnotification.log');
$logger = new Logger();
$logger->addWriter($writer);
}
private function createExceptionNotificationXmlRequest($shippingEmail)
{
//Licencia
$xml = '<?xml version="1.0"?>
//Request
$xml.='<?xml version="1.0"?>';
$xml.= "<ShipmentServiceOptions>
<Notification>
<NotificationCode>7</NotificationCode>
<EMail>".$shippingEmail."</EMail>
</Notification>
<Notification>
<NotificationCode>8</NotificationCode>
<EMail>".$shippingEmail."</EMail>
</Notification>
</ShipmentServiceOptions>";
return $xml;
}
请指出我哪里出错了。
拉希
我现在不知所措,我正在尝试添加将包裹发送到 UPS 接入点的选项,文档告诉我我需要为 UAP (013) 添加通知对象,并且日常活动 (012)
当我阅读文档时,通知对象最多允许出现 3 次,通常在 xml 中它看起来像:
<ShipmentServiceOptions>
<Notification>
<NotificationCode>012</NotificationCode>
some other values ( here..)
</Notification>
<Notification>
<NotificationCode>013</NotificationCode>
some other values ( here..)
</Notification>
</ShipmentServiceOptions>
但是由于我使用的是 JSON,所以我创建了一个对象数组:
$Shipment['ShipmentServiceOptions']['Notification'][] = ['NotificationCode' => '012'];
$Shipment['ShipmentServiceOptions']['Notification'][] = ['NotificationCode' => '013'];
当我 json 解码这个完整的数组时,它看起来像:
{
"Notification": [{
"NotificationCode": "013",
"EmailMessage": {
"EMailAddress": "info@tom-it.nl",
"UndeliverableEMailAddr": "info@tom-it.nl",
"FromEMailAddress ": "fromemail@test.com",
"FromName": "From Email"
},
"Locale": {
"Language": "ENG",
"Dialect": "US"
}
}, {
"NotificationCode": "012",
"EmailMessage": {
"EMailAddress": "info@tom-it.nl",
"UndeliverableEMailAddr": "info@tom-it.nl",
"FromEMailAddress ": "From Email",
"FromName": "From Name"
},
"Locale": {
"Language": "ENG",
"Dialect": "US"
}
}]
}
这是一个有效的 json 对象,但由于某种原因我不断收到错误消息:
ADL notification code (012) and notification data (email or phone number) is required for hold for pickup at access point location shipment.
当我翻转数组值时,我会得到错误:
UAP shipper notification code (013) and notification data (email or phone number) is required for UPS Access Point Delivery.
在我看来,这似乎只从数组中读取了 1 个值,阅读文档让我相信它需要多个 Notification 键,但我真的不知道如何在 json,这将使 json 对象无效。任何帮助将不胜感激
编辑
当我将 JSON 对象转换为如下所示时:
"ShipmentServiceOptions": [{
"Notification": {
"NotificationCode": "013",
"EmailMessage": {
"EMailAddress": "info@tom-it.nl",
"UndeliverableEMailAddr": "info@tom-it.nl",
"FromEMailAddress ": "fromemail",
"FromName": "From Name"
},
"Locale": {
"Language": "ENG",
"Dialect": "US"
}
}
}, {
"Notification": {
"NotificationCode": "012",
"EmailMessage": {
"EMailAddress": "info@tom-it.nl",
"UndeliverableEMailAddr": "info@tom-it.nl",
"FromEMailAddress ": "fromemail",
"FromName": "From Name"
},
"Locale": {
"Language": "ENG",
"Dialect": "US"
}
}
}],
它给了我这个错误:
ADL notification code (012) and notification data (email or phone number) is required for hold for pickup at access point location shipment.
交换项目不会改变错误
我知道这会很简单,如果需要一个多小时才能修复,你就知道这很简单 ;-)
我将 xml 文档与 Web 服务文档交换,在 xml 中添加通知电子邮件数据的节点称为:
/ShipmentConfirmRequest/Shipment/ShipmentServiceOptions/Notification/EMailMessage/
在 JSON 文档中,保存邮件数据的同一节点称为:
/ShipmentConfirmRequest/Shipment/ShipmentServiceOptions/Notification/EMail/
为了完整性,这是通知对象的正确 json 部分:
{
"Notification": [{
"NotificationCode": "013",
"EMail": {
"EMailAddress": "info@tom-it.nl",
"UndeliverableEMailAddr": "info@tom-it.nl",
"FromEMailAddress ": "fromemail",
"FromName": "fromemail"
},
"Locale": {
"Language": "ENG",
"Dialect": "US"
}
}, {
"NotificationCode": "012",
"EMail": {
"EMailAddress": "info@tom-it.nl",
"UndeliverableEMailAddr": "info@tom-it.nl",
"FromEMailAddress ": "fromname",
"FromName": "From Name"
},
"Locale": {
"Language": "ENG",
"Dialect": "US"
}
}]
}
我也想实现UPS的异常通知。 API 是:/ShipmentRequest/Shipment/ShipmentServiceOptions/Notification & /ShipmentRequest/Shipment/ShipmentServiceOptions/Notification/NotificationCode
我尝试在结帐事件中这样做,但未找到响应 302。 代码:
public function execute(\Magento\Framework\Event\Observer $observer) {
$event = $observer->getEvent();
$orderIds = $event->getOrderIds();
$order_id = $orderIds[0];
// echo $order_id;
$writer = new Stream(BP . '/var/log/upsnotification.log');
$logger = new Logger();
$logger->addWriter($writer);
$logger->info("UPS Exception Notification");
$shippingEmail = 'rashi.goyal@netsmartz.net';
/* $post = [
'NotificationCode' => '7',
'EMailAddress' => 'rashi.goyal@netsmartz.net',
'OrderId' => $order_id
]; */
$request = $this->createExceptionNotificationXmlRequest($shippingEmail);
$endpointurl = $this->_helper->getConfig('bizzarro/auth/endpoint').'/ShipmentRequest/Shipment/ShipmentServiceOptions/Notification/NotificationCode';
$outputFileName = BP."/var/UPSExceptionNotification_".$order_id.".xml";
/* $post['ShipmentServiceOptions']['Notification'][] = ['NotificationCode' => '7'];
$post['ShipmentServiceOptions']['Notification'][] = ['NotificationCode' => '8'];
$data_string = json_encode($post); */
/* $shippingEmail = array(
"EMailAddress" => $shipping["email"]
); */
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $endpointurl );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $request);
$response = curl_exec($ch);
//print_r($response);die;
curl_close($ch);
if ($response == false) {
throw new Exception ( "Bad data." );
} else {
// save request and response to file
$fw = fopen ( $outputFileName, 'w' );
fwrite ( $fw, "TEST FROM OBSERVER\n\n" );
fwrite ( $fw, "Response: \n" . json_encode($response) . "\n" );
fclose ( $fw );
}
$writer = new Stream(BP . '/var/log/upsnotification.log');
$logger = new Logger();
$logger->addWriter($writer);
}
private function createExceptionNotificationXmlRequest($shippingEmail)
{
//Licencia
$xml = '<?xml version="1.0"?>
//Request
$xml.='<?xml version="1.0"?>';
$xml.= "<ShipmentServiceOptions>
<Notification>
<NotificationCode>7</NotificationCode>
<EMail>".$shippingEmail."</EMail>
</Notification>
<Notification>
<NotificationCode>8</NotificationCode>
<EMail>".$shippingEmail."</EMail>
</Notification>
</ShipmentServiceOptions>";
return $xml;
}
请指出我哪里出错了。 拉希