private static function make_crc_table() { for ($n = 0; $n < 256; $n++) { $c = $n; for ($k = 0; $k < 8; $k++) { if (($c & 1) == 1) { $c = 0xedb88320 ^ self::SHR($c, 1); } else { $c = self::SHR($c, 1); } } self::$crc_table[$n] = $c; } self::$crc_table_computed = true; }
function shipping_zto($order) { //require('taobao/order_synchro.php'); include_once 'taobao/sk.php'; include_once 'taobao/TopSdk.php'; $auth = (include_once 'taobao/config.php'); //中通,加盟型 $c = new TopClient(); $c->appkey = $auth['appkey']; $c->secretKey = $auth['secretKey']; $req = new WlbWaybillISearchRequest(); $waybill_apply_request = new WaybillApplyRequest(); $waybill_apply_request->seller_id = $sk['taobao_user_id']; $waybill_apply_request->cp_code = "ZTO"; $req->setWaybillApplyRequest(json_encode($waybill_apply_request)); $resp = $c->execute($req, $sk['access_token']); //查看面单可用数量 $resp = json_decode(json_encode($resp), TRUE); $branch_account_cols = $resp['subscribtions']['waybill_apply_subscription_info']['branch_account_cols']; $quantity = $branch_account_cols['waybill_branch_account']['quantity']; $seller_id = $branch_account_cols['waybill_branch_account']['seller_id']; //发货地址 $address = $branch_account_cols['waybill_branch_account']['shipp_address_cols']['waybill_address']; $shipping_address = array("province" => $address['province'], "area" => $address['area'], "city" => $address['city'], "town" => '', "address_detail" => $address['address_detail']); $consignee_address = array("province" => $order['prov'], "city" => $order['city'], "area" => $order['city'], "town" => $order['district'], "address_detail" => $order['address']); $package_items = array("count" => 1, "item_name" => '保健食品'); $trade_order_info_cols = array("send_phone" => '15989155172', "trade_order_list" => $order['order_sn'], "product_type" => "STANDARD_EXPRESS", "consignee_phone" => $order['mobile'], "send_name" => "韦雪婷", "consignee_name" => $order['consignee'], "package_items" => $package_items, "real_user_id" => $sk['taobao_user_id'], "package_id" => $order['sn'], "consignee_address" => $consignee_address, "order_channels_type" => "TB"); //面单申请 $req = new WlbWaybillIGetRequest(); $waybill_apply_new_request = new WaybillApplyNewRequest(); $waybill_apply_new_request->seller_id = $seller_id; $waybill_apply_new_request->cp_code = "ZTO"; $waybill_apply_new_request->shipping_address = $shipping_address; $waybill_apply_new_request->app_key = $auth['appkey']; $waybill_apply_new_request->trade_order_info_cols = $trade_order_info_cols; $req->setWaybillApplyNewRequest(json_encode($waybill_apply_new_request)); $resp = $c->execute($req, $sk['access_token']); //获取面单号 $get_resp = json_decode(json_encode($resp), TRUE); if (!$get_resp['waybill_apply_new_cols']) { echo $get_resp['sub_msg']; exit; } $waybill_code = $get_resp['waybill_apply_new_cols']['waybill_apply_new_info']['waybill_code']; if (file_exists('code.jpg')) { unlink('code.jpg'); } if (file_exists('code1.jgp')) { unlink('code1.jpg'); } include './includes/bcode128.class.php'; $options = array('type' => 'B', 'dpi' => 300, 'width' => 350, 'height' => 100, 'margin' => '10', 'img_type' => 'jpg', 'color' => '#000', 'out_file' => 'code.png', 'top_size' => 20, 'top_margin' => 10, 'top_font' => 'font/microhei.ttc', 'bottom_text' => $waybill_code, 'bottom_size' => 20, 'bottom_margin' => 10, 'bottom_font' => 'font/Arial.ttf'); $font = new bcode128($waybill_code, $options); $font->img(); $options['out_file'] = 'code1.png'; $options['width'] = '240'; $options['height'] = '80'; $font = new bcode128($waybill_code, $options); $font->img(); //打印中通快递 $req = new WlbWaybillIPrintRequest(); $waybill_apply_print_check_request = new WaybillApplyPrintCheckRequest(); $other_info = $get_resp['waybill_apply_new_cols']['waybill_apply_new_info']; $print_check_info_cols = array_merge($get_resp['waybill_apply_new_cols']['waybill_apply_new_info']['trade_order_info'], array('shipping_address' => $shipping_address)); $print_check_info_cols['shipping_branch_code'] = $other_info['shipping_branch_code']; $print_check_info_cols['send_phone'] = $trade_order_info_cols['send_phone']; $print_check_info_cols['send_name'] = $trade_order_info_cols['send_name']; $print_check_info_cols['waybill_code'] = $other_info['waybill_code']; $print_check_info_cols['short_address'] = $other_info['short_address']; $print_check_info_cols = json_decode(json_encode($print_check_info_cols)); $waybill_apply_print_check_request->seller_id = $seller_id; $waybill_apply_print_check_request->print_check_info_cols = $print_check_info_cols; $waybill_apply_print_check_request->cp_code = "ZTO"; $waybill_apply_print_check_request->app_key = $auth['appkey']; $req->setWaybillApplyPrintCheckRequest(json_encode($waybill_apply_print_check_request)); $resp = $c->execute($req, $sk['access_token']); $resp = json_decode(json_encode($resp), TRUE); if (!$resp['waybill_apply_print_check_infos']) { echo '<pre>'; print_r($resp); exit; } $order_id = intval($_REQUEST['order_id']); $sql = 'UPDATE ' . $GLOBALS['ecs']->table('order_info') . ' SET shipping_time=UNIX_TIMESTAMP(),shipping_status=1, ' . "order_status=5,pay_status=2,tracking_sn='{$waybill_code}' WHERE order_id={$order_id}"; $res = $GLOBALS['db']->query($sql); $syn_info = shipping_synchro($order_id); $get_resp['waybill_apply_new_cols']['waybill_apply_new_info']['trade_order_info']['consignee_address']['address_detail'] = $order['address']; return array('get_resp' => $get_resp['waybill_apply_new_cols']['waybill_apply_new_info'], 'shipping_address' => $address); }