Example #1
0
 /**
  * (non-PHPdoc)
  * @see \tfc\mvc\interfaces\Action::run()
  */
 public function run()
 {
     $req = Ap::getRequest();
     $cookie = new Cookie('cookie');
     $appid = Cfg::getApp('appid', 'qq', 'extlogin');
     $appkey = Cfg::getApp('appkey', 'qq', 'extlogin');
     $callback = Options::getSiteUrl() . '/index.php?r=member/data/qqcallback';
     if ($cookie->get('state') !== $req->getParam('state')) {
         exit('The state does not match. You may be a victim of CSRF.');
     }
     $tokenUrl = 'https://graph.qq.com/oauth2.0/token?grant_type=authorization_code' . '&client_id=' . $appid . '&redirect_uri=' . urlencode($callback) . '&client_secret=' . $appkey . '&code=' . $req->getParam('code');
     $response = file_get_contents($tokenUrl);
     if (strpos($response, 'callback') !== false) {
         $lpos = strpos($response, '(');
         $rpos = strrpos($response, ')');
         $response = substr($response, $lpos + 1, $rpos - $lpos - 1);
         $msg = json_decode($response);
         if (isset($msg->error)) {
             echo '<h3>error:</h3>' . $msg->error;
             echo '<h3>msg  :</h3>' . $msg->error_description;
             exit;
         }
     }
     $params = array();
     parse_str($response, $params);
     $graphUrl = 'https://graph.qq.com/oauth2.0/me?access_token=' . $params['access_token'];
     $str = file_get_contents($graphUrl);
     if (strpos($str, 'callback') !== false) {
         $lpos = strpos($str, '(');
         $rpos = strrpos($str, ')');
         $str = substr($str, $lpos + 1, $rpos - $lpos - 1);
     }
     $user = json_decode($str);
     if (isset($user->error)) {
         echo '<h3>error:</h3>' . $user->error;
         echo '<h3>msg  :</h3>' . $user->error_description;
         exit;
     }
     $openid = $user->openid;
     $mod = Model::getInstance('Account', 'member');
     $ret = $mod->extlogin(DataAccount::PARTNER_QQ, $openid);
     if ($ret['err_no'] === DataAccount::SUCCESS_LOGIN_NUM) {
         $httpReferer = HttpCookie::get('http_referer', 'index.php');
         HttpCookie::remove('http_referer');
         Ap::getResponse()->location($httpReferer);
     } else {
         Ap::getResponse()->location('index.php?r=member/show/login');
     }
 }
Example #2
0
 /**
  * (non-PHPdoc)
  * @see \tfc\mvc\interfaces\Action::run()
  */
 public function run()
 {
     $cookie = new Cookie('cookie');
     $httpReferer = Ap::getRequest()->getTrim('http_referer');
     if ($httpReferer === '') {
         $httpReferer = 'index.php';
     }
     HttpCookie::add('http_referer', $httpReferer);
     $appid = Cfg::getApp('appid', 'wechat', 'extlogin');
     $callback = Options::getSiteUrl() . '/index.php?r=member/data/wechatcallback';
     $scope = 'snsapi_base';
     $state = md5(uniqid(rand(), TRUE));
     //CSRF protection
     $cookie->add('state', $state);
     $loginUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize?response_type=code' . '&appid=' . $appid . '&redirect_uri=' . urlencode($callback) . '&state=' . $state . '&scope=' . $scope . '#wechat_redirect';
     Ap::getResponse()->location($loginUrl);
 }
Example #3
0
 /**
  * (non-PHPdoc)
  * @see \tfc\mvc\interfaces\Action::run()
  */
 public function run()
 {
     $cookie = new Cookie('cookie');
     $httpReferer = Ap::getRequest()->getTrim('http_referer');
     if ($httpReferer === '') {
         $httpReferer = 'index.php';
     }
     HttpCookie::add('http_referer', $httpReferer);
     $appid = Cfg::getApp('appid', 'qq', 'extlogin');
     $callback = Options::getSiteUrl() . '/index.php?r=member/data/qqcallback';
     $scope = 'get_user_info';
     $state = md5(uniqid(rand(), TRUE));
     //CSRF protection
     $cookie->add('state', $state);
     $loginUrl = 'https://graph.qq.com/oauth2.0/authorize?response_type=code' . '&client_id=' . $appid . '&redirect_uri=' . urlencode($callback) . '&state=' . $state . '&scope=' . $scope;
     Ap::getResponse()->location($loginUrl);
 }
