我想直接了解如何打印运输标签。
我已经测试https://github.com/aaronjsmith/stamps.com-php它工作正常(它只提供费率)
如何使用PHP打印标签。使用代码后,我收到以下错误
在做好一切之后我得到了这个错误信息几乎试过了8-10
#message: "Invalid rate. Invalid FromZIPCode."
#code: 0
#file: "C:\xampp\htdocs\www.checkwriter.com\app\Http\Controllers\HomePageController.php"
#line: 367
+"faultstring": "Invalid rate. Invalid FromZIPCode."
+"faultcode": "soap:Server"
+"faultactor": "http://swsim.testing.stamps.com/swsim/swsimv62.asmx"
+"detail": {#500 ▶}
trace: {▶}
答案 0 :(得分:0)
公共函数CreateLabel($ to,$ packige,$ ShipDate){
$d=[
'Authenticator' =>$this->authenticator,
'Address' => [
'FullName' => $to->name,
'Address1' => $to->address1,
'Address2' => $to->address2,
'City' => $to->city,
'State' => $to->state,
'ZIPcode' => $to->zip
]
];
$cleanseToAddressResponse = $this->makeCall('CleanseAddress', $d);
if (!$cleanseToAddressResponse->CityStateZipOK) {
return array('err'=>'yes','code'=>_('Bad customer adress'));
}
$Address =new StamsAddress(STAMPS_COMPANY, STAMPS_ADRESS1,STAMPS_ADRESS2,STAMPS_CITY, STAMPS_COUNTRY,STAMPS_ZIP);
$company=[
'Authenticator' =>$this->authenticator,
'Address' => [
'FullName' => $Address->name,
'Address1' => $Address->address1,
'Address2' => $Address->address2,
'City' => $Address->city,
'State' => $Address->state,
'ZIPcode' => $Address->zip
]
];
$cleanseFromAddressResponse = $this->makeCall('CleanseAddress', $company);
if (!$cleanseFromAddressResponse->CityStateZipOK) {
return array('err'=>'yes','code'=>_('Bad company adress'));
}
$rateOptions = [
"Authenticator" => $this->authenticator,
"Rate" => [
"FromZIPCode" =>$Address->zip,
'ToZIPCode' => $to->zip,
"Length" => $packige['l'],
"Width" =>$packige['w'],
"Height" => $packige['h'],
"WeightOz" => $packige['oz'],
'WeightLb' => '0.0',
'ServiceType' =>$packige['service_type'],
"PackageType" => "Package",
"ShipDate" => $ShipDate,
"InsuredValue" => '0.0',
'AddOns' => array(
array(
'AddOnType' => 'SC-A-HP' // Hide price on label
)
)
]
];
try {
$rates = $this->makeCall('getRates', $rateOptions);
}catch (SoapFault $fault) {
return array('err'=>'yes','code'=>_('No reate customer adress'));
}
$rateOptions = [
"Authenticator" => $this->authenticator,
"Rate" => [
"FromZIPCode" =>$Address->zip,
'ToZIPCode' => $to->zip,
"Length" => $packige['l'],
"Width" =>$packige['w'],
"Height" => $packige['h'],
"WeightOz" => $packige['oz'],
'WeightLb' => '0.0',
'ServiceType' =>$packige['service_type'],
"PackageType" => "Package",
"ShipDate" => $ShipDate,
"InsuredValue" => '0.0',
'Amount' =>$rates->Rates->Rate->Amount,
'AddOns' => array(
array(
'AddOnType' => 'SC-A-HP' // Hide price on label
)
)
]
];
// 4. Generate label
$IntegratorTxID=time();
/**
* If true, generates a sample label without real value.
* @var bool
*/
$Loger = new Logger();
$isSampleOnly = true;
$labelOptions = [
'Authenticator' =>$this->authenticator,
'IntegratorTxID' => $IntegratorTxID,
'SampleOnly' =>$isSampleOnly,
'ImageType' => 'Pdf',
'TrackingNumber' => '',
'Rate' => $rateOptions,
'From' => [
'FullName' => $Address->name,
'Address1' => $Address->address1,
'Address2' => $Address->address2,
'City' => $Address->city,
'State' => $Address->state,
'ZIPcode' => $Address->zip
],
'To' => [
'FullName' => $to->name,
'Address1' => $to->address1,
'Address2' => $to->address2,
'City' => $to->city,
'State' => $to->state,
'ZIPcode' => $to->zip
]
];
$indiciumResponse = $this->makeCall('CreateIndicium', $labelOptions);
/**
* If use tracking $indiciumResponse->TrackingNumber
*
*/
/**
* If download label $indiciumResponse->URL
*
*/
$filename=false;
$Loger->msg(LOG_ERROR,"stamps 1 ".$Loger->var_ex($labelOptions), __FILE__, __LINE__);
$Loger->msg(LOG_ERROR,"stamps 2 ".$Loger->var_ex($indiciumResponse), __FILE__, __LINE__);
if(!isset($indiciumResponse->URL)){
return array('err'=>'yes','code'=>_('No create label'));
}
if(is_array($indiciumResponse) && !count($indiciumResponse)){
return array('err'=>'yes','code'=>_('No create label'));
}
if ($filename) {
$ch = curl_init($indiciumResponse->URL);
$fp = fopen($filename, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
}
$daa['err']='no';
$daa['URL']=$indiciumResponse->URL;
$daa['TrackingNumber']=$indiciumResponse->TrackingNumber;
return $daa ;
}