初始化代码
This commit is contained in:
32
app/index/common.php
Normal file
32
app/index/common.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
// 这是系统自动生成的index应用公共文件
|
||||
//通过Token获取用户信息
|
||||
|
||||
|
||||
//删除用户登录信息
|
||||
function delUserForToken($token) {
|
||||
return delCache("Token_".$token);
|
||||
}
|
||||
|
||||
//生成token
|
||||
function longbingCreateToken() {
|
||||
return uuid();
|
||||
}
|
||||
|
||||
//检查密码是否正确
|
||||
function longbingCheckPasswd(string $passwd ,string $offset ,string $hash) {
|
||||
//检查秘钥是否正确
|
||||
return password_verify($offset . $passwd . $offset ,$hash);
|
||||
}
|
||||
|
||||
//获取缓存数据中的 accounts 列表
|
||||
function getAccountList($uniacid = 7777){
|
||||
//获取缓存数据
|
||||
$result = getCache('accounts_' . $uniacid);
|
||||
// var_dump(getCache('accounts_7777'));die;
|
||||
//数据存在返回数据
|
||||
if(!empty($result)) return $result;
|
||||
//缓存数据不存在时,从数据库获取数据,同时写入缓存
|
||||
|
||||
return $result;
|
||||
}
|
||||
74
app/index/controller/Index.php
Normal file
74
app/index/controller/Index.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/*
|
||||
* @Description:
|
||||
* @Author: xiao li
|
||||
* @Date: 2021-12-10 14:00:31
|
||||
* @LastEditTime: 2022-03-15 23:27:39
|
||||
* @LastEditors: xiao li
|
||||
*/
|
||||
namespace app\index\controller;
|
||||
use think\facade\View;
|
||||
class Index
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$timestamp = '?v=' . time();
|
||||
$is_we7 = defined('IS_WEIQIN') ? true : false;
|
||||
$appcss = $is_we7 ? '/addons/'. APP_MODEL_NAME .'/core2/public/static/css/app.css' : '/static/css/app.css';
|
||||
$manifest = $is_we7 ? '/addons/'.APP_MODEL_NAME.'/core2/public/static/js/manifest.js' : '/static/js/manifest.js';
|
||||
$vendor = $is_we7 ? '/addons/'.APP_MODEL_NAME.'/core2/public/static/js/vendor.js' : '/static/js/vendor.js';
|
||||
$app = $is_we7 ? '/addons/'.APP_MODEL_NAME .'/core2/public/static/js/app.js' : '/static/js/app.js';
|
||||
$jsPath = $is_we7 ? '/addons/'.APP_MODEL_NAME .'/core2/public/' : '/';
|
||||
|
||||
$jsMin = $is_we7 ? '/addons/'.APP_MODEL_NAME .'/core2/public/js/jquery.min.js' : '/js/jquery.min.js';
|
||||
|
||||
$jsPdf = $is_we7 ? '/addons/'.APP_MODEL_NAME .'/core2/public/js/pdf.js' : '/js/pdf.js';
|
||||
|
||||
$jsWorker= $is_we7 ? '/addons/'.APP_MODEL_NAME .'/core2/public/js/pdf.worker.js' : '/js/pdf.worker.js';
|
||||
|
||||
$jsVueMin = $is_we7 ? '/addons/'.APP_MODEL_NAME .'/core2/public/js/vue.min.js' : '/js/vue.min.js';
|
||||
|
||||
$jsVuexMin = $is_we7 ? '/addons/'.APP_MODEL_NAME .'/core2/public/js/vuex.min.js' : '/js/vuex.min.js';
|
||||
|
||||
$jsMmin = $is_we7 ? '/addons/'.APP_MODEL_NAME .'/core2/public/js/moment.min.js' : '/js/moment.min.js';
|
||||
|
||||
$jsIndexMin = $is_we7 ? '/addons/'.APP_MODEL_NAME .'/core2/public/js/index.min.js' : '/js/index.min.js';
|
||||
|
||||
$jsMincss = $is_we7 ? '/addons/'.APP_MODEL_NAME .'/core2/public/js/index.min.css' : '/js/index.min.css';
|
||||
|
||||
$jsNcss = $is_we7 ? '/addons/'.APP_MODEL_NAME .'/core2/public/js/nprogress.min.css' : '/js/nprogress.min.css';
|
||||
global $_W;
|
||||
$is_founder = isset($_W['isfounder']) ? $_W['isfounder'] : false;
|
||||
|
||||
View::assign('jsPath', $jsPath);
|
||||
|
||||
View::assign('jsMin', $jsMin);
|
||||
|
||||
View::assign('jsPdf', $jsPdf);
|
||||
|
||||
View::assign('jsWorker', $jsWorker);
|
||||
|
||||
View::assign('jsVueMin', $jsVueMin);
|
||||
|
||||
View::assign('jsVuexMin', $jsVuexMin);
|
||||
|
||||
View::assign('jsMmin', $jsMmin);
|
||||
|
||||
View::assign('jsIndexMin', $jsIndexMin);
|
||||
|
||||
View::assign('jsMincss', $jsMincss);
|
||||
|
||||
View::assign('jsNcss', $jsNcss);
|
||||
|
||||
View::assign('is_founder', $is_founder);
|
||||
View::assign('isWe7', $is_we7);
|
||||
View::assign('appcss', $appcss.$timestamp);
|
||||
View::assign('manifest', $manifest .$timestamp);
|
||||
View::assign('vendor', $vendor .$timestamp );
|
||||
View::assign('app', $app . $timestamp);
|
||||
|
||||
//var_dump(View());die;
|
||||
return View::fetch();
|
||||
// return View::engine('think')->fetch('index');
|
||||
}
|
||||
}
|
||||
420
app/index/controller/Login.php
Normal file
420
app/index/controller/Login.php
Normal file
@@ -0,0 +1,420 @@
|
||||
<?php
|
||||
|
||||
namespace app\index\controller;
|
||||
|
||||
use app\baidu\model\AdminSetting;
|
||||
|
||||
use app\farm\model\User;
|
||||
use app\massage\model\CouponAtv;
|
||||
use app\redbag\model\Invitation;
|
||||
use app\restaurant\model\ClassDate;
|
||||
use Exception;
|
||||
use longbingcore\tools\LongbingDefault;
|
||||
use think\App;
|
||||
use think\facade\Db;
|
||||
use think\Response;
|
||||
use app\baidu\model\AdminActive;
|
||||
|
||||
class Login
|
||||
{
|
||||
// 小程序登陆每个用户产生的唯一表示
|
||||
protected $code = '';
|
||||
|
||||
protected $uniacid;
|
||||
protected $request;
|
||||
protected $_param;
|
||||
protected $_input;
|
||||
|
||||
function __construct(App $app)
|
||||
{
|
||||
global $_GPC, $_W;
|
||||
|
||||
$this->request = $app->request;
|
||||
//获取param
|
||||
$this->_param = $this->request->param();
|
||||
|
||||
$this->_input = json_decode($this->request->getInput(), true);
|
||||
//获取uniacid
|
||||
if (!isset($this->_param['i']) || !$this->_param['i']) {
|
||||
|
||||
return $this->error('need uniacid',400);
|
||||
}
|
||||
|
||||
$this->uniacid = $this->_param['i'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-17 10:06
|
||||
* @功能说明:小程序用户登陆接口
|
||||
*/
|
||||
function index()
|
||||
{
|
||||
$input = $this->_param;
|
||||
|
||||
if (!isset($this->_param['code']) || !$this->_param['code']) {
|
||||
|
||||
return $this->error(['code' => 400, 'error' => 'need code']);
|
||||
|
||||
}
|
||||
|
||||
$cap_id = !empty($input['cap_id'])?$input['cap_id']:0;
|
||||
|
||||
$code = $this->_param['code'];
|
||||
// 是否是微擎
|
||||
$config = longbingGetAppConfig($this->uniacid);
|
||||
|
||||
$appid = $config['appid'];
|
||||
|
||||
$appsecret = $config['appsecret'];
|
||||
// 从微信获取openid等
|
||||
$url = "https://api.weixin.qq.com/sns/jscode2session?appid={$appid}&secret={$appsecret}&js_code={$code}&grant_type=authorization_code";
|
||||
|
||||
$arrContextOptions = array(
|
||||
|
||||
"ssl"=>array(
|
||||
|
||||
"verify_peer" => false,
|
||||
|
||||
"verify_peer_name"=> false,
|
||||
),
|
||||
);
|
||||
|
||||
$info = file_get_contents($url ,false, stream_context_create($arrContextOptions));
|
||||
|
||||
$info = @json_decode($info, true);
|
||||
// 微信端返回错误
|
||||
if (isset($info['errcode'])) {
|
||||
|
||||
return $this->error($info['errcode'] . ', errmsg: ' . $info['errmsg']);
|
||||
|
||||
}
|
||||
if (!isset($info['session_key'])) {
|
||||
|
||||
return $this->error('session_key not exists','402');
|
||||
|
||||
}
|
||||
|
||||
if(empty($info['openid'])){
|
||||
|
||||
return $this->error('openid not exists');
|
||||
|
||||
}
|
||||
|
||||
$user_model = new User();
|
||||
|
||||
$dis = [
|
||||
|
||||
'openid' => $info['openid'],
|
||||
|
||||
'uniacid' => $this->uniacid
|
||||
|
||||
];
|
||||
|
||||
$user_info = $user_model->dataInfo($dis);
|
||||
|
||||
if(empty($user_info)){
|
||||
|
||||
try {
|
||||
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $this->uniacid,
|
||||
|
||||
'openid' => $info['openid'],
|
||||
|
||||
'cap_id' => $cap_id,
|
||||
|
||||
'session_key' => $info['session_key'],
|
||||
|
||||
|
||||
];
|
||||
|
||||
if(!empty($input['pid'])){
|
||||
|
||||
$insert['pid'] = $input['pid'];
|
||||
}
|
||||
|
||||
$user_model->dataAdd($insert);
|
||||
|
||||
}catch(Exception $e)
|
||||
{}
|
||||
|
||||
// $user_id = $user_model->getLastInsID();
|
||||
|
||||
$user_info = $user_model->dataInfo($insert);
|
||||
|
||||
|
||||
}else{
|
||||
|
||||
$user_model->dataUpdate(['id'=>$user_info['id']],['session_key'=>$info['session_key']]);
|
||||
}
|
||||
|
||||
$key = 'longbing_user_autograph_' . $user_info['id'];
|
||||
|
||||
$key = md5($key);
|
||||
|
||||
setCache($key, $user_info, 7200, $this->uniacid);
|
||||
|
||||
$arr = [
|
||||
|
||||
'data' => $user_info,
|
||||
|
||||
'autograph' => $key
|
||||
];
|
||||
|
||||
return $this->success($arr);
|
||||
|
||||
}
|
||||
|
||||
//返回成功
|
||||
public function success($data, $code = 200)
|
||||
{
|
||||
$result['data'] = $data;
|
||||
$result['code'] = $code;
|
||||
$result['sign'] = null;
|
||||
|
||||
return $this->response($result, 'json', $code);
|
||||
}
|
||||
|
||||
//返回错误数据
|
||||
public function error($msg, $code = 400)
|
||||
{
|
||||
$result['error'] = $msg;
|
||||
$result['code'] = $code;
|
||||
return $this->response($result, 'json', $code);
|
||||
}
|
||||
|
||||
//response
|
||||
protected function response($data, $type = 'json', $code = 200)
|
||||
{
|
||||
return Response::create($data, $type)->code($code);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-17 10:06
|
||||
* @功能说明:微信登陆
|
||||
*/
|
||||
function appLogin()
|
||||
{
|
||||
$input = $this->_input;
|
||||
|
||||
$uniacid = $this->uniacid;
|
||||
|
||||
$input = $input['data'];
|
||||
|
||||
$cap_id = !empty($input['cap_id'])?$input['cap_id']:0;
|
||||
|
||||
$user_model = new User();
|
||||
|
||||
$dis = [
|
||||
|
||||
'unionid' => $input['unionId'],
|
||||
|
||||
];
|
||||
|
||||
$user_info = $user_model->dataInfo($dis);
|
||||
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $uniacid,
|
||||
|
||||
'nickName' => $input['nickName'],
|
||||
|
||||
'avatarUrl'=> $input['avatarUrl'],
|
||||
|
||||
'unionid' => $input['unionId'],
|
||||
|
||||
'gender' => $input['gender'],
|
||||
|
||||
'city' => $input['city'],
|
||||
|
||||
'province' => $input['province'],
|
||||
|
||||
'country' => $input['country'],
|
||||
|
||||
'openid' => $input['openId'],
|
||||
|
||||
'app_openid' => $input['openId'],
|
||||
|
||||
'push_id' => !empty($input['push_id'])?$input['push_id']:'',
|
||||
|
||||
'cap_id' => $cap_id,
|
||||
|
||||
'last_login_type' => 1,
|
||||
|
||||
];
|
||||
|
||||
if(empty($user_info)){
|
||||
|
||||
if(!empty($input['pid'])){
|
||||
|
||||
$insert['pid'] = $input['pid'];
|
||||
}
|
||||
|
||||
$user_model->dataAdd($insert);
|
||||
|
||||
$user_id = $user_model->getLastInsID();
|
||||
|
||||
}else{
|
||||
|
||||
$user_id = $user_info['id'];
|
||||
|
||||
$user_model->dataUpdate(['id'=>$user_id],$insert);
|
||||
|
||||
}
|
||||
|
||||
$user_info = $user_model->dataInfo(['id'=>$user_id]);
|
||||
|
||||
$key = 'longbing_user_autograph_' . $user_info['id'];
|
||||
|
||||
$key = md5($key);
|
||||
|
||||
setCache($key, $user_info, 7200, $this->uniacid);
|
||||
|
||||
$arr = [
|
||||
|
||||
'data' => $user_info,
|
||||
|
||||
'autograph' => $key
|
||||
];
|
||||
|
||||
return $this->success($arr);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2021-03-17 10:06
|
||||
* @功能说明:ios登陆
|
||||
*/
|
||||
function iosLogin()
|
||||
{
|
||||
$input = $this->_input;
|
||||
|
||||
$uniacid = $this->uniacid;
|
||||
|
||||
$input = $input['data'];
|
||||
|
||||
$cap_id = !empty($input['cap_id'])?$input['cap_id']:0;
|
||||
|
||||
$user_model = new User();
|
||||
|
||||
$dis = [
|
||||
|
||||
'openid' => $input['openId'],
|
||||
|
||||
];
|
||||
|
||||
$user_info = $user_model->dataInfo($dis);
|
||||
|
||||
$familyName = !empty($input['fullName']['familyName'])?$input['fullName']['familyName']:'';
|
||||
|
||||
$giveName = !empty($input['fullName']['giveName'])?$input['fullName']['giveName']:'';
|
||||
|
||||
$name = !empty($familyName.$giveName)?$familyName.$giveName:'默认用户';
|
||||
|
||||
$insert = [
|
||||
|
||||
'uniacid' => $uniacid,
|
||||
|
||||
'nickName' => $name,
|
||||
|
||||
'avatarUrl'=> 'https://lbqny.migugu.com/admin/farm/default-user.png',
|
||||
|
||||
// 'unionid' => $input['unionId'],
|
||||
//
|
||||
// 'gender' => $input['gender'],
|
||||
//
|
||||
// 'city' => $input['city'],
|
||||
//
|
||||
// 'province' => $input['province'],
|
||||
//
|
||||
// 'country' => $input['country'],
|
||||
|
||||
'openid' => $input['openId'],
|
||||
|
||||
//'app_openid' => $input['openId'],
|
||||
|
||||
'push_id' => !empty($input['push_id'])?$input['push_id']:'',
|
||||
|
||||
'cap_id' => $cap_id,
|
||||
|
||||
'last_login_type' => 1,
|
||||
|
||||
];
|
||||
|
||||
if(empty($user_info)){
|
||||
|
||||
if(!empty($input['pid'])){
|
||||
|
||||
$insert['pid'] = $input['pid'];
|
||||
}
|
||||
|
||||
$user_model->dataAdd($insert);
|
||||
|
||||
$user_id = $user_model->getLastInsID();
|
||||
|
||||
}else{
|
||||
|
||||
$user_id = $user_info['id'];
|
||||
|
||||
$user_model->dataUpdate(['id'=>$user_id],$insert);
|
||||
|
||||
}
|
||||
|
||||
$user_info = $user_model->dataInfo(['id'=>$user_id]);
|
||||
|
||||
$key = 'longbing_user_autograph_' . $user_info['id'];
|
||||
|
||||
$key = md5($key);
|
||||
|
||||
setCache($key, $user_info, 7200, $this->uniacid);
|
||||
|
||||
$arr = [
|
||||
|
||||
'data' => $user_info,
|
||||
|
||||
'autograph' => $key
|
||||
];
|
||||
|
||||
return $this->success($arr);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @author chenniang
|
||||
* @DataTime: 2022-08-10 18:30
|
||||
* @功能说明:
|
||||
*/
|
||||
public function getConfig(){
|
||||
|
||||
$config = longbingGetAppConfig($this->uniacid);
|
||||
|
||||
$data['login_protocol'] = $config['login_protocol'];
|
||||
|
||||
$data['app_text'] = $config['app_text'];
|
||||
|
||||
$data['app_logo'] = $config['app_logo'];
|
||||
|
||||
$data['ios_login'] = $config['ios_login'];
|
||||
|
||||
$data['information_protection'] = $config['information_protection'];
|
||||
|
||||
$data['app_banner'] = $config['app_banner'];
|
||||
|
||||
return $this->success($data);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
5
app/index/event.php
Normal file
5
app/index/event.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
// 这是系统自动生成的index应用event定义文件
|
||||
return [
|
||||
|
||||
];
|
||||
16
app/index/lang/zh-cn.php
Normal file
16
app/index/lang/zh-cn.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
return [
|
||||
'hello thinkphp' => '欢迎使用ThinkPHP',
|
||||
'data type error' => '数据类型错误',
|
||||
'test' => '你好啊',
|
||||
'picture' => '图片',
|
||||
'audio' => '音频',
|
||||
'vedio' => '视频',
|
||||
'Hello, I am ' => '您好,我是',
|
||||
', May I help you? Please contact me!' => ',有什么可以帮到您的吗?记得联系我!',
|
||||
'not chat id ,please check param' => '没有关系数据,请检查传入参数。',
|
||||
'my reply' => '自定义话术',
|
||||
'login error' => '登陆失败',
|
||||
'invalid appid, hints: [ req_id: EIEEn_4ce-R.HZBA ]' => 'AppId填写错误, 请检查后充填',
|
||||
'invalid appsecret, view more at http://t.cn/RAEkdVq, hints: [ req_id: fIEEs.5ce-IRwLUa ]' => 'AppSecret填写错误, 请检查后充填',
|
||||
];
|
||||
5
app/index/middleware.php
Normal file
5
app/index/middleware.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
// 这是系统自动生成的index应用middleware定义文件
|
||||
return [
|
||||
|
||||
];
|
||||
5
app/index/provider.php
Normal file
5
app/index/provider.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
// 这是系统自动生成的index应用provider定义文件
|
||||
return [
|
||||
|
||||
];
|
||||
14
app/index/route/route.php
Normal file
14
app/index/route/route.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
use think\facade\Route;
|
||||
/**
|
||||
* @model index
|
||||
* @author yangqi
|
||||
* @create time 2019年11月25日23:09:59
|
||||
*
|
||||
*/
|
||||
Route::get('/', 'index/index');
|
||||
Route::post('login', 'login/index');
|
||||
Route::post('logappLoginin', 'login/appLogin');
|
||||
Route::post('iosLogin', 'login/iosLogin');
|
||||
Route::get('getConfig', 'login/getConfig');
|
||||
|
||||
38
app/index/view/index/index.html
Normal file
38
app/index/view/index/index.html
Normal file
@@ -0,0 +1,38 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<meta name="renderer" content="webkit"/>
|
||||
<meta name="force-rendering" content="webkit"/>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"/>
|
||||
<meta name=viewport content="width=device-width,initial-scale=1">
|
||||
<title>登录 - 后台管理中心</title>
|
||||
<link href='{$appcss}' rel=stylesheet>
|
||||
<script type="text/javascript" src='{$jsMin}'></script>
|
||||
<script type="text/javascript" src="{$jsPdf}"></script>
|
||||
<script type="text/javascript" src="{$jsWorker}"></script>
|
||||
|
||||
<script src="{$jsVueMin}"></script>
|
||||
<script src="{$jsVuexMin}"></script>
|
||||
<script src="{$jsMmin}"></script>
|
||||
<script src="{$jsIndexMin}"></script>
|
||||
<!-- 引入样式 -->
|
||||
<link href="{$jsMincss}" rel="stylesheet">
|
||||
<link href="{$jsNcss}" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<div id=app></div>
|
||||
<script>
|
||||
var lbConfig = {
|
||||
jsPath: '{$jsPath}',
|
||||
isWe7: '{$isWe7}',
|
||||
is_founder: '{$is_founder}'
|
||||
}
|
||||
window.lbConfig = lbConfig;
|
||||
</script>
|
||||
<script type=text/javascript src='{$manifest}'></script>
|
||||
<script type=text/javascript src='{$vendor}'></script>
|
||||
<script type=text/javascript src='{$app}'></script>
|
||||
<script charset=utf-8 src="https://map.qq.com/api/js?v=2.exp&key=2LNBZ-HT2R2-LENUE-CBNZK-QZ4VS-AQB5Z"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user