Example #1
0
File: wxapi.php Project: wxl2012/wx
 /**
  * 处理微信服务器推送的请求
  *
  */
 public function action_action($appid = false)
 {
     if (!$appid) {
         die(json_decode(['status' => 'err', 'msg' => '非法请求', 'errcode' => 2010]));
     }
     if (is_numeric($appid)) {
         $this->account = \Model_WXAccount::find($appid);
     } else {
         if (is_string($appid)) {
             $this->account = \Model_WXAccount::query()->where('app_id', $appid)->get_one();
         }
     }
     if (!$this->account) {
         die(json_decode(['status' => 'err', 'msg' => '该公众号不存在', 'errcode' => 2011]));
     }
     \Session::set($this->SESSION_WXACCOUNT_KEY, $this->account);
     //检验消息合法性
     if (!\handler\mp\Tool::checkSignature(\Input::get('signature', false), \Input::get('timestamp', false), \Input::get('nonce', false), $this->account->token)) {
         \Log::error('WXApi.php check signature account:' . json_encode($this->account->to_array()));
         die('');
     }
     //接入请求
     if (\Input::get('echostr', false)) {
         if ($this->account->status != 'NONE') {
             \Log::error('account status error');
             die;
         } else {
             die(\Input::get('echostr'));
         }
     }
     $this->handler();
 }
Example #2
0
File: home.php Project: wxl2012/wx
 public function action_login()
 {
     if (\Auth::check()) {
         $redirect = "/admin";
         if (isset($data['to_url'])) {
             $redirect = $data['to_url'];
         }
         \Response::redirect($redirect);
     }
     \View::set_global(array('menu' => 'admin-home', 'title' => '登录系统', 'action' => 'login'));
     if (\Input::method() == 'POST') {
         if (\Auth::login()) {
             if (\Auth::get_user()->username == 'admin') {
                 \Response::redirect('/admin');
             }
             $employee = \Model_Employee::query()->where('parent_id', \Auth::get_user()->id)->get_one();
             if (!$employee) {
                 \Session::set_flash('msg', ['status' => 'err', 'msg' => '非法登录,多次尝试登录,您的帐户将被封锁!', 'title' => '警告', 'sub_title' => '非法登录', 'icon' => 'exclamation-circle', 'color' => '#d9534f']);
                 return $this->not_login_alert();
             }
             // 保存会话信息: 当前登录人员的身份、所属商户、微信公众号信息
             \Session::set('seller', $employee->seller);
             \Session::set('people', $employee->people);
             \Session::set('employee', $employee);
             // 查询当前商户默认公众号信息
             $accounts = \Model_WXAccount::query()->where(['seller_id' => $employee->seller->id])->get();
             $account = false;
             if (count($accounts) > 1) {
                 foreach ($accounts as $item) {
                     if ($account->is_default == 1) {
                         $account = $item;
                         break;
                     }
                 }
             } else {
                 $account = current($accounts);
             }
             \Session::set('WXAccount', $account);
             //获取API访问令牌
             $result = \handler\common\UrlTool::request(\Config::get('base_url') . 'api/token.json?user_id=' . \Auth::get_user()->id);
             $token = json_decode($result->body);
             \Session::set('access_token', $token->access_token);
             $redirect = "/admin";
             if (isset($data['to_url'])) {
                 $redirect = $data['to_url'];
             }
             \Response::redirect($redirect);
         }
         \Session::set_flash('msg', array('status' => 'err', 'msg' => '登录失败', 'errcode' => 20));
     }
     return \Response::forge(\View::forge("ace/login"));
 }
Example #3
0
 public function action_exist($filed = 'open_id', $value = '')
 {
     $account = \Model_WXAccount::query()->where($filed, $value)->get();
     if (!$account) {
         die(json_encode(array('status' => 'succ', 'msg' => '', 'errcode' => 0, 'data' => false)));
     }
     die(json_encode(array('status' => 'succ', 'msg' => '', 'errcode' => 0, 'data' => true)));
 }