0, 'message' => '', 'result' => '', 'errNo' => 0); try { $ch = curl_init($url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Accept-Language: zh-cn', 'Connection: Keep-Alive', 'Cache-Control: no-cache', 'Content-type: application/x-www-form-urlencoded;charset=UTF-8')); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //设置超时时间 curl_setopt($ch, CURLOPT_TIMEOUT, 120); //API返回数据 $apiResult = curl_exec($ch); $errNo = curl_errno($ch); if ($errNo) { //返回错误码 $return['errNo'] = $errNo; $errorStr = curl_error($ch); switch ((int)$errNo) { case 6: //避免一直发邮件 URL报错 break; case 7: //无法通过 connect() 连接至主机或代理服务器 break; case 28: //超时 break; case 56: //接收网络数据失败 break; default: break; } throw new Exception($errorStr); } curl_close($ch); $return['state'] = 1; //返回数据 $return['result'] = $apiResult; } catch (Exception $e) { $return['state'] = 0; $return['message'] = $e->getMessage(); } return $return; } /************************************************demo*************************************************/ /** * 1, 授权 */ $rs = curlRequest('http://www.sz56t.com:8082/selectAuth.htm', "username=test&password=123456"); $reData = json_decode(str_replace("'", "\"", $rs['result'])); $customer_id = $reData->customer_id; $customer_userid = $reData->customer_userid; //配置信息:淼信荷兰小包 $product_id = 3641; //产品id $format = 'lbl_NL_XIN.frx'; //打印类型 $printType = 1; //打印类型 /** * 2, 预报订单 */ //预报数据 $data = Array( 'buyerid' => '', 'consignee_address' => 'Blumenstraße', 'consignee_city' => 'Kulmain', 'consignee_mobile' => '', 'consignee_name' => 'Johann Schindler', 'trade_type' => 'ZYXT', 'consignee_postcode' => '95508', 'consignee_state' => 'SHANG HAI', 'consignee_telephone' => '', 'country' => 'DE', 'customer_id' => $customer_id, 'customer_userid' => $customer_userid, 'orderInvoiceParam' => Array( '0' => Array ( 'invoice_amount' => 3.5, 'invoice_pcs' => 1, 'invoice_title' => 'candle lights', 'invoice_weight' => 0.571, 'item_id' => '', 'item_transactionid' => '', 'sku' => '蜡烛灯', 'sku_code' => 'HL101', ), '1' => Array ( 'invoice_amount' => 3.5, 'invoice_pcs' => 1, 'invoice_title' => 'candle lights', 'invoice_weight' => 0.534, 'item_id' => '', 'item_transactionid' =>'', 'sku' => '蜡烛灯', 'sku_code' => 'HL103', ), ), 'order_customerinvoicecode' => 'SO781507140104', 'product_id' => $product_id, 'weight' => 1.105, 'product_imagepath' => '', ); $result = curlRequest('http://www.sz56t.com:8082/createOrderApi.htm', "param=" . json_encode($data)); echo "
"; print_r($result); echo ""; echo "