/**
  * 设备列表
  * @author Hanxiang
  */
 public function index()
 {
     // get devices by status
     $input = Input::all();
     if (!isset($input['status']) || $input['status'] == -1) {
         $devices = Device::where('status', '>=', 0);
         //->paginate(15);
         $status = -1;
     } else {
         $status = $input['status'];
         $devices = Device::where('status', $status);
         //->paginate(15);
     }
     if (isset($input['app_id']) && !empty($input['app_id'])) {
         $app_id = $input['app_id'];
         $device_ids = [];
         $device_apps = DeviceApp::where('app_id', $app_id)->get()->toArray();
         foreach ($device_apps as $da) {
             array_push($device_ids, $da['device_id']);
         }
         $devices = $devices->whereIn('id', $device_ids);
     }
     if (isset($input['sn']) && !empty($input['sn'])) {
         $devices = $devices->where('sn', 'like', '%' . $input['sn'] . '%');
     }
     if (isset($input['uuid']) && !empty($input['uuid'])) {
         $devices = $devices->where('uuid', 'like', '%' . $input['uuid'] . '%');
     }
     if (isset($input['major']) && !empty($input['major'])) {
         $devices = $devices->where('major', $input['major']);
     }
     if (isset($input['minor']) && !empty($input['minor'])) {
         $devices = $devices->where('minor', $input['minor']);
     }
     if (isset($input['date_from']) && !empty($input['date_from'])) {
         $devices = $devices->where('created_at', '>', self::convtDate($input['date_from']));
     }
     if (isset($input['date_to']) && !empty($input['date_to'])) {
         $devices = $devices->where('created_at', '<', self::convtDate($input['date_to'], false));
     }
     $devices = $devices->orderBy('updated_at', 'desc')->get();
     //->paginate(15);
     foreach ($devices as $device) {
         $device->status_cn = Device::$status[$device->status];
         if ($device->status > 0) {
             $deviceApp = DeviceApp::where("device_id", $device->id)->first();
             if ($deviceApp) {
                 $device->app = DeviceApp::find($deviceApp->id)->app;
             } else {
                 $app_empty = new \stdClass();
                 $app_empty->name = '';
                 $device->app = $app_empty;
             }
         }
     }
     $manufacturers = Manufacturer::getAllWithModels();
     // get all apps
     $apps = App::all();
     return view('admin.devices')->with('devices', $devices)->with('status', $status)->with('apps', $apps)->with('manufacturers', $manufacturers);
 }
 /**
  * 获取token
  * @param null
  * @return mixed
  * @author zhengqian.zhu
  */
 public function getToken(Request $request)
 {
     $request = $request->only('appid', 't', 'sign');
     $validator = \Validator::make($request, array('appid' => 'required', 't' => 'required', 'sign' => 'required'));
     if ($validator->fails()) {
         return RestHelp::parametersIllegal($validator->messages()->first());
     }
     $app = App::where("app_id", $request['appid'])->first();
     if (!$app) {
         return RestHelp::encodeResult("21001", "appId not found");
     }
     $appsecret = $app->app_secret;
     $md5Sign = $this->md5Str($request['appid'], $appsecret, $request['t']);
     if ($request['sign'] != $md5Sign) {
         return RestHelp::encodeResult("21002", "sign not correct");
     }
     $day = new \DateTime();
     $day->modify("+2 hours");
     $app->expire_at = $day->format("Y-m-d H:i:s");
     //如果存在未过期的token,直接返回token
     if (!$app->access_token || $app->expire_at <= date("Y-m-d H:i:s")) {
         $app->access_token = Uuid::v4(false);
     }
     $app->save();
     return RestHelp::success(['access_token' => $app->access_token, 'expires_in' => 7200]);
 }
 /**
  * 验证 Token 并使其登录
  * @author zhengqian.zhu@dajiayao.cc
  */
 protected function verifyToken($tokenStr)
 {
     // TODO: Redis 缓存 Token
     // 判断 Token 有效性
     $token = App::where('access_token', '=', $tokenStr)->where('expire_at', '>', date("Y-m-d H:i:s"))->first();
     if (!$token) {
         return false;
     }
     // 延长 Token 的有效期
     $today = new \Datetime();
     $modifier = '+2 hours';
     $token->expire_at = $today->modify($modifier);
     $token->save();
     return $token->app_id;
 }
 public function index()
 {
     $user = Auth::user();
     if ($user->role == User::ROLE_ADMIN) {
         $devicesCount = Device::all()->count();
         $wxDevicesCount = WeixinDevice::all()->count();
         $appsCount = App::all()->count();
         $wxPagesCount = WeixinPage::all()->count();
     } else {
         $apps = App::where('user_id', $user->id)->lists('id');
         $devicesCount = DeviceApp::whereIn('app_id', $apps)->count();
         $mps = WeixinMp::whereIn('app_id', $apps)->lists('id');
         $wxDevicesCount = WeixinDevice::whereIn('wx_mp_id', $mps)->count();
         $appsCount = count($apps);
         $wxPagesCount = WeixinPage::whereIn('wx_mp_id', $mps)->count();
     }
     return view('admin.index')->with('devicesCount', $devicesCount)->with('wxDevicesCount', $wxDevicesCount)->with('appsCount', $appsCount)->with('wxPagesCount', $wxPagesCount);
 }
