0

我在 asp.net 中使用 usps api。发送发货确认后,我得到了回复:

<?xml version="1.0"?>
     <DelivConfirmCertifyV3.0Response>DeliveryConfirmationNumber>420063719101969010386000074165</DeliveryConfirmationNumber>
 <DeliveryConfirmationLabel> 

2q/+mEH/8IP/wQPSU+zna52BhiD/1T4YX//6 FJqEGnDXww/9U//hEnJuH e9ecC/+GD/ /////8EtsMO+iN/Mkcwf+YWMfNp9Eb/+YY/5gdEb/m04N8wf//5tP8wf62ww/ovv g35+///FF9/8G+19F9/8G/z9/////4i2236+z8Tz2fv/s/X2fvr/7PxeferP3X9n 7zE/Z+///7P3/Z+/cMP+u6V7pNpa7pMMJOl+ra+6V/7petpOl9+6TaTaX/7pe2rp Nrk3rVht/a9q2tra2vanJjtftbX7VteO17W1tfbXtbW1//tftbW1OXbbF9iUP2KY pimKYlD9itpivYlD2P2KYraYrYlD4pivYrYpimK//Yr2NimP02w/abwwmEGEGE14 YWGEGF7TYZb/DCYXhhbTczhBhewsMIMIML/8MLwy3hhBlv9NsPxERERERERERERE RERERERERERERERERERERERwm239Nw/1sN/SbYXzWHITN53YyUGR8qiPZ2BZFdJs Nfvwg11/CCbDX56B4ovnOtREEU8ukm2v4fQTfoRaTj/b0m/BhJN/8+eby+aZwz+R 2R8z6c8Z/LmEDL5vI7L5dm2ZjCBmM+Z/LmajJzP5HI0y+fM0Okr/thB/4QcfqIQc X8emEwn4QcWEGEHH4TCDQIvoJv/o2P20kbHNzSpGxy7YYLm4SoE8OfmGC0bHLto2 NGxzY0tGto2PcJN/+n/6f/p6f+mnSf6enp6f/punEUm/+k39qk3V+t1/VVj+t14pN1a6TpNpP//96/dLp///Bfp/h/vXj6Tf/j++P////zwn/7I+H3/Ggr//7pe3///+ ERv//YP3S/Ct/+fT/Pp0myH// /8///wefT/zl23/S/tL/1///0v/8iL7S8z9Nv/3 797fdWv///9r5Rve//ab/0nM//cz+KbV6///X3r73M//bScz02v4WGEvYqGEvbCV r//9hftfbShhLYrtYYSCdfiExX7Fb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/TI9T9U 09P03TyPgm6/SdBNyEgJtBN///DC/+h+nr6H9/p6////b9Mj9d9ViF0nrDD//of/ // /iPORj///////j9tKP0tD+P82L/5qce2l8c6Bx///////////2/D//om//wb//////Oj//+v// /OjtpTo/gjv//QL/8z+dFtL50+dBwn//////t1//+l//6Tf// 16////////+z3Zz+1/s52uv2v/Z7/7Pex2lfzj/9e19vs9 /9nOz32e7PbaTaTaX/ bSdfbS/dW0rS9tL8JNpexTaXtqx/f9rFpfYSbS2K3VtLbSbStbW1/Id7GxUPYr9i mKioexXxTH+x7TFP7f7HIRxXsUx/sUx7Gxm+KOcVFf9hNPtftBhTjp9r6YXtMLww n9v9lw3a8NMLa2mFsJhYaw0GviIiIiIiI4iIiIiIiI4hxGxERFIRERERERERERH/ ttpf0rbX+FbbS/03aXxFthhL7sNftsMJftkM/r7YYhfba+219sML7hhfLcM2wwud pMkzKDMGR4qw5riBxG2Q2Rkbjt4yEgYMRNLQOwYLrqvD852v52k/9EHFWUhdUCI8 gSBd+tr+v+gbY9fqhmnEfxxztFjoG3//2+CI/OP/9EMsC9Um/3+ 1//YNvow/wgwgzEXj95iI7Lx8j8R2XggyPH7/PEfs6ETkfiOM/F4+RoR1i7JyNCCDPETsvHy8uZoR +I7OEdY8R1i5mhbINQR9L/9tL48IOP/3rCD8INBxBEfrCaD0GEGEHhBhPQfFoONB 4QemEHsG30tJsMIMLbS1l9Rd5fQwm0u10bH6Lto1uXjXRdtGtxKhou6LthhI2NFw NGt8nDRrcvzW9F24lQ0XfkNZO////pfTf//6T/TpP/1aT09N0+k9Ok/TpPpP09PT ewbfS//bSjrSbr/3//xSbp60nSbptJvH9J0m+tJukm/GtJvZCuQaA/S0m/2Kr// b S7Sx/h/2vj//Dx////+H/7ZwM1vpcf/C////wvsHH/8f+weF+P+Pj2D/9wYO/ENP 9qar///+bC+GD96//wweeC/// 4YP/2ygM1v/+n//7aW2lojf4Nzaf+YHTZy/bSbORx4QL9cOq+H661j/x/9 RUfFbFfxUV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fVYfw/hhBhfhwwmW8GEHZN4c MIMLDCDCDsm/BhBIDEgMCBSDQo+Pg0Kc3RhcnR4cmVmDQoyOTM3MA0KJSVFT0YNCg==

