Example #1
0
 /**
  * 生成短信验证码
  * 判断用户获得验证码的资格:type:
  * 1 - 只有未注册的用户才能获取注册验证码
  * 3 - 只有注册过的用户才能获取添加亲人验证码
  * 7 - 只有注册过的用户才能获取忘记密码的验证码
  * 9 - 只有注册过的用户才能获取修改密码的验证码
  * 11 - 只有注册过的用户才能获取第三方注册验证码
  */
 public function makeCaptcha($type, $mobi = '', $babyId = '')
 {
     $userInfo = $this->userSwoole->getUserInfoByMobi($mobi);
     if (($type == '1' || $type == '11') && !empty($userInfo['data'])) {
         return self::EXIST_MOBILE;
     }
     if (($type == '3' || $type == '7' || $type == '9') && empty($userInfo['data'])) {
         return self::NON_EXIST_MOBILE;
     }
     //如果是添加副号,则须判断是否登录以及该手机号是否已经添加
     if ($type == '3') {
         //如果该号已经是宝贝亲人号,则不发送短信
         $checkRel = $this->family->checkRelation($userInfo['data']['u_id'], $babyId);
         if (!empty($checkRel)) {
             return self::HAVE_FAMILY_RELATION;
         }
         $babyInfo = $this->baby->getBabyName($babyId);
     }
     $RedisLib = new \Appserver\Utils\RedisLib($this->di);
     $redis = $RedisLib::getRedis();
     //生成验证码ename123
     if ($redis->get($mobi . $type) == FALSE) {
         $captchaCode = \Appserver\Utils\Common::random(4);
         $redis->setex($mobi . $type, $this->di['sysconfig']['capTime'], $captchaCode);
     } else {
         $captchaCode = $redis->get($mobi . $type);
     }
     switch ($type) {
         case 1:
             $message = sprintf($this->di['sysconfig']['regCaptchaMsg'], $captchaCode);
             break;
         case 3:
             $message = sprintf($this->di['sysconfig']['addRelCaptchaMsg'], $captchaCode, $babyInfo['baby_nick']);
             break;
         case 7:
             $message = sprintf($this->di['sysconfig']['resetCaptchaMsg'], $captchaCode);
             break;
         case 9:
             $message = sprintf($this->di['sysconfig']['changeCaptchaMsg'], $captchaCode);
             break;
         case 11:
             $message = sprintf($this->di['sysconfig']['regCaptchaMsg'], $captchaCode);
             break;
     }
     $lastCapthaInfo = $this->captcha->getLastCapthaInfo($mobi, $type);
     if ($_SERVER['REQUEST_TIME'] - $lastCapthaInfo['mc_addtime'] < 60) {
         return self::GET_TOO_CAPTCHA;
     }
     //验证码入库
     $data = $this->captcha->addCaptcha($mobi, $type, $_SERVER['REQUEST_TIME'], $captchaCode);
     if ($data) {
         $sendMsg = new RpcService($this->di['sysconfig']['thriftConf']['ip'], $this->di['sysconfig']['thriftConf']['port']);
         $sendMsg->smsSend($mobi, $message);
         return self::SUCCESS;
     } else {
         return self::FAIL;
     }
 }
