Php 如何使用stamps.com创建装运标签

Php 如何使用stamps.com创建装运标签,php,shipping,Php,Shipping,我想要关于如何打印装运标签的直接代码 我已经测试过它工作正常(它只提供费率) 如何使用PHP打印标签。使用代码后,我得到以下错误 在做了所有正确的事情之后,我收到了这个错误消息,尝试了将近8-10次 #message: "Invalid rate. Invalid FromZIPCode." #code: 0 #file: "C:\xampp\htdocs\www.checkwriter.com\app\Http\Controllers\HomePageController.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: {▶}

公共函数CreateLabel($to、$packige、$ShipDate){


这不是免费的代码编写服务,你至少需要尝试一下。如果你的帖子以“我想要直接代码”开头那么你可能已经做错了什么,你能用示例地址来称呼它吗?这给了我错误如果你没有足够的时间用示例地址来检查这个,那么你也不应该得到代码…我相信SOF不是免费的代码服务。
    $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 ;
}