Browse Source

初始化

master
jianglong 3 years ago
parent
commit
0c1dad9bdb
  1. 8
      .htaccess
  2. 7
      404.html
  3. 1
      addons/.gitkeep
  4. 1
      addons/.htaccess
  5. 1
      addons/alisms/.addonrc
  6. 86
      addons/alisms/Alisms.php
  7. 73
      addons/alisms/config.php
  8. 73
      addons/alisms/controller/Index.php
  9. 10
      addons/alisms/info.ini
  10. 170
      addons/alisms/library/Alisms.php
  11. 62
      addons/alisms/view/index/index.html
  12. 2
      addons/qingdong/model/Staff.php
  13. 17
      application/admin/controller/Index.php
  14. 2
      application/admin/controller/auth/Admin.php
  15. 2
      application/admin/library/Auth.php
  16. 2
      application/admin/validate/Admin.php
  17. 16
      application/common/controller/Backend.php
  18. 2
      application/config.php
  19. 9
      application/extra/addons.php
  20. 2
      application/extra/site.php
  21. 4
      extend/fast/Auth.php
  22. 39
      index.html
  23. 2
      public/assets/js/require-backend.js
  24. 2
      route/app.php

8
.htaccess

@ -0,0 +1,8 @@
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
</IfModule>

7
404.html

@ -0,0 +1,7 @@
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx</center>
</body>
</html>

1
addons/.gitkeep

@ -0,0 +1 @@

1
addons/.htaccess

@ -0,0 +1 @@
deny from all

1
addons/alisms/.addonrc

@ -0,0 +1 @@
{"files":[],"license":"regular","licenseto":"48387","licensekey":"Pfv3uGdOlHY9JkNs ipSrRrVAtDrrRKmg6Qwqnw==","domains":["iiixo.com"],"licensecodes":[],"validations":["8c705a04d965d13dbbabb413e876acfd"]}

86
addons/alisms/Alisms.php

@ -0,0 +1,86 @@
<?php
namespace addons\alisms;
use think\Addons;
/**
* Alisms
*/
class Alisms extends Addons
{
/**
* 插件安装方法
* @return bool
*/
public function install()
{
return true;
}
/**
* 插件卸载方法
* @return bool
*/
public function uninstall()
{
return true;
}
/**
* 短信发送行为
* @param array $params 必须包含mobile,event,code
* @return boolean
*/
public function smsSend(&$params)
{
$config = get_addon_config('alisms');
if (!isset($config['template'][$params['event']])) {
return false;
}
$alisms = new \addons\alisms\library\Alisms();
$result = $alisms->mobile($params['mobile'])
->template($config['template'][$params['event']])
->param(['code' => $params['code']])
->send();
return $result;
}
/**
* 短信发送通知
* @param array $params 必须包含 mobile,event,msg
* @return boolean
*/
public function smsNotice(&$params)
{
$config = get_addon_config('alisms');
$alisms = \addons\alisms\library\Alisms::instance();
if (isset($params['msg'])) {
if (is_array($params['msg'])) {
$param = $params['msg'];
} else {
parse_str($params['msg'], $param);
}
} else {
$param = [];
}
$param = $param ? $param : [];
$params['template'] = isset($params['template']) ? $params['template'] : (isset($params['event']) && isset($config['template'][$params['event']]) ? $config['template'][$params['event']] : '');
$result = $alisms->mobile($params['mobile'])
->template($params['template'])
->param($param)
->send();
return $result;
}
/**
* 检测验证是否正确
* @param $params
* @return boolean
*/
public function smsCheck(&$params)
{
return true;
}
}

73
addons/alisms/config.php

