Foreword
Most of the mall will need to call the Express interface to record logistics information mall, where you are given a method for Express Interface (Express 100) call.
text
First, official documents
1. The address of the official document is:
https://www.kuaidi100.com/openapi/api_subscribe.shtml
Second, the specific implementation
1. Mall courier services and interface services specific interaction diagram:
Specific implementation logic:
We will send express order number 100, then subscribe message for the order number. When the Express 100 has subscription information generated will give the specified address to send a message similar to the push message.
Waybill your company will need to submit to the courier tracking the specified interface 100, 100 received after these express a single number is monitored to monitor if the consignment has been updated to take the initiative to push these logistics tracking information to your specified interface ,
until the end of the life cycle of these orders (generally "have been received" shall prevail), a courier waybill 100 will generally push many times more than the tracking information, your side will save it to the database. When users log on to your party website, or a mobile phone APP,
to read data directly from your company's database and displayed on your side of the website, or a mobile phone APP.
2. code implementation
(1) an order subscription information
public static function subscribeExpress($courier_company, $courier_no) { $data = [ 'company' => $courier_company, 'number' => $courier_no, 'key' => config('express_config.poll_key'), 'parameters' => [ 'callbackurl' => env('API_HOST', 'http://panda.qujie8.com/') . 'api/alipay/express/notify', 'departureCountry' => 'CN' ] ]; $post_data = [ 'schema' => 'json', 'param' => json_encode($data), ]; Log :: info ( 'Subscription Alert parameters 100', [ $ post_data ]); $ O = '' ; the foreach ( $ post_data AS $ K => $ V ) { $ O . = " $ K . =" Urlencode ( $ V ) '&';. // The default encoding format UTF-8 } $post_data = substr($o, 0, -1); $url = env('EXPRESS_PUST_URL', 'http://poll.kuaidi100.com/poll'); $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); $rst = curl_exec($ch); curl_close($ch); Log :: info ( '100 results Subscription Alert', [ $ RST ]); $ RST = of json_decode ( $ RST ,. 1 ); log :: info ( '100 results Subscription Alert', [ $ RST ]); if ($rst['result'] == false) { if ($rst['returnCode'] == 501) { Log::info('订阅快递100重复', [$rst, 'company' => $courier_company, 'courier_no' => $courier_no]); return true; } the throw new new a ServiceException ( '100 fails Subscription Alert', $ RST [ 'the returnCode' ]); } return true; }
(2) receives the order information for each callback
/** * Express 100 callback */ public static function notifyExpressInfo($poll_express_info) { $company = array_get($poll_express_info['lastResult'], 'com'); $number = array_get($poll_express_info['lastResult'], 'nu'); $borrow_express_type = FrontConst::BORROW_EXPRESS_TYPE_BORROW; $borrow_info = Borrow::where('business_courier_company_name', $company)->where('business_courier_no', $number)->first(); if (empty($borrow_info)) { $borrow_express_type = FrontConst::BORROW_EXPRESS_TYPE_RETURN; $borrow_info = Borrow::where('courier_company_name', $company)->where('courier_no', $number)->first(); } if (!empty($borrow_info)) { if ($borrow_info->status == FrontConst::STATUS_BORROW_DONE_RETURN) { \ The Log :: info ( '--- 100 Express transfer is complete order number -', [ 'borrow_id' => $ borrow_info -> the above mentioned id, 'Status' => $ borrow_info -> Status, 'business_courier_no' => borrow_info $ -> business_courier_no, 'Request_courier_no' => $ number ]); the throw new new a ServiceException ( 'The single number has been completed without further operation book', -2000 ); } } IF ( empty ( $ borrow_info )) { the throw new new a ServiceException ( 'no single stream matches the order number', -1000 ); } express_last_info $ = array_get ( $ poll_express_info , 'the lastResult' ); IF ( empty ( $ express_last_info )) { the throw new new a ServiceException ( 'without the latest delivery logistics information', -1000 ); } $ischeck = array_get($express_last_info, 'ischeck'); try { DB::beginTransaction(); $express_data = array_reverse($express_last_info['data']); foreach ($express_data as $key => $value) { //查询该快递信息是否已经录入 $borrow_express = BorrowExpress::where('borrow_id', $borrow_info->id)->where('ftime', $value['ftime'])->first(); if (empty($borrow_express)) { $express_info =[ 'Ischeck' => $ ischeck , 'state' => ExpressConst::$expressState[$express_last_info['state']], 'ftime' => $value['ftime'], 'content' => $value['context'], 'control_status' => ExpressConst::$expressStatus[$poll_express_info['status']], 'control_message' => $poll_express_info['message'], ]; //增加快递信息 self::addExpress($borrow_info->id, $borrow_info->borrow_source, $borrow_info->status, $express_info, $borrow_express_type); } } //快递被签收 if ($ischeck == 1 && $borrow_express_type == FrontConst::BORROW_EXPRESS_TYPE_BORROW) { $borrow_info->status = FrontConst::STATUS_BORROW_RECEIPT_DELIVERY; //修改订单dead_line,支付宝小程序不需要修改 if ($borrow_info->borrow_source != FrontConst::SOURCE_ALIPAY_APPLETS) { $dead_line_info = BorrowRepository::getBorrowDeadOverdue($borrow_info); $borrow_info->dead_line = empty($dead_line_info['dead_line']) ? $borrow_info->dead_line : $dead_line_info['dead_line']; } $borrow_info->save(); $return_time = strtotime($borrow_info->dead_line); if ($borrow_info->borrow_source == FrontConst::SOURCE_ALIPAY_APPLETS) { $return_time -= FrontConst::APPLETS_RENTS_EXPRESS_RETURN_TIME * 3600 * 24; } if ($borrow_info->borrow_source == FrontConst::SOURCE_ALIPAY) { //判断是否是信用借还 $notify_alipay_status = true; $user_package = $borrow_info->user_package; $package_info = empty($user_package->book_package) ? $user_package->package : $user_package->book_package; $notify_alipay_status = (!empty($user_package->book_package)) ? true : ($package_info->subscribe_times > 1 ? false : true); // notice Alipay time to modify the order IF ( $ notify_alipay_status ) { BorrowRepository::orderRentModify($borrow_info, $dead_line_info['dead_line']); \ The Log . :: info ( 'the line' $ borrow_info -.> ID 'using'. $ Package_info -.> Name ', no need to modify the expiration time', [ 'ID' => $ borrow_info -> ID ]); } } self::addExpress($borrow_info->id, $borrow_info->borrow_source, $borrow_info->status); //发送短信 SmsEntrance::sendCodeByScene($borrow_info->mobile, SmsEntrance::SCENES_USER_BORROW_RECEIPT, date('m', $return_time), date('d', $return_time)); } DB::commit(); } catch (ServiceException $e) { DB::rollBack(); Log::error($e); throw new ServiceException($e->getMessage(), $e->getCode()); } catch (Exception $e) { DB::rollBack(); Log::error($e); throw new ServiceException($e->getMessage(), $e->getCode()); } return true; }
postscript
Day to day by day too, a little bit of knowledge to accumulate.