public function applyUPSLabel($data) { $recipients = isset($data['recipients']) ? $this->strreplace($data['recipients']) : ''; //收货人 $re_phone = isset($data['re_phone']) ? $this->strreplace($data['re_phone']) : ''; //收货人电话 $re_address1 = isset($data['re_address1']) ? $this->strreplace($data['re_address1']) : ''; //收件人地址1 $re_address2 = isset($data['re_address2']) ? $this->strreplace($data['re_address2']) : ''; //收件人地址2 $re_city = isset($data['re_city']) ? $this->strreplace($data['re_city']) : ''; //收件人城市 $re_state_code = isset($data['re_state_code']) ? $data['re_state_code'] : ''; //收件人所在州简码 $re_post_code = isset($data['re_post_code']) ? $data['re_post_code'] : ''; //收件人邮编 $re_country_code = isset($data['re_country_code']) ? $data['re_country_code'] : ''; //所在国家简码 $weight = isset($data['weight']) ? $data['weight'] : ''; //重量 //其他信息 $orderId = isset($data['orderId']) ? $data['orderId'] : ''; //订单号 $sku_position = isset($data['sku_position']) ? $data['sku_position'] : ''; //位置 $show_detail = isset($data['show_detail']) ? $data['show_detail'] : ''; //详细 $requestXml = <<<EOF <?xml version="1.0"?> <AccessRequest xml:lang="en-US"> <AccessLicenseNumber>0CBABC2A72B88046</AccessLicenseNumber> <UserId>linemartups</UserId> <Password>LineMart9988</Password> </AccessRequest> <?xml version="1.0"?> <ShipmentConfirmRequest xml:lang="en-US"> <Request> <TransactionReference> <CustomerContext>Customer Comment</CustomerContext> <XpciVersion/> </TransactionReference> <RequestAction>ShipConfirm</RequestAction> <RequestOption>nonvalidate</RequestOption> </Request> <LabelSpecification> <LabelPrintMethod> <Code>GIF</Code> <Description>GIF file</Description> </LabelPrintMethod> <LabelImageFormat> <Code>GIF</Code> <Description>gif</Description> </LabelImageFormat> \t<LabelStockSize> \t <Height>4</Height> \t <Width>6</Width> \t</LabelStockSize> </LabelSpecification> <Shipment> <RateInformation> <NegotiatedRatesIndicator/> </RateInformation> \t<Description/> <Shipper> <Name>Linemart Inc</Name> <PhoneNumber></PhoneNumber> <ShipperNumber>A305W6</ShipperNumber> \t <TaxIdentificationNumber></TaxIdentificationNumber> <Address> \t<AddressLine1>16518 E. Gale Ave</AddressLine1> \t<City>City of Industry</City> \t<StateProvinceCode>CA</StateProvinceCode> \t<PostalCode>91745</PostalCode> \t<PostcodeExtendedLow></PostcodeExtendedLow> \t<CountryCode>US</CountryCode> </Address> </Shipper> \t<ShipTo> <CompanyName>{$recipients}</CompanyName> <AttentionName>{$recipients}</AttentionName> <PhoneNumber>{$re_phone}</PhoneNumber> <Address> <AddressLine1>{$re_address1}</AddressLine1> <AddressLine2>{$re_address2}</AddressLine2> <City>{$re_city}</City> <StateProvinceCode>{$re_state_code}</StateProvinceCode> <PostalCode>{$re_post_code}</PostalCode> <CountryCode>{$re_country_code}</CountryCode> </Address> </ShipTo> <ShipFrom> <CompanyName>LINEMART INC.</CompanyName> <AttentionName>LINEMART INC.</AttentionName> <PhoneNumber></PhoneNumber> \t <TaxIdentificationNumber></TaxIdentificationNumber> <Address> <AddressLine1>16518 E. Gale Ave</AddressLine1> <City>City of Industry</City> \t<StateProvinceCode>CA</StateProvinceCode> \t<PostalCode>91745</PostalCode> \t<CountryCode>US</CountryCode> </Address> </ShipFrom> <PaymentInformation> \t\t<BillThirdParty> \t\t\t<BillThirdPartyShipper> \t\t\t\t<AccountNumber>E6W710</AccountNumber>\t \t\t\t\t<ThirdParty> \t\t\t\t<Address> \t\t\t\t<PostalCode>60544</PostalCode> \t\t\t\t<CountryCode>US</CountryCode> \t\t\t\t</Address> \t\t\t\t</ThirdParty> \t\t\t</BillThirdPartyShipper> \t\t</BillThirdParty> </PaymentInformation> <Service> <Code>03</Code> <Description>Ground</Description> </Service> <Package> <PackagingType> <Code>02</Code> <Description>Customer Supplied</Description> </PackagingType> <Description>Package Description</Description> \t <ReferenceNumber> \t \t<Code>00</Code> \t\t<Value>{$orderId} , {$sku_position}</Value> \t </ReferenceNumber> \t <ReferenceNumber> \t \t<Code>01</Code> \t\t<Value>{$show_detail}</Value> \t </ReferenceNumber> <PackageWeight> <UnitOfMeasurement/> <Weight>{$weight}</Weight> </PackageWeight> <AdditionalHandling>0</AdditionalHandling> </Package> </Shipment> </ShipmentConfirmRequest> EOF; // echo $requestXml;exit; $confirmUrl = 'https://onlinetools.ups.com/ups.app/xml/ShipConfirm'; //生产环境 // $confirmUrl = 'https://wwwcie.ups.com/ups.app/xml/ShipConfirm'; //测试环境地址 $result = $this->sendRequest($requestXml, $confirmUrl); if (FALSE === $result) { return FALSE; } $parsedResult = $this->parseXMLResult($result); if (FALSE === $parsedResult) { return FALSE; } // print_r($parsedResult); if ($parsedResult->Response->ResponseStatusDescription == 'Failure') { //请求失败 self::$errMsg = strval($parsedResult->Response->Error->ErrorDescription); return FALSE; } // print_r($parsedResult);exit; $shipDes = strval($parsedResult->ShipmentDigest); // var_dump($shipDes);exit; $requestXml_accetp = <<<EOF <?xml version="1.0" encoding="ISO-8859-1"?> \t<AccessRequest> \t\t<AccessLicenseNumber>0CBABC2A72B88046</AccessLicenseNumber> \t\t<UserId>linemartups</UserId> \t\t<Password>LineMart9988</Password> \t</AccessRequest> \t<?xml version="1.0" encoding="ISO-8859-1"?> \t<ShipmentAcceptRequest> \t\t<Request> \t\t\t<TransactionReference> \t\t\t\t<CustomerContext>Customer Comment</CustomerContext> \t\t\t</TransactionReference> \t\t\t<RequestAction>ShipAccept</RequestAction> \t\t\t<RequestOption>1</RequestOption> \t\t</Request> \t\t<ShipmentDigest>{$shipDes}</ShipmentDigest> \t</ShipmentAcceptRequest> EOF; $accept_curl = "https://onlinetools.ups.com/ups.app/xml/ShipAccept"; //生产环境地址 // $accept_curl = "https://wwwcie.ups.com/ups.app/xml/ShipAccept"; //测试环境地址 $accept_result = $this->sendRequest($requestXml_accetp, $accept_curl); if (FALSE === $accept_result) { return FALSE; } $accept_parseResult = $this->parseXMLResult($accept_result); if (FALSE === $accept_parseResult) { return FALSE; } // print_r($accept_parseResult); if ($accept_parseResult->Response->ResponseStatusDescription == 'Failure') { //返回错误 self::$errMsg = strval($accept_parseResult->Response->Error->ErrorDescription); return FALSE; } $trackNumber = strval($accept_parseResult->ShipmentResults->PackageResults->TrackingNumber); //跟踪号 $totalMoney = strval($accept_parseResult->ShipmentResults->ShipmentCharges->TotalCharges->MonetaryValue); //运费 $Base64LabelImage = strval($accept_parseResult->ShipmentResults->PackageResults->LabelImage->GraphicImage); //label数据 $labelContent = base64_decode($Base64LabelImage); $labelSavePath = $this->generatePathStr($orderId, 'ups/'); $labelSavePath .= "{$orderId}.gif"; $saveResult = $this->saveLabelPic($labelSavePath, $labelContent); if (FALSE === $saveResult) { $this->errCode = 8002; $this->errMsg = 'label文件存储出错 --trackNumber -- ' . $trackNumber; return FALSE; } $returnData = array('trackNumber' => $trackNumber, 'shippFee' => $totalMoney, 'imagePath' => $labelSavePath); return $returnData; }
public function view_applyLabel() { $returnData = array('code' => 0, 'msg' => ''); $orderId = isset($_GET['oid']) ? intval($_GET['oid']) : 0; if (!$orderId) { $returnData['msg'] = '未指定订单号'; echo json_encode($returnData); return FALSE; } $orderInfo = OrderInfoModel::getOrderInfo($orderId); if (FALSE === $orderInfo) { //不存在的订单号 $returnData['msg'] = '不存在的订单号!'; echo json_encode($returnData); return FALSE; } if ($orderInfo['orderStatus'] != 911 || $orderInfo['orderType'] != 916) { //订单状态不合法 $returnData['msg'] = '该订单不是海外仓待打印订单!'; echo json_encode($returnData); return FALSE; } if ($orderInfo['transportId'] == 0) { //订单未设置运输方式 $returnData['msg'] = '该订单还未设定运输方式!'; echo json_encode($returnData); return FALSE; } $orderActObj = new OrderindexAct(); $skuList = $orderActObj->act_getRealskulist($orderId); //获得全部的sku列表 if (FALSE == $skuList) { $returnData['msg'] = '获取料号信息出错!'; echo json_encode($returnData); return FALSE; } $owOrderMg = new OwOrderManageModel(); $owShipDes = new OwShippingWayDesisionModel(); $outside = $owShipDes->culPackageLWH($skuList); $buyerInfo = $owOrderMg->getUnshippedOrderBuyerInfo($orderId); //买家信息 if (FALSE === $buyerInfo) { $returnData['msg'] = '获取买家信息失败!'; echo json_encode($returnData); return FALSE; } $zipCode = $buyerInfo['zipCode']; //邮编 $weight = $orderInfo['calcWeight']; //订单重量 if ($weight == 0) { //重量为0 则无法处理 $returnData['msg'] = '订单重量为0,请先确认重量!'; echo json_encode($returnData); return FALSE; } $owOrderMG = new OwOrderManageModel(); $transInfo = $owOrderMG->getShippingInfo($orderId); if (!empty($transInfo) && $transInfo['shippingWay'] == 'USPS' && $transInfo['isCanceled'] == 0) { /* 当之前有申请过usps 并且申请的usps还没有退款的时 则 不予申请*/ $returnData['msg'] = '请先退款已申请的USPS!'; echo json_encode($returnData); return FALSE; } $shipping = new ExpressLabelApplyModel(); $zone = $shipping->getZoneCode($zipCode); $zone = FALSE !== $zone ? $zone : 6; //如果没找到分区则默认为6区 $shippingInfo = $owShipDes->chooseShippingWay($skuList, $weight, $outside, $zone); if ($shippingInfo) { $transId = $shipping->reflectCodeToId($shippingInfo['shippingCode']); } else { $transId = 0; } if ($transId != $orderInfo['transportId']) { //计算出的运输方式和系统的不符合 $returnData['msg'] = "计算的运输方式和初始运输方式不符合! 请重新生成运输方式 ! 计算运输方式为 " . $shippingInfo['shippingCode']; echo json_encode($returnData); return FALSE; } if (0 == $transId) { //没找到正确的运输方式 $returnData['msg'] = OwShippingWayDesisionModel::$errMsg; echo json_encode($returnData); return FALSE; } $data = array(); $data['recipients'] = $buyerInfo['username']; //收件人 $data['re_phone'] = $buyerInfo['landline'] . '/' . $buyerInfo['phone']; //电话 $data['re_address1'] = $buyerInfo['street']; //街道地址一 $data['re_address2'] = $buyerInfo['address2']; //街道地址二 $data['re_city'] = $buyerInfo['city']; //市 $data['re_post_code'] = $zipCode; //邮编 $data['re_country_code'] = 'US'; //国家简称 $data['weight'] = $weight; //重量 $data['orderId'] = $orderId; //订单号 $owSkuMG = new OwSkuInfoManageModel(); //生成料号仓位数据 $skuLocation = $owSkuMG->getAsetOfSkusLocation(array_keys($skuList)); $positionStr = ''; $skuDetailStr = ''; foreach ($skuList as $k => $_num) { $position = $skuLocation[$k]; $positionStr .= " {$k} [{$position}] "; $skuDetailStr .= " {$k} * {$_num} "; } $data['sku_position'] = $positionStr; $data['show_detail'] = $skuDetailStr; $handResult = FALSE; $errMsg = ''; // print_r($shippingInfo['shippingCode']);exit; if ('UPS Ground' == $shippingInfo['shippingCode']) { //申请 UPS Label $upsApplyObj = new ApplyUpsLabelModel(); $data['re_state_code'] = $upsApplyObj->getStateAbbreviationName($buyerInfo['state']); //州简称 if (FALSE == $data['re_state_code']) { //没找到则使用原始值 $data['re_state_code'] = $buyerInfo['state']; } // print_r($data);exit; $applyResult = $upsApplyObj->applyUPSLabel($data); if (FALSE === $applyResult) { //申请标签失败 $errMsg = ApplyUpsLabelModel::$errMsg; } else { $handResult = TRUE; $this->deal_img_ups($applyResult['imagePath'], $applyResult['imagePath']); } } else { if ('USPS' == $shippingInfo['shippingCode']) { //申请usps label $uspsApplyObj = new ApplyUSPSLabelModel(); $data['re_state_code'] = $uspsApplyObj->getStateAbbreviationName($buyerInfo['state']); //州简称 if (FALSE == $data['re_state_code']) { //没找到则使用原始值 $data['re_state_code'] = $buyerInfo['state']; } $mailClass = $shippingInfo['extensionInfo']['mailclass']; //运输类型 $packageType = $shippingInfo['extensionInfo']['packageType']; $typeInfo = array('mailClass' => $mailClass, 'packageType' => $packageType); $applyResult = $uspsApplyObj->aplyUSPSLabel($data, $typeInfo); if (FALSE === $applyResult) { //申请标签失败 $errMsg = ApplyUSPSLabelModel::$errMsg; } else { $handResult = TRUE; if ($packageType == 'Letter' || $packageType == 'Flat') { $this->deal_img_usps($applyResult['imagePath'], $applyResult['imagePath']); //后期处理图片 } } } } if (FALSE == $handResult) { $returnData['msg'] = $errMsg; } else { $returnData['code'] = 1; // array('trackNumber'=>$trackNumber, 'shippFee'=>$totalMoney, 'imagePath'=>$labelSavePath $result = $owOrderMG->insertNewTrackNumber($orderId, $applyResult['trackNumber'], $shippingInfo['shippingCode'], $_SESSION['sysUserId'], 0); //更新跟踪号信息 $result2 = $owOrderMG->changeOrderStatus(911, 910, $orderId); } echo json_encode($returnData); return FALSE; }