Example #2
0
 /**
  * [获取天气预报信息]
  * @param  [type] $babyId [description]
  * @param  [type] $city   [description]
  * @return [type]         [description]
  */
 public function getFore($babyId, $city)
 {
     $babyInfo = $this->baby->getBabyName($babyId);
     try {
         $rpcConnect = new \Appserver\Utils\RpcService($this->di['sysconfig']['thriftConf']['ip'], $this->di['sysconfig']['thriftConf']['port']);
         $location = $rpcConnect->GetBabyLocation($babyId);
     } catch (\Exception $e) {
         continue;
     }
     //如果从babyid找不到地理位置,则根据请求的地理位置计算天气
     if (!empty($location)) {
         $location = json_decode($location, true);
         $city = $location['city'];
     }
     if ($city != '') {
         //获取地区编码
         $areaid = UserHelper::getAreaCode($this->di, $city);
         if (!$areaid) {
             $city = substr($city, 0, -3);
             $areaid = UserHelper::getAreaCode($this->di, $city);
         }
     }
     if ($city == '' || !$areaid) {
         return array('flag' => '1', 'area' => $city, 'aqi' => '', 'qlt' => '', 'h_temp' => '', 'l_temp' => '', 'weat_pic' => '', 'weather' => '', 'baby_pic' => '');
     }
     $redisObj = new RedisLib($this->di);
     $redis = $redisObj->getRedis();
     $weatherData = $redis->get($this->di['weatherConfig']['weatherData'] . $areaid);
     if (empty($weatherData)) {
         //缓存过期,重新获取数据
         $data = UserHelper::rollCurlRequest(array('aqi' => sprintf($this->di['weatherConfig']['pm25']['url'], urlencode($city)), 'fore' => sprintf($this->di['weatherConfig']['weatherConfig']['url'], urlencode($city))));
         if (empty($data) || !empty($data[0]['error']) || !empty($data[1]['error'])) {
             $flag = 0;
             $log = '查询天气:' . $city . '>>结果:aqi:' . $data[0]['error'] . '>>天气:' . $data[1]['error'];
         } else {
             $weather = json_decode($data['fore']['info'], true);
             $aqi = json_decode($data['aqi']['info'], true);
             if ($weather['error_code'] != '0' || $aqi['error_code'] != '0') {
                 $flag = 0;
             }
             $log = '查询天气:' . $city . '>>结果:aqi:' . $aqi['reason'] . '>>天气:' . $weather['reason'];
             //构造天气数据
             if ($weather['error_code'] == 0) {
                 $temp = explode('~', $weather['result']['today']['temperature']);
                 $ltemp = (string) $temp[0];
                 $htemp = (string) $temp[1];
                 //气象实况
                 $weath = $weather['result']['today']['fb'];
                 $forecast = $weather['result']['today']['weather'];
             } else {
                 $ltemp = '';
                 $htemp = '';
                 //气象实况,99-未知天气
                 $weath = '99';
                 $forecast = '';
                 $flag = 0;
                 $log = '查询天气:' . $city . '>>结果:' . $weather['reason'];
             }
             //构造aqi数据
             if ($aqi['error_code'] == 0) {
                 $pmAqi = (string) $aqi['result']['AQI'];
                 $qlt = (string) $aqi['result']['Quality'];
             } else {
                 $pmAqi = '';
                 $qlt = '';
                 $flag = 0;
                 $log = '查询aqi:' . $city . '>>结果:aqi:' . $aqi['reason'];
             }
             $weatherData['area'] = $city;
             $weatherData['aqi'] = $pmAqi;
             $weatherData['qlt'] = $qlt;
             $weatherData['h_temp'] = $htemp;
             $weatherData['l_temp'] = $ltemp;
             $weatherData['weather'] = $forecast;
             $weatherData['weatherCode'] = $weath;
             //存入缓存:如果数据不完整,则缓存半小时,若数据完整,则缓存8小时
             if (empty($weatherData['weather'])) {
                 $redis->setex($this->di['weatherConfig']['weatherData'] . $areaid, $this->di['weatherConfig']['weatherShortTime'], $weatherData);
             } else {
                 $redis->setex($this->di['weatherConfig']['weatherData'] . $areaid, $this->di['weatherConfig']['weatherTime'], $weatherData);
             }
         }
     }
     if (!empty($weatherData['weatherCode']) && !empty($weatherData['aqi']) && (!empty($weatherData['l_temp']) || !empty($weatherData['h_temp']))) {
         $res = UserHelper::getBabyWeatherPic($this->di, $babyInfo['baby_sex'], $weatherData['weatherCode'], $weatherData['aqi'], $weatherData['l_temp'], $weatherData['h_temp']);
         $weatherData['baby_pic'] = $res['baby_pic'];
         $weatherData['weat_pic'] = $res['weat_pic'];
     } else {
         $weatherData['baby_pic'] = '';
         $weatherData['weat_pic'] = '';
     }
     unset($weatherData['weatherCode']);
     $weatherData['flag'] = '1';
     return $weatherData;
 }
