梵音定版初始化
This commit is contained in:
1
addons/smsbao/.addonrc
Normal file
1
addons/smsbao/.addonrc
Normal file
@@ -0,0 +1 @@
|
||||
{"files":[],"license":"regular","licenseto":"101612","licensekey":"atgXVDoULqMszxQw kpVEe8VoEoVYyXbE3jPbng==","domains":["45.221"],"licensecodes":[],"validations":["01aa56d41a1a59da181975a3a6c82078"]}
|
||||
87
addons/smsbao/Smsbao.php
Normal file
87
addons/smsbao/Smsbao.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
namespace addons\smsbao;
|
||||
|
||||
use app\common\library\Menu;
|
||||
use think\Addons;
|
||||
|
||||
/**
|
||||
* Smsbao插件
|
||||
*/
|
||||
class Smsbao extends Addons
|
||||
{
|
||||
|
||||
/**
|
||||
* 插件安装方法
|
||||
* @return bool
|
||||
*/
|
||||
public function install()
|
||||
{
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 插件卸载方法
|
||||
* @return bool
|
||||
*/
|
||||
public function uninstall()
|
||||
{
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 插件启用方法
|
||||
* @return bool
|
||||
*/
|
||||
public function enable()
|
||||
{
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 插件禁用方法
|
||||
* @return bool
|
||||
*/
|
||||
public function disable()
|
||||
{
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 短信发送
|
||||
* @param Sms $params
|
||||
* @return mixed
|
||||
*/
|
||||
public function smsSend(&$params)
|
||||
{
|
||||
$smsbao = new library\Smsbao();
|
||||
$result = $smsbao->mobile($params['mobile'])->msg("你的短信验证码是:{$params['code']}")->send();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 短信发送通知(msg参数直接构建实际短信内容即可)
|
||||
* @param array $params
|
||||
* @return boolean
|
||||
*/
|
||||
public function smsNotice(&$params)
|
||||
{
|
||||
$smsbao = new library\Smsbao();
|
||||
$result = $smsbao->mobile($params['mobile'])->msg($params['msg'])->send();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测验证是否正确
|
||||
* @param Sms $params
|
||||
* @return boolean
|
||||
*/
|
||||
public function smsCheck(&$params)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
46
addons/smsbao/config.php
Normal file
46
addons/smsbao/config.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
return array(
|
||||
0 =>
|
||||
array(
|
||||
'name' => 'username',
|
||||
'title' => '短信宝账号',
|
||||
'type' => 'string',
|
||||
'content' =>
|
||||
array(),
|
||||
'value' => 'username',
|
||||
'rule' => 'required',
|
||||
'msg' => '',
|
||||
'tip' => '',
|
||||
'ok' => '',
|
||||
'extend' => '',
|
||||
),
|
||||
1 =>
|
||||
array(
|
||||
'name' => 'password',
|
||||
'title' => '短信宝密码',
|
||||
'type' => 'string',
|
||||
'content' =>
|
||||
array(),
|
||||
'value' => 'password',
|
||||
'rule' => 'required',
|
||||
'msg' => '',
|
||||
'tip' => '',
|
||||
'ok' => '',
|
||||
'extend' => '',
|
||||
),
|
||||
2 =>
|
||||
array(
|
||||
'name' => 'sign',
|
||||
'title' => '短信签名',
|
||||
'type' => 'string',
|
||||
'content' =>
|
||||
array(),
|
||||
'value' => '【短信签名】',
|
||||
'rule' => 'required',
|
||||
'msg' => '',
|
||||
'tip' => '例如【短信宝】',
|
||||
'ok' => '',
|
||||
'extend' => '',
|
||||
),
|
||||
);
|
||||
15
addons/smsbao/controller/Index.php
Normal file
15
addons/smsbao/controller/Index.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace addons\smsbao\controller;
|
||||
|
||||
use think\addons\Controller;
|
||||
|
||||
class Index extends Controller
|
||||
{
|
||||
|
||||
public function index()
|
||||
{
|
||||
$this->error("当前插件暂无前台页面");
|
||||
}
|
||||
|
||||
}
|
||||
10
addons/smsbao/info.ini
Normal file
10
addons/smsbao/info.ini
Normal file
@@ -0,0 +1,10 @@
|
||||
name = smsbao
|
||||
title = 短信宝
|
||||
intro = 快速接入、使用方便、价格低廉的短信服务
|
||||
author = 一只敲代码的猫
|
||||
website = https://www.fastadmin.net
|
||||
version = 1.0.0
|
||||
state = 1
|
||||
url = /addons/smsbao
|
||||
license = regular
|
||||
licenseto = 101612
|
||||
113
addons/smsbao/library/Smsbao.php
Normal file
113
addons/smsbao/library/Smsbao.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace addons\smsbao\library;
|
||||
|
||||
class Smsbao
|
||||
{
|
||||
private $_params = [];
|
||||
protected $error = '';
|
||||
protected $config = [];
|
||||
protected static $instance = null;
|
||||
protected $statusStr = array(
|
||||
"0" => "短信发送成功",
|
||||
"-1" => "参数不全",
|
||||
"-2" => "服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!",
|
||||
"30" => "密码错误",
|
||||
"40" => "账号不存在",
|
||||
"41" => "余额不足",
|
||||
"42" => "帐户已过期",
|
||||
"43" => "IP地址限制",
|
||||
"50" => "内容含有敏感词"
|
||||
);
|
||||
|
||||
public function __construct($options = [])
|
||||
{
|
||||
if ($config = get_addon_config('smsbao')) {
|
||||
$this->config = array_merge($this->config, $config);
|
||||
}
|
||||
$this->config = array_merge($this->config, is_array($options) ? $options : []);
|
||||
}
|
||||
|
||||
/**
|
||||
* 单例
|
||||
* @param array $options 参数
|
||||
* @return Smsbao
|
||||
*/
|
||||
public static function instance($options = [])
|
||||
{
|
||||
if (is_null(self::$instance)) {
|
||||
self::$instance = new static($options);
|
||||
}
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 立即发送短信
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function send()
|
||||
{
|
||||
$this->error = '';
|
||||
$params = $this->_params();
|
||||
$postArr = array(
|
||||
'u' => $params['u'],
|
||||
'p' => $params['p'],
|
||||
'm' => $params['mobile'],
|
||||
'c' => $params['msg']
|
||||
);
|
||||
$options = [
|
||||
CURLOPT_HTTPHEADER => array(
|
||||
'Content-Type: application/json; charset=utf-8'
|
||||
)
|
||||
];
|
||||
$result = \fast\Http::sendRequest('http://api.smsbao.com/sms', $postArr, 'GET', $options);
|
||||
if ($result['ret']) {
|
||||
if (isset($result['msg']) && $result['msg'] == '0')
|
||||
return TRUE;
|
||||
$this->error = isset($this->statusStr[$result['msg']]) ? $this->statusStr[$result['msg']] : 'InvalidResult';
|
||||
} else {
|
||||
$this->error = $result['msg'];
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
private function _params()
|
||||
{
|
||||
return array_merge([
|
||||
'u' => $this->config['username'],
|
||||
'p' => md5($this->config['password']),
|
||||
], $this->_params);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取错误信息
|
||||
* @return string
|
||||
*/
|
||||
public function getError()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
/**
|
||||
* 接收手机
|
||||
* @param string $mobile 手机号码
|
||||
* @return Smsbao
|
||||
*/
|
||||
public function mobile($mobile = '')
|
||||
{
|
||||
$this->_params['mobile'] = $mobile;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 短信内容
|
||||
* @param string $msg 短信内容
|
||||
* @return Smsbao
|
||||
*/
|
||||
public function msg($msg = '')
|
||||
{
|
||||
$this->_params['msg'] = $this->config['sign'] . $msg;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user