@ -0,0 +1,73 @@
<?php
return [
[
'name' => 'key',
'title' => '应用key',
'type' => 'string',
'content' => [],
'value' => 'LTAI5t8WhSffm9KteMHriC8k',
'rule' => 'required',
'msg' => '',
'tip' => '',
'ok' => '',
'extend' => '',
],
[
'name' => 'secret',
'title' => '密钥secret',
'type' => 'string',
'content' => [],
'value' => 'hSnnKORIhdxycXZpCx92wjHM6x92aZ',
'rule' => 'required',
'msg' => '',
'tip' => '',
'ok' => '',
'extend' => '',
],
[
'name' => 'sign',
'title' => '签名',
'type' => 'string',
'content' => [],
'value' => '博创',
'rule' => 'required',
'msg' => '',
'tip' => '',
'ok' => '',
'extend' => '',
],
[
'name' => 'template',
'title' => '短信模板',
'type' => 'array',
'content' => [],
'value' => [
'register' => 'SMS_461540415',
'resetpwd' => 'SMS_114000000',
'changepwd' => 'SMS_114000000',
'changemobile' => 'SMS_114000000',
'profile' => 'SMS_114000000',
'notice' => 'SMS_114000000',
'mobilelogin' => 'SMS_114000000',
'bind' => 'SMS_114000000',
],
'rule' => 'required',
'msg' => '',
'tip' => '',
'ok' => '',
'extend' => '',
],
[
'name' => '__tips__',
'title' => '温馨提示',
'type' => 'string',
'content' => [],
'value' => '应用key和密钥你可以通过 https://ak-console.aliyun.com/?spm=a2c4g.11186623.2.13.fd315777PX3tjy#/accesskey 获取',
'rule' => 'required',
'msg' => '',
'tip' => '',
'ok' => '',
'extend' => '',
],
];

73
addons/alisms/controller/Index.php

@ -0,0 +1,73 @@
<?php
namespace addons\alisms\controller;
use think\addons\Controller;
/**
* 阿里短信
*/
class Index extends Controller
{
protected $model = null;
protected $templateList = [
'register' => '注册',
'resetpwd' => '重置密码',
'changepwd' => '修改密码',
'changemobile' => '修改手机号',
'profile' => '修改个人信息',
'notice' => '通知',
'mobilelogin' => '移动端登录',
'bind' => '绑定账号',
];
public function _initialize()
{
if (!\app\admin\library\Auth::instance()->id) {
$this->error('暂无权限浏览');
}
parent::_initialize();
}
//首页
public function index()
{
$this->view->assign('templateList', $this->templateList);
return $this->view->fetch();
}
//发送测试短信
public function send()
{
$config = get_addon_config('alisms');
$mobile = $this->request->post('mobile');
$template = $this->request->post('template');
$sign = $this->request->post('sign', '');
if (!$mobile) {
$this->error('手机号不能为空');
}
$templateArr = $config['template'] ?? [];
if (!isset($templateArr[$template]) || !$templateArr[$template]) {
$this->error('后台未配置对应的模板CODE');
}
$template = $templateArr[$template];
$sign = $sign ? $sign : $config['sign'];
$param = (array)json_decode($this->request->post('param', '', 'trim'));
$param = ['code' => mt_rand(1000, 9999)];
$alisms = new \addons\alisms\library\Alisms();
$ret = $alisms->mobile($mobile)
->template($template)
->sign($sign)
->param($param)
->send();
if ($ret) {
$this->success("发送成功");
} else {
$this->error("发送失败!失败原因:" . $alisms->getError());
}
}
}

10
addons/alisms/info.ini

@ -0,0 +1,10 @@
name = alisms
title = 阿里云短信发送
intro = 阿里云短信发送插件
author = FastAdmin
website = https://www.fastadmin.net
version = 1.0.10
state = 1
url = /addons/alisms
license = regular
licenseto = 48387

170
addons/alisms/library/Alisms.php

