24 changed files with 570 additions and 23 deletions
@ -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> |
||||
@ -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> |
||||
@ -0,0 +1 @@ |
|||||
|
|
||||
@ -0,0 +1 @@ |
|||||
|
deny from all |
||||
@ -0,0 +1 @@ |
|||||
|
{"files":[],"license":"regular","licenseto":"48387","licensekey":"Pfv3uGdOlHY9JkNs ipSrRrVAtDrrRKmg6Qwqnw==","domains":["iiixo.com"],"licensecodes":[],"validations":["8c705a04d965d13dbbabb413e876acfd"]} |
||||
@ -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; |
||||
|
} |
||||
|
} |
||||
@ -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' => '', |
||||
|
], |
||||
|
]; |
||||
@ -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()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -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 |
||||
@ -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; |
||||
|
} |
||||
|
} |
||||
@ -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> |
||||
@ -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> |
||||
Loading…
Reference in new issue