$shipperCode,'LogisticCode' => $logisticCode)); $account = self::get_account(); Log::record("EBusinessID={$account}",Log::DEBUG); $datas = array( 'EBusinessID' => $account['EBusinessID'], 'RequestType' => '1002', 'RequestData' => urlencode($requestData), 'DataType' => '2', 'DataSign' => self::encrypt($requestData, $account['AppID']) ); $result = http_post_data(self::req_url,$datas); return $result; } static public function cur_businessid() { $account = self::get_account(); return $account['EBusinessID']; } static public function get_account() { if(defined('MOBILE_PUBLISH') && MOBILE_PUBLISH == true) { return array('EBusinessID' => '1256766','AppID' => '22c88d88-3565-4023-b5ac-0201792869ed'); } else { return array('EBusinessID' => '1256051','AppID' => '6718d260-e2b6-4329-ad78-daff173309ac'); } } static private function encrypt($data, $appkey) { return urlencode(base64_encode(md5($data . $appkey))); } static public function subscribe($order_sn) { $model_order = Model('order'); $condition['order_sn'] = $order_sn; $order_info = $model_order->getOrderInfo($condition, array('order_common', 'order_goods')); // 发送快递鸟订阅回调 $express = rkcache('express', true); $e_code = $express[$order_info['extend_order_common']['shipping_express_id']]['e_kdn_code']; if(empty($e_code)) { Log::record("找不到该单号的快递公司编码—— ordersn={$order_sn}",Log::ERR); return; } // 通知订阅, 快递鸟定时回调 $ret = self::req_subscribe($e_code, $order_info['shipping_code'], $order_sn); if($ret === false) { Log::record("kdn_helper::subscribe order_sn={$order_sn} error.",Log::ERR); } else { Log::record("kdn_helper::subscribe ret={$ret}",Log::DEBUG); } } static public function req_subscribe($e_code, $logisticCode, $order_sn) { $datas = array(array('Code' => $e_code,'Item' => array(array('No' => $logisticCode,'Bk' => $order_sn)))); $requestData = json_encode($datas); $account = self::get_account(); $datas = array( 'EBusinessID' => $account['EBusinessID'], 'RequestType' => '1005', 'RequestData' => urlencode($requestData), 'DataType' => '2', 'DataSign' => self::encrypt($requestData, $account['AppID']) ); $result = http_post_data(self::req_url, $datas); return $result; } static public function onCallback($data) { $order_sn = $data['CallBack']; if(empty($order_sn)) return; $e_code = $data['ShipperCode']; $shipping_code = $data['LogisticCode']; $key = "express_{$e_code}_{$shipping_code}"; wkcache($key, $data); // 数据解析 switch ($data['State']) { case '3': // 已签收, 设置为已收货 { $model_order = Model('order'); $update = $model_order->editOrder(array('order_state' => ORDER_STATE_SUCCESS), array('order_state' => ORDER_STATE_SEND,'order_sn' => $order_sn)); if (!$update) { Log::record('更新订单状态为已收货状态时写入失败'); } } break; case '4': // 问题件 Log::record("order_sn={$order_sn},code = {$data['LogisticCode']}.",Log::ERR); break; default: { Log::record('query_status false'); break; } } } }