function cw_usps_parce_result($result, $xml_head, $type) { $response['type'] = $type; $response['error'] = false; $res = cw_xml2hash($result); if ($res['Error']) { $response['error'] = true; $response['type'] = "txt"; $response['data'] = $res['Error']['Description']; $response['error_code'] = $res['Error']['Number']; return $response; } if ($res[$xml_head . 'Response']) { if (!empty($res[$xml_head . 'Response']['DeliveryConfirmationLabel'])) { $response['data'] = base64_decode(str_replace(array("\n"), array(""), $res[$xml_head . 'Response']['DeliveryConfirmationLabel'])); } elseif (!empty($res[$xml_head . 'Response']['LabelImage'])) { $response['data'] = base64_decode(str_replace(array("\n"), array(""), $res[$xml_head . 'Response']['LabelImage'])); } elseif (!empty($res[$xml_head . 'Response']['EMConfirmationNumber']) && $type == 'txt') { $response['data'] = $res[$xml_head . 'Response']['EMConfirmationNumber']; } } return $response; }
<CustomerRefNo></CustomerRefNo> <AddressServiceRequested></AddressServiceRequested> <SenderName></SenderName> <SenderEMail></SenderEMail> <RecipientName></RecipientName> <RecipientEMail></RecipientEMail> </{$xml_head}> EOT; } $query_prepared = urlencode($query); list($header, $return) = cw_https_request("GET", $usps_server . "?API={$api}&XML=" . $query_prepared); if (defined('USPS_DEBUG')) { cw_log_add('usps', $query . "\n\n" . $header . "\n\n" . $return); } $response = array("result" => 'http_error'); $res = cw_xml2hash($return); if ($res['Error']) { $response['result'] = 'error'; $response['error'] = $res['Error']['Description']; } elseif ($res[$head . 'Response']) { $response['result'] = 'ok'; if ($service_type == "GlobalAir" || $service_type == "GlobalExpress" || $service_type == "GlobalPriority") { $response['image'] = base64_decode(str_replace(array("\n"), array(""), $res[$head . 'Response']['LabelImage'])); } elseif ($service_type == "ExpressMail") { $response['image'] = base64_decode(str_replace(array("\n"), array(""), $res[$head . 'Response']['EMLabel'])); } else { $response['image'] = base64_decode(str_replace(array("\n"), array(""), $res[$head . 'Response']['DeliveryConfirmationLabel'])); } switch ($image_type) { case 'TIF': $response['image_type'] = "image/tiff";