Exemple #5
0
 public function add()
 {
     $input = Input::only('name', 'app_id', 'app_secret', 'type', 'comment', 'device_url', 'user_id');
     $name = $input['name'];
     $appId = $input['app_id'];
     $appSecret = $input['app_secret'];
     $type = $input['type'];
     $comment = $input['comment'];
     $deviceUrl = $input['device_url'];
     $userId = $input['user_id'];
     $user = $this->userService->getUserById($userId);
     if (!($name and $appId and $appSecret and $type and $user)) {
         return redirect()->back()->with('error_tips', '提交数据不完整')->withInput();
     }
     $app = ['name' => $name, 'app_id' => $appId, 'app_secret' => $appSecret, 'type' => $type, 'comment' => $comment, 'device_url' => $deviceUrl, 'status' => App::STATUS_NORMAL, 'user_id' => $userId];
     App::create($app);
     return redirect()->route('apps')->with("success_tips", "保存成功!");
 }
Exemple #6
0
 public function getAppById($id)
 {
     return App::where('id', $id)->first();
 }
 /**
  * 获取当前用户拥有的公众号
  * @author Hanxiang
  */
 private static function getCurrentWxMps()
 {
     $user = Auth::user();
     $wx_mps = [];
     if ($user->role == User::ROLE_COMMON_USER) {
         $apps = App::where('user_id', $user->id)->get();
         if ($apps) {
             foreach ($apps as $a) {
                 $wx_mps = WeixinMp::where('app_id', $a->id)->get();
             }
         }
     } else {
         $wx_mps = WeixinMp::all();
     }
     return $wx_mps;
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     // $this->call('UserTableSeeder');
     DB::table('users')->truncate();
     User::create(['username' => 'admin', 'email' => '*****@*****.**', 'password' => \Hash::make('11431143'), 'role' => User::ROLE_ADMIN, 'status' => User::STATUS_NORMAL]);
     User::create(['username' => 'yayao001', 'email' => '*****@*****.**', 'password' => \Hash::make('yayao001'), 'role' => User::ROLE_COMMON_USER, 'status' => User::STATUS_NORMAL]);
     DB::table('manufacturers')->truncate();
     Manufacturer::create(['name' => '佰睿科技', 'website' => 'http://www.bytereal.com', 'address' => '深圳市南山区高新南六道航盛科技大厦', 'email' => '*****@*****.**', 'phone' => '400-8899-181']);
     Manufacturer::create(['name' => '微肯科技', 'website' => 'http://www.wizarcan.com', 'address' => '上海市黄浦区西藏南路760号安基大厦706室', 'email' => '*****@*****.**', 'phone' => '021-63309703']);
     DB::table('device_models')->truncate();
     DeviceModel::create(['id' => 1, 'manufacturer_id' => 1, 'battery_lifetime' => 18, 'name' => 'BR', 'comment' => '佰睿']);
     DeviceModel::create(['id' => 2, 'manufacturer_id' => 2, 'battery_lifetime' => 18, 'name' => 'wizarcan', 'comment' => '微肯']);
     DB::table('apps')->truncate();
     App::create(['app_id' => 'yyfa7b475d22b0ef1d', 'app_secret' => 'ec6a2a765bc197a273841cd41ed171a2 ', 'name' => '丫摇小店', 'type' => App::TYPE_WEIXIN, 'access_token' => '', 'expire_at' => '2030-05-01 00:00:00', 'comment' => '丫摇小店(消费者服务号)', 'user_id' => 2, 'status' => App::STATUS_NORMAL]);
     App::create(['app_id' => 'yy3a6b475fc2b19f2e', 'app_secret' => '3a76597a2784bc11edeccd416a2171a2', 'name' => '测试应用', 'type' => App::TYPE_WEIXIN, 'access_token' => '', 'expire_at' => '2030-05-01 00:00:00', 'comment' => '测试应用', 'user_id' => 2, 'status' => App::STATUS_NORMAL]);
     DB::table('wx_mp')->truncate();
     WeixinMp::create(['appid' => 'wxfb42b0ea75d27f1d', 'appsecret' => 'a62a7197273e81cd4a1d14715bca2ec6', 'name' => '丫摇小店', 'mp_id' => 'gh_dd4f2e417685', 'comment' => '丫摇小店(消费者服务号)', 'app_id' => 1]);
     WeixinMp::create(['appid' => 'wxbc879a670cb32971', 'appsecret' => '20b517a9882cecc620e20175f8943ef0', 'name' => '测试号', 'mp_id' => 'gh_dxxxxxxxx', 'comment' => '测试', 'app_id' => 2]);
     DB::table('devices')->truncate();
     //        \Dajiayao\Model\Device::create([
     //            "id"=>1,
     //            "model_id"=>1,
     //            "manufacturer_sn"=>11111,
     //            "sn"=>2015121212,
     //            "wx_device_id"=>1,
     //            "uuid"=>'FDA50693-A4E2-4FB1-AFCF-C6EB07647825',
     //            "major"=>10001,
     //            "minor"=>44330,
     //            "password"=>123456,
     //            "comment"=>'comment',
     //            "status"=>1
     //        ]);
     //
     //        \Dajiayao\Model\Device::create([
     //            "id"=>2,
     //            "model_id"=>1,
     //            "manufacturer_sn"=>22222,
     //            "sn"=>2015131313,
     //            "wx_device_id"=>1,
     //            "uuid"=>'FDA50693-A4E2-4FB1-AFCF-C6EB07647825',
     //            "major"=>10001,
     //            "minor"=>44330,
     //            "password"=>123456,
     //            "comment"=>'comment',
     //            "status"=>1
     //        ]);
     //
     //        \Dajiayao\Model\Device::create([
     //            "id"=>3,
     //            "model_id"=>1,
     //            "manufacturer_sn"=>33333,
     //            "sn"=>2015141414,
     //            "wx_device_id"=>2,
     //            "uuid"=>'FDA50693-A4E2-4FB1-AFCF-C6EB07647825',
     //            "major"=>10001,
     //            "minor"=>44331,
     //            "password"=>123456,
     //            "comment"=>'comment',
     //            "status"=>1
     //        ]);
     //
     //        \Dajiayao\Model\Device::create([
     //            "id"=>4,
     //            "model_id"=>1,
     //            "manufacturer_sn"=>44444,
     //            "sn"=>201515151515,
     //            "wx_device_id"=>3,
     //            "uuid"=>'FDA50693-A4E2-4FB1-AFCF-C6EB07647825',
     //            "major"=>10001,
     //            "minor"=>44332,
     //            "password"=>123456,
     //            "comment"=>'comment',
     //            "status"=>1
     //        ]);
     DB::table('wx_devices')->truncate();
     //        \Dajiayao\Model\WeixinDevice::create([
     //            'id'=>1,
     //            "uuid"=>'FDA50693-A4E2-4FB1-AFCF-C6EB07647825',
     //            "major"=>10001,
     //            "minor"=>44330,
     //            "device_id"=>657415,
     //            "wx_mp_id"=>1
     //        ]);
     //
     //
     //        \Dajiayao\Model\WeixinDevice::create([
     //            'id'=>2,
     //            "uuid"=>'FDA50693-A4E2-4FB1-AFCF-C6EB07647825',
     //            "major"=>10001,
     //            "minor"=>44331,
     //            "device_id"=>657416,
     //            "wx_mp_id"=>1
     //        ]);
     //
     //        \Dajiayao\Model\WeixinDevice::create([
     //            'id'=>3,
     //            "uuid"=>'FDA50693-A4E2-4FB1-AFCF-C6EB07647825',
     //            "major"=>10001,
     //            "minor"=>44332,
     //            "device_id"=>657417,
     //            "wx_mp_id"=>1
     //        ]);
     //
     //        \Dajiayao\Model\WeixinDevice::create([
     //            'id'=>4,
     //            "uuid"=>'FDA50693-A4E2-4FB1-AFCF-C6EB07647825',
     //            "major"=>10007,
     //            "minor"=>41549,
     //            "device_id"=>681062,
     //            "wx_mp_id"=>1,
     //            "apply_id"=>26858
     //        ]);
     DB::table('wx_pages')->truncate();
     //        \Dajiayao\Model\WeixinPage::create([
     //            "wx_mp_id"=>1,
     //            "page_id"=>81039,
     //            'title'=>'周边主标题',
     //            'description'=>'副标题',
     //            'icon_url'=>'http://shp.qpic.cn/wx_shake_bus/0/1431503979e9dd2797018cad79186e03e8c5aec8dc/120',
     //            'url'=>'http://www.baidu.com',
     //            'comment'=>'comment'
     //        ]);
     //
     //        DB::table('wx_mp')->truncate();
     //        \Dajiayao\Model\WeixinMp::create([
     //            "id"=>1,
     //            "appid"=>'wxbc879a670cb32971',
     //            'appsecret'=>'20b517a9882cecc620e20175f8943ef0',
     //            'name'=>'大家摇',
     //            'mp_id'=>'原始id',
     //            'app_id'=>1
     //        ]);
 }