Example #4
0
 /**
  * (non-PHPdoc)
  * @see \tfc\mvc\interfaces\Action::run()
  */
 public function run()
 {
     $req = Ap::getRequest();
     $cookie = new Cookie('cookie');
     $appid = Cfg::getApp('appid', 'wechat', 'extlogin');
     $appsecret = Cfg::getApp('appsecret', 'wechat', 'extlogin');
     if ($cookie->get('state') !== $req->getParam('state')) {
         exit('The state does not match. You may be a victim of CSRF.');
     }
     $tokenUrl = 'https://api.weixin.qq.com/sns/oauth2/access_token?grant_type=authorization_code' . '&appid=' . $appid . '&secret=' . $appsecret . '&code=' . $req->getParam('code');
     $resource = curl_init();
     curl_setopt($resource, CURLOPT_URL, $tokenUrl);
     curl_setopt($resource, CURLOPT_HEADER, 0);
     curl_setopt($resource, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($resource, CURLOPT_NOSIGNAL, 1);
     curl_setopt($resource, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
     $result = curl_exec($resource);
     if ($result === false) {
         $errNo = curl_errno($resource);
         $errMsg = curl_error($resource);
         curl_close($resource);
         echo '<h3>error:</h3>' . $errNo;
         echo '<h3>msg  :</h3>' . $errMsg;
         exit;
     }
     curl_close($resource);
     $user = json_decode($result);
     $openid = $user->openid;
     $mod = Model::getInstance('Account', 'member');
     $ret = $mod->extlogin(DataAccount::PARTNER_WECHAT, $openid);
     if ($ret['err_no'] === DataAccount::SUCCESS_LOGIN_NUM) {
         $httpReferer = HttpCookie::get('http_referer', 'index.php');
         HttpCookie::remove('http_referer');
         Ap::getResponse()->location($httpReferer);
     } else {
         Ap::getResponse()->location('index.php?r=member/show/login');
     }
 }
Example #5
0
 /**
  * 页面重定向到指定的链接
  * @param string $url
  * @param string $message
  * @param integer $delay
  * @return void
  */
 public function redirect($url, $message = '', $delay = 0)
 {
     Ap::getResponse()->redirect($url, $message, $delay);
     exit;
 }
Example #6
0
 /**
  * 通过表Metadata生成Builders数据
  * @param string $tblName
  * @return void
  */
 public function gb($tblName)
 {
     Ap::getResponse()->contentType();
     $tableNames = $this->_metadata->getTableNames($tblName);
     if (!in_array($tblName, $tableNames)) {
         Log::errExit(__LINE__, 'Table Name Not Exists!');
     }
     Log::echoTrace('Generate Begin, Table Name "' . $tblName . '"');
     $tableSchema = $this->_metadata->getTableSchema($tblName);
     $comments = $this->_metadata->getComments($tableSchema->name);
     $tblPrefix = $this->getDbProxy()->getTblprefix();
     $tblPreLen = strlen($tblPrefix);
     Log::echoTrace('Import to builders Begin ...');
     $params = array('builder_name' => isset($comments['__table__']) ? $comments['__table__'] : $tableSchema->name, 'tbl_name' => substr($tableSchema->name, $tblPreLen), 'tbl_profile' => DataBuilders::TBL_PROFILE_N, 'tbl_engine' => DataBuilders::TBL_ENGINE_INNODB, 'tbl_charset' => DataBuilders::TBL_CHARSET_UTF8, 'tbl_comment' => isset($comments['__table__']) ? $comments['__table__'] : '', 'srv_type' => DataBuilders::SRV_TYPE_NORMAL, 'srv_name' => 'undefined', 'app_name' => 'administrator', 'mod_name' => 'undefined', 'ctrl_name' => substr($tableSchema->name, strrpos($tableSchema->name, '_') + 1), 'cls_name' => substr($tableSchema->name, strrpos($tableSchema->name, '_') + 1), 'fk_column' => '', 'act_index_name' => 'index', 'act_view_name' => 'view', 'act_create_name' => 'create', 'act_modify_name' => 'modify', 'act_remove_name' => 'remove', 'index_row_btns' => array(DataBuilders::INDEX_ROW_BTNS_PENCIL, DataBuilders::INDEX_ROW_BTNS_REMOVE), 'description' => '', 'author_name' => UserIdentity::getNick(), 'author_mail' => UserIdentity::getName());
     $mod = Service::getInstance('Builders', $this->_srvName);
     $builderId = $mod->create($params);
     if ($builderId > 0) {
         Log::echoTrace('Import to builders Successfully ...');
     } else {
         $errors = $mod->getErrors();
         Log::errExit(__LINE__, 'Import to builders Failed! ' . serialize($errors));
     }
     Log::echoTrace('Import to builder_fields Begin ...');
     $sort = 0;
     foreach ($tableSchema->columns as $columnSchema) {
         $sort++;
         if ($columnSchema->type === 'integer') {
             $columnLength = $columnSchema->size;
         } elseif (stripos($columnSchema->dbType, 'enum') !== false) {
             $columnLength = str_replace(array('\'', ','), array('', '|'), substr(substr($columnSchema->dbType, 5), 0, -1));
         } elseif (stripos($columnSchema->dbType, 'char') !== false) {
             $columnLength = $columnSchema->size;
         } else {
             $columnLength = '';
         }
         if ($columnSchema->isPrimaryKey) {
             $formRequired = DataFields::FORM_REQUIRED_N;
         } elseif (stripos($columnSchema->dbType, 'enum') !== false) {
             $formRequired = DataFields::FORM_REQUIRED_N;
         } else {
             $formRequired = DataFields::FORM_REQUIRED_Y;
         }
         if ($columnLength === 'y|n') {
             $typeId = 4;
         } elseif (stripos($columnSchema->dbType, 'enum') !== false) {
             $typeId = 5;
         } elseif ($columnSchema->isPrimaryKey) {
             $typeId = 9;
         } elseif ($columnSchema->type === 'integer') {
             $typeId = 2;
         } elseif (in_array($columnSchema->dbType, array('text', 'longtext'))) {
             $typeId = 10;
         } else {
             $typeId = 1;
         }
         $params = array('field_name' => $columnSchema->name, 'column_length' => $columnLength, 'column_auto_increment' => $columnSchema->isAutoIncrement ? DataFields::COLUMN_AUTO_INCREMENT_Y : DataFields::COLUMN_AUTO_INCREMENT_N, 'column_unsigned' => stripos($columnSchema->dbType, 'unsigned') !== false ? DataFields::COLUMN_UNSIGNED_Y : DataFields::COLUMN_UNSIGNED_N, 'column_comment' => isset($comments[$columnSchema->name]) ? $comments[$columnSchema->name] : '', 'builder_id' => $builderId, 'group_id' => 1, 'type_id' => $typeId, 'sort' => $sort, 'html_label' => isset($comments[$columnSchema->name]) ? $comments[$columnSchema->name] : $columnSchema->name, 'form_prompt' => '', 'form_required' => $formRequired, 'form_modifiable' => DataFields::FORM_MODIFIABLE_N, 'index_show' => DataFields::INDEX_SHOW_Y, 'index_sort' => $columnSchema->isPrimaryKey ? 1000 : $sort, 'form_create_show' => $columnSchema->isPrimaryKey ? DataFields::FORM_CREATE_SHOW_N : DataFields::FORM_CREATE_SHOW_Y, 'form_create_sort' => $sort, 'form_modify_show' => $columnSchema->isPrimaryKey ? DataFields::FORM_MODIFY_SHOW_N : DataFields::FORM_MODIFY_SHOW_Y, 'form_modify_sort' => $sort, 'form_search_show' => DataFields::FORM_SEARCH_SHOW_Y, 'form_search_sort' => $sort);
         $mod = Service::getInstance('Fields', $this->_srvName);
         $fieldId = $mod->create($params);
         if ($fieldId > 0) {
             Log::echoTrace('Import to builder_fields "' . $columnSchema->name . '" Successfully ...');
         } else {
             $errors = $mod->getErrors();
             Log::errExit(__LINE__, 'Import to builder_fields "' . $columnSchema->name . '" Failed! ' . serialize($errors));
         }
     }
     Log::echoTrace('Import to builder_fields Successfully ...');
     Log::echoTrace('Generate End, Table Name "' . $tblName . '"');
     exit;
 }
Example #7
0
 /**
  * 测试打印数据,只有DEBUG或者强制的时候才输出
  * @param mixed $expression
  * @param boolean $coercion
  * @return void
  */
 function debug_print_r($expression, $coercion = false)
 {
     if (DEBUG || $coercion) {
         $response = \tfc\ap\Ap::getResponse();
         if (!$response->headersSent()) {
             $response->contentType('text/html', \tfc\ap\Ap::getEncoding());
         }
         echo '<pre>';
         print_r($expression);
         echo '</pre>';
         exit;
     }
 }