@ -0,0 +1,170 @@
<?php
namespace addons\alisms\library;
/**
* 阿里大于SMS短信发送
*/
class Alisms
{
private $_params = [];
public $error = '';
protected $config = [];
protected static $instance;
public function __construct($options = [])
{
if ($config = get_addon_config('alisms')) {
$this->config = array_merge($this->config, $config);
}
$this->config = array_merge($this->config, is_array($options) ? $options : []);
}
/**
* 单例
* @param array $options 参数
* @return Alisms
*/
public static function instance($options = [])
{
if (is_null(self::$instance)) {
self::$instance = new static($options);
}
return self::$instance;
}
/**
* 设置签名
* @param string $sign
* @return Alisms
*/
public function sign($sign = '')
{
$this->_params['SignName'] = $sign;
return $this;
}
/**
* 设置参数
* @param array $param
* @return Alisms
*/
public function param(array $param = [])
{
foreach ($param as $k => &$v) {
$v = (string)$v;
}
unset($v);
$param = array_filter($param);
$this->_params['TemplateParam'] = $param ? json_encode($param) : '{}';
return $this;
}
/**
* 设置模板
* @param string $code 短信模板
* @return Alisms
*/
public function template($code = '')
{
$this->_params['TemplateCode'] = $code;
return $this;
}
/**
* 接收手机
* @param string $mobile 手机号码
* @return Alisms
*/
public function mobile($mobile = '')
{
$this->_params['PhoneNumbers'] = $mobile;
return $this;
}
/**
* 立即发送
* @return boolean
*/
public function send()
{
$this->error = '';
$params = $this->_params();
$params['Signature'] = $this->_signed($params);
$response = $this->_curl($params);
if ($response !== false) {
$res = (array)json_decode($response, true);
if (isset($res['Code']) && $res['Code'] == 'OK') {
return true;
}
$this->error = isset($res['Message']) ? $res['Message'] : 'InvalidResult';
} else {
$this->error = 'InvalidResult';
}
return false;
}
/**
* 获取错误信息
* @return string
*/
public function getError()
{
return $this->error;
}
private function _params()
{
return array_merge([
'AccessKeyId' => $this->config['key'],
'SignName' => isset($this->config['sign']) ? $this->config['sign'] : '',
'Action' => 'SendSms',
'Format' => 'JSON',
'Version' => '2017-05-25',
'SignatureVersion' => '1.0',
'SignatureMethod' => 'HMAC-SHA1',
'SignatureNonce' => uniqid(),
'Timestamp' => gmdate('Y-m-d\TH:i:s\Z'),
], $this->_params);
}
private function percentEncode($string)
{
$string = urlencode($string);
$string = preg_replace('/\+/', '%20', $string);
$string = preg_replace('/\*/', '%2A', $string);
$string = preg_replace('/%7E/', '~', $string);
return $string;
}
private function _signed($params)
{
$sign = $this->config['secret'];
ksort($params);
$canonicalizedQueryString = '';
foreach ($params as $key => $value) {
$canonicalizedQueryString .= '&' . $this->percentEncode($key) . '=' . $this->percentEncode($value);
}
$stringToSign = 'GET&%2F&' . $this->percentencode(substr($canonicalizedQueryString, 1));
$signature = base64_encode(hash_hmac('sha1', $stringToSign, $sign . '&', true));
return $signature;
}
private function _curl($params)
{
$uri = 'http://dysmsapi.aliyuncs.com/?' . http_build_query($params);
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_URL, $uri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.98 Safari/537.36");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$reponse = curl_exec($ch);
curl_close($ch);
return $reponse;
}
}

62
addons/alisms/view/index/index.html

@ -0,0 +1,62 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<title>阿里云短信发送示例 - {$site.name}</title>
<!-- Bootstrap Core CSS -->
<link href="__CDN__/assets/libs/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="__CDN__/assets/css/frontend.min.css" rel="stylesheet">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://cdn.staticfile.org/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<div class="well" style="margin-top:30px;">
<div class="alert alert-danger-light">温馨提示:仅用于测试插件是否能正常发送短信</div>
<form class="form-horizontal" action="{:addon_url('alisms/index/send')}" method="POST">
<fieldset>
<legend>阿里云短信发送测试</legend>
<div class="form-group">
<label class="col-lg-2 control-label">手机号</label>
<div class="col-lg-10">
<input type="text" class="form-control" name="mobile" placeholder="手机号">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">消息模板</label>
<div class="col-lg-10">
<select name="template" class="form-control">
{foreach name="templateList" id="item"}
<option value="{$key}">{$item} ({$key})</option>
{/foreach}
</select>
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button type="submit" class="btn btn-primary">发送</button>
<button type="reset" class="btn btn-default">重置</button>
</div>
</div>
</fieldset>
</form>
</div>
</div>
<script src="__CDN__/assets/libs/jquery/dist/jquery.min.js"></script>
<script src="__CDN__/assets/libs/bootstrap/dist/js/bootstrap.min.js"></script>
<script type="text/javascript">
$(function () {
});
</script>
</body>
</html>

2
addons/qingdong/model/Staff.php

