/** * Checks the token and authenticates the users if present. * * @param [type] $token [description] * * @return [type] [description] */ public function check($token) { $userToken = UserToken::where('token', '=', $token)->first(); if (!$userToken) { return false; } $date = new DateTime($userToken->updated_at); $timestamp = $date->format('U'); $delay = time() - $timestamp; $timeInMinutes = $delay / 60; $expires = Session::get('token_expires'); if ($expires && $timeInMinutes < $expires) { $user = Sentry::findUserById($userToken->user_id); if ($user) { return true; } } return false; }
/** * 更改订单状态时,向手机端(包括Android和IOS)发送提醒信息 * * @param [object] $[shop] [店铺对象] * @param [object] $[mainOrder] [主订单] * @param [int] $[toBeStatus] [要改变状态] * * @return Response */ protected function pushOrderInfo($shop, $mainOrder, $toBeStatus) { //获取信鸽系统配置 $accessId = Config::get('xinge.accessId'); $secretKey = Config::get('xinge.secretKey'); $xingeApp = new XingeApp($accessId, $secretKey); //根据mainorder中的userid获取token和设备类型 $userTokens = UserToken::where('wy_user_id', $mainOrder->wy_user_id)->where('wy_user_type', USER_TYPE_1)->where('wy_status', LOGIN_STATUS_1)->get(); if (!empty($userTokens->toArray())) { foreach ($userTokens as $index => $userToken) { if (DEVICE_TYPE_1 == $userToken->wy_device_type) { //根据不同状态获取不同的模板信息 switch ($toBeStatus) { case ORDER_STATE_2: //接单 $orderMessage = Config::get('xinge.androidRecvMessage'); break; case ORDER_STATE_3: //配送中 $orderMessage = Config::get('xinge.androidDeliveryMessage'); break; case ORDER_STATE_4: //完成 $orderMessage = Config::get('xinge.androidFinishMessage'); break; case ORDER_STATE_6: //拒单 $orderMessage = Config::get('xinge.androidRefuseMessage'); break; default: break; } if (isset($orderMessage)) { //单击动作 $action = new ClickAction(); $action->setActionType(ClickAction::TYPE_ACTIVITY); $action->setActivity($orderMessage['activity']); //显示样式 $styleParams = $orderMessage['style']; $style = new Style($styleParams['builderId'], $styleParams['ring'], $styleParams['vibrate'], $styleParams['clearable'], $styleParams['nId'], $styleParams['lights'], $styleParams['iconType'], $styleParams['styleId']); //Android平台的消息 $message = new Message(); $message->setTitle($orderMessage['title']); $message->setContent($orderMessage['content']); $message->setExpireTime($orderMessage['expireTime']); $message->setType(Message::TYPE_NOTIFICATION); $message->setStyle($style); $message->setAction($action); } else { $context = array("errorCode" => -10054, "userID" => $mainOrder->wy_user_id, "toBeStatus" => $toBeStatus); Log::error(Lang::get('errormessages.-10054'), $context); } } elseif (DEVICE_TYPE_2 == $userToken->wy_device_type) { //根据不同状态获取不同的模板信息 switch ($toBeStatus) { case ORDER_STATE_2: //接单 $orderMessage = Config::get('xinge.iosRecvMessage'); break; case ORDER_STATE_3: //配送中 $orderMessage = Config::get('xinge.iosDeliveryMessage'); break; case ORDER_STATE_4: //完成 $orderMessage = Config::get('xinge.iosFinishMessage'); break; case ORDER_STATE_6: //拒单 $orderMessage = Config::get('xinge.iosRefuseMessage'); break; default: break; } if (isset($orderMessage)) { //IOS平台的消息,需要IOS文档 $message = new MessageIOS(); $message->setTitle($orderMessage['title']); } else { $context = array("errorCode" => -10055, "userID" => $mainOrder->wy_user_id, "toBeStatus" => $toBeStatus); Log::error(Lang::get('errormessages.-10055'), $context); } } else { $context = array("errorCode" => -10056, "userID" => $mainOrder->wy_user_id, "deviceType" => $userToken->wy_device_type); Log::error(Lang::get('errormessages.-10056'), $context); } //自定义参数,key-value形式的 if (isset($message)) { $custom = array('shop_name' => $shop->wy_shop_name, 'main_order_id' => $mainOrder->wy_main_order_id); $message->setCustom($custom); $result = $xingeApp->PushSingleDevice($userToken->wy_token, $message); Log::info($result); } else { $context = array("errorCode" => -10057, "userID" => $mainOrder->wy_user_id, "deviceType" => $userToken->wy_device_type, "toBeStatus" => $toBeStatus); Log::error(Lang::get('errormessages.-10057'), $context); } } } else { $context = array("errorCode" => -10053, "userID" => $mainOrder->wy_user_id); Log::error(Lang::get('errormessages.-10053'), $context); } }