</DeliveryConfirmationLabel>
<ToName>Tom Collins</ToName>
<ToFirm>XYZ CORP.</ToFirm>
<ToAddress1>Suite 4D</ToAddress1>
<ToAddress2>8 WILDWOOD DR</ToAddress2>
<ToCity>OLD LYME</ToCity>
<ToState>CT</ToState>
<ToZip5>06371</ToZip5>
<ToZip4>1844</ToZip4>
<Postnet>06371184408</Postnet>
</DelivConfirmCertifyV3.0Response>

我使用以下代码从其字节生成pdf文件:

 byte[] labelBuffer = encoding.GetBytes("i put here inner string of DeliveryConfirmationLabel");
    string fileSaveLocation = " d:/test.pdf";
    // Save label buffer to file
    FileStream LabelFile = new FileStream(fileSaveLocation, FileMode.Create);
    LabelFile.Write(labelBuffer, 0, labelBuffer.Length);
    LabelFile.Close();

pdf已创建但 pdf 的内容未打开,为什么?任何人都可以帮忙吗?

4

2 回答 2

0

您需要将图像作为 Base64String 处理,这就是它的本质。

byte[] labelBuffer = Convert.FromBase64String("i put here inner string of DeliveryConfirmationLabel");

而且我认为它不是pdf,而是图像。所以试试这个代码:

public Image Base64ToImage(string base64String)
{
  // Convert Base64 String to byte[]
  byte[] imageBytes = Convert.FromBase64String(base64String);
  MemoryStream ms = new MemoryStream(imageBytes, 0, 
    imageBytes.Length);

  // Convert byte[] to Image
  ms.Write(imageBytes, 0, imageBytes.Length);
  Image image = Image.FromStream(ms, true);
  return image;
}
于 2012-02-06T10:07:34.930 回答
0

将其保存为 pdf。

$response = curl_exec($session);

$xml = new SimpleXMLElement($response);
$label_img = $xml->DeliveryConfirmationLabel;

$label_title = 'label.pdf'; // 给出你的文件名

$file=fopen($label_title,"w");

fwrite($file,base64_decode($label_img));

说明: $response 是从 USPS api 调用中收到的,您为获取编码标签而进行的调用。只需在变量“$label_img”中获取此标签,然后将其保存在磁盘上。$label_title 是要保存的文件的名称。fopen 和 fwrite 是 php 命令。

于 2013-12-27T07:53:22.657 回答