Example #3
0
 /**
  * [点击获取新定位点]
  * @param  [type] $babyId [宝贝id]
  * @param  [type] $type   [1-主动获取 3-自动更新]
  * @return [type]         [description]
  */
 public function getNewLocate($babyId, $type = '')
 {
     if (empty($type) || $type == '1') {
         $uuid = $this->locateModel->getUuidByBaby($babyId);
         //如果找不到uuid,则从设备表中查找
         if (empty($uuid) || $uuid['uuid'] == '0') {
             $devicesModel = $this->initModel('\\Appserver\\Mdu\\Models\\DevicesModel');
             $uuid = $devicesModel->getNearlyDev($babyId);
         }
         if (!empty($uuid) && $uuid['uuid'] != '0') {
             try {
                 //设置获取数据数据的超时时间为58秒
                 $rpcObj = new RpcService($this->di['sysconfig']['thriftConf']['ip'], $this->di['sysconfig']['thriftConf']['port'], 58000);
                 $liInfo = json_decode($rpcObj->LocateFind($uuid['uuid']), true);
                 if (!empty($liInfo['li_id'])) {
                     $status = self::DEV_REGULAR;
                     //如果从rpc获得了新点,则返回新点
                     $data = $this->locateModel->getLocateInfoByLiid($liInfo['li_id']);
                 } else {
                     //获取最近的一个点
                     $data = $this->locateModel->nearlyCoorOfToday($babyId, strtotime(date('Y-m-d', $_SERVER['REQUEST_TIME'])));
                     if (in_array($liInfo['status'], array(0, 1, 3, 9))) {
                         if (!empty($data)) {
                             $status = self::DEV_REGULAR;
                         } else {
                             $status = self::DEV_SIGNAL_POOR;
                         }
                     } elseif ($liInfo['status'] == '7') {
                         //休眠时,不通知客户端,当成正常点处理
                         $status = self::DEV_REGULAR;
                         if (empty($data)) {
                             //得知设备休眠,获取假点
                             $getPoint = new RpcService($this->di['sysconfig']['thriftConf']['ip'], $this->di['sysconfig']['thriftConf']['port']);
                             //从云端获得假点
                             $pointInfo = json_decode($getPoint->getPoint($babyId), true);
                             if (!empty($pointInfo) && array_key_exists('coordinates', $pointInfo)) {
                                 $data = array('coordinates' => (string) $pointInfo['coordinates'], 'timestamp' => (string) $pointInfo['timestamp'], 'place' => (string) $pointInfo['place'], 'battery' => (string) $pointInfo['battery'], 'start' => (string) $pointInfo['start'], 'end' => (string) $_SERVER['REQUEST_TIME'], 'type' => (string) $pointInfo['type'], 'accur' => (string) $pointInfo['accur']);
                             }
                         }
                     } elseif ($liInfo['status'] == '5') {
                         $status = self::DEV_CLOSED;
                     }
                 }
             } catch (\Exception $e) {
                 $status = self::DEV_SIGNAL_POOR;
                 //获取最近的一个点
                 $data = $this->locateModel->nearlyCoorOfToday($babyId, strtotime(date('Y-m-d', $_SERVER['REQUEST_TIME'])));
             }
         } else {
             $status = self::DEV_SIGNAL_POOR;
         }
     } elseif ($type == '3') {
         $status = self::DEV_REGULAR;
         $data = $this->locateModel->nearlyCoorOfToday($babyId, strtotime(date('Y-m-d', $_SERVER['REQUEST_TIME'])));
     }
     if (isset($data) && !empty($data)) {
         $data['end'] = (string) $_SERVER['REQUEST_TIME'];
         $data = array($data);
     } else {
         $data = array();
     }
     return array('flag' => '1', 'data' => $data, 'status' => $status, 'status_msg' => $this->di['sysconfig']['msgForDevStatus'][$status]);
 }
Example #4
0
 /**
  * 童鞋工作模式
  *如果宝贝id有值,则修改该宝贝所有童鞋的工作模式;如果shoeid有值,则改变对应的童鞋的工作模式;二者不能同时有值
  *备注:目前根据宝贝id修改工作模式的功能暂时屏蔽
  *mode:修改的工作模式: 1-省电 3-安全 5-休眠
  *$dev是所有需要修改工作模式的童鞋id的集合
  */
 public function modeAction()
 {
     //目前只开放针对宝贝的工作模式切换,不提供关于童鞋的
     if (!isset($this->_sanReq['baby_id']) && isset($this->_sanReq['shoe_id'])) {
         $babyId = $this->devices->getBabyIdByShoeId($this->userInfo['uid'], $this->_sanReq['shoe_id']);
         if (empty($babyId) || $babyId['baby_id'] == '0') {
             $this->_showMsg(self::NON_EXIST_SHOE, $this->di['flagmsg'][self::NON_EXIST_SHOE]);
         }
         $this->_oauthrity($this->userInfo['uid'], $babyId['baby_id']);
         $this->devices->updateShoeMode($this->_sanReq['shoe_id'], $this->_sanReq['mode']);
         $shoeMode = new \Appserver\Utils\RpcService($this->di['sysconfig']['thriftConf']['ip'], $this->di['sysconfig']['thriftConf']['port']);
         $shoeMode->setDevMod($this->_sanReq['shoe_id'], $this->userInfo['mobi'], $this->_sanReq['mode']);
         $this->_showMsg(self::SUCCESS);
     } else {
         $this->_showMsg(self::INVALID_OPERATE, $this->di['flagmsg'][self::INVALID_OPERATE]);
     }
 }