@ -44,7 +44,7 @@ class Staff Extends Model {
'salt' => $changed['salt']??'', 'salt' => $changed['salt']??'',
'avatar' => $changed['img'], 'avatar' => $changed['img'],
'email' => $changed['email'], 'email' => $changed['email'],
'cid' => $changed['cid'], 'cid' => isset($changed['cid']) ? $changed['cid'] : 0,
]; ];
if(isset($changed['admin_id']) && $changed['admin_id']){ if(isset($changed['admin_id']) && $changed['admin_id']){

17
application/admin/controller/Index.php

@ -14,6 +14,7 @@ use app\admin\model\MemberGroup;
use app\admin\model\MemberGroupAccess; use app\admin\model\MemberGroupAccess;
use app\admin\model\User; use app\admin\model\User;
use app\common\controller\Backend; use app\common\controller\Backend;
use app\common\library\Sms as Smslib;
use fast\Random; use fast\Random;
use think\Cache; use think\Cache;
use think\Config; use think\Config;
@ -177,15 +178,21 @@ class Index extends Backend
public function sendSms() public function sendSms()
{ {
$mobile = $this->request->get('mobile', ''); $mobile = $this->request->get('mobile', '');
if(!$mobile){ if(!$mobile){
$this->error("请输入手机号"); $this->error("请输入手机号");
} }
if (!$mobile || !\think\Validate::regex($mobile, "^1\d{10}$")) {
$this->error(__('手机号不正确'));
}
//生成验证码 //生成验证码
$random = 8888; $random = rand(1000,9999);
// rand(1000,9999) //
//发送验证码
$flag = 1; $ret = Smslib::send($mobile, $random, 'register');
if(!$flag){
if(!$ret){
$this->error("验证码发送失败,请稍后重试!"); $this->error("验证码发送失败,请稍后重试!");
} }

2
application/admin/controller/auth/Admin.php

@ -131,6 +131,8 @@ class Admin extends Backend
$params['salt'] = Random::alnum(); $params['salt'] = Random::alnum();
$params['password'] = md5(md5($params['password']) . $params['salt']); $params['password'] = md5(md5($params['password']) . $params['salt']);
$params['avatar'] = '/assets/img/avatar.png'; //设置新管理员默认头像。 $params['avatar'] = '/assets/img/avatar.png'; //设置新管理员默认头像。
//获取id
$result = $this->model->validate('Admin.add')->save($params); $result = $this->model->validate('Admin.add')->save($params);
if ($result === false) { if ($result === false) {
exception($this->model->getError()); exception($this->model->getError());

2
application/admin/library/Auth.php

@ -96,7 +96,6 @@ class Auth extends \fast\Auth
$admin->logintime = time(); $admin->logintime = time();
$admin->loginip = request()->ip(); $admin->loginip = request()->ip();
$admin->token = Random::uuid(); $admin->token = Random::uuid();
$admin->save(); $admin->save();
Session::set("admin", $admin->toArray()); Session::set("admin", $admin->toArray());
return true; return true;
@ -542,7 +541,6 @@ class Auth extends \fast\Auth
// 读取管理员当前拥有的权限节点 // 读取管理员当前拥有的权限节点
$userRule = $this->getRuleList2(); $userRule = $this->getRuleList2();
$selected = $referer = []; $selected = $referer = [];
$refererUrl = Session::get('referer'); $refererUrl = Session::get('referer');
// 必须将结果集转换为数组 // 必须将结果集转换为数组

2
application/admin/validate/Admin.php

@ -11,7 +11,7 @@ class Admin extends Validate
* 验证规则 * 验证规则
*/ */
protected $rule = [ protected $rule = [
'username' => 'require|regex:\w{3,30}|unique:admin,cid', 'username' => 'require|regex:\w{3,30}|unique:admin,username',
'nickname' => 'require', 'nickname' => 'require',
'password' => 'require|regex:\S{32}', 'password' => 'require|regex:\S{32}',
// 'email' => 'require|email|unique:admin,email', // 'email' => 'require|email|unique:admin,email',

16
application/common/controller/Backend.php

@ -167,14 +167,14 @@ class Backend extends Controller
$this->error(__('Please login first'), url('index/register', ['url' => $url])); $this->error(__('Please login first'), url('index/register', ['url' => $url]));
} }
// 判断是否需要验证权限 // // 判断是否需要验证权限
if (!$this->auth->match($this->noNeedRight)) { // if (!$this->auth->match($this->noNeedRight)) {
// 判断控制器和方法是否有对应权限 // // 判断控制器和方法是否有对应权限
if (!$this->auth->check($path) ) { // if (!$this->auth->check($path) ) {
Hook::listen('admin_nopermission', $this); // Hook::listen('admin_nopermission', $this);
$this->error(__('You have no permission'), ''); // $this->error(__('You have no permission'), '');
} // }
} // }
} }
// 非选项卡时重定向 // 非选项卡时重定向

2
application/config.php

@ -308,6 +308,6 @@ return [
'key' => '00b7691d86d96aebd21dd9e138f90840', 'key' => '00b7691d86d96aebd21dd9e138f90840',
'cert_path' => ROOT_PATH.'cert/apiclient_cert.pem', // 证书文件路径 'cert_path' => ROOT_PATH.'cert/apiclient_cert.pem', // 证书文件路径
'key_path' => ROOT_PATH.'cert/apiclient_key.pem',// 密钥文件路径 'key_path' => ROOT_PATH.'cert/apiclient_key.pem',// 密钥文件路径
'notify_url' => 'http://shunshicrm.iiixo.com/pay/api/pay/notify', // 支付回调通知URL 'notify_url' => 'http://shunshicrm.iiixo.com/api/pay/notify', // 支付回调通知URL
], ],
]; ];

9
application/extra/addons.php

@ -3,6 +3,15 @@
return [ return [
'autoload' => false, 'autoload' => false,
'hooks' => [ 'hooks' => [
'sms_send' => [
'alisms',
],
'sms_notice' => [
'alisms',
],
'sms_check' => [
'alisms',
],
'upgrade' => [ 'upgrade' => [
'qingdong', 'qingdong',
], ],

2
application/extra/site.php

@ -12,7 +12,7 @@ return array (
'backend' => 'zh-cn', 'backend' => 'zh-cn',
'frontend' => 'zh-cn', 'frontend' => 'zh-cn',
), ),
'fixedpage' => 'dashboard', 'fixedpage' => 'qingdong/dashboard',
'categorytype' => 'categorytype' =>
array ( array (
'default' => 'Default', 'default' => 'Default',

4
extend/fast/Auth.php

@ -156,7 +156,7 @@ class Auth
return $groups[$uid]; return $groups[$uid];
} }
if($uid<1000000){ if(!defined('CID') || CID==0 ){
// 执行查询 // 执行查询
$user_groups = Db::name($this->config['auth_group_access']) $user_groups = Db::name($this->config['auth_group_access'])
->alias('aga') ->alias('aga')
@ -260,7 +260,7 @@ class Auth
} }
//如果是企业账户 并且 该账户拥有企业全部权限 //如果是企业账户 并且 该账户拥有企业全部权限
if($ism && $uid>=1000000 && count($ids) == 1 && $ids[0] == "*"){ if(!!defined('CID') && CID>0 && $ism && $uid>=1000000 && count($ids) == 1 && $ids[0] == "*"){
//获取公司的权限 //获取公司的权限
$userInfo = Db::name("qingdong_staff")->where("admin_id",$uid)->find(); $userInfo = Db::name("qingdong_staff")->where("admin_id",$uid)->find();
$groupInfo = Db::name("company")->where("id",$userInfo['cid'])->find(); $groupInfo = Db::name("company")->where("id",$userInfo['cid'])->find();

39
index.html

@ -0,0 +1,39 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>恭喜,站点创建成功!</title>
<style>
.container {
width: 60%;
margin: 10% auto 0;
background-color: #f0f0f0;
padding: 2% 5%;
border-radius: 10px
}
ul {
padding-left: 20px;
}
ul li {
line-height: 2.3
}
a {
color: #20a53a
}
</style>
</head>
<body>
<div class="container">
<h1>恭喜, 站点创建成功!</h1>
<h3>这是默认index.html,本页面由系统自动生成</h3>
<ul>
<li>本页面在FTP根目录下的index.html</li>
<li>您可以修改、删除或覆盖本页面</li>
<li>FTP相关信息,请到“面板系统后台 > FTP” 查看</li>
</ul>
</div>
</body>
</html>

2
public/assets/js/require-backend.js

@ -50,7 +50,7 @@ require.config({
'template': '../libs/art-template/dist/template-native', 'template': '../libs/art-template/dist/template-native',
'selectpage': '../libs/fastadmin-selectpage/selectpage', 'selectpage': '../libs/fastadmin-selectpage/selectpage',
'citypicker': '../libs/fastadmin-citypicker/dist/js/city-picker.min', 'citypicker': '../libs/fastadmin-citypicker/dist/js/city-picker.min',
'citypicker-data': '../libs/fastadmin-citypicker/dist/js/city-picker.data' 'citypicker-data': '../libs/fastadmin-citypicker/dist/js/city-picker.data',
}, },
// shim依赖配置 // shim依赖配置
shim: { shim: {

2
route/app.php

@ -4,4 +4,4 @@
// 注册路由到index模块的News控制器的read操作 // 注册路由到index模块的News控制器的read操作
use think\Route; use think\Route;
Route::rule('pay/notify','/api/pay/complate'); Route::rule('pay/notify','admin/qingdong/product/member/complate');
Loading…
Cancel
Save