Example #1
0
 /**
  * 获取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]);
 }
Example #2
0
 /**
  * 验证 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;
 }
Example #3
0
 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);
 }
Example #4
0
 public function getAppById($id)
 {
     return App::where('id', $id)->first();
 }
Example #5
0
 /**
  * 获取当前用户拥有的公众号
  * @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;
 }