线上网校系统MeEdu二次开发新增短信宝短信插件
修改的文件:
\app\Meedu\Setting.php
\vendor\overtrue\easy-sms\src\Gateways\SmsbaoGateway.php
\src\components\setting\index.vue
<?php
namespace Overtrue\EasySms\Gateways;
use Overtrue\EasySms\Contracts\MessageInterface;
use Overtrue\EasySms\Contracts\PhoneNumberInterface;
use Overtrue\EasySms\Exceptions\GatewayErrorException;
use Overtrue\EasySms\Support\Config;
use Overtrue\EasySms\Traits\HasHttpRequest;
class SmsbaoGateway extends Gateway
{
use HasHttpRequest;
public function send(PhoneNumberInterface $to, MessageInterface $message, Config $config)
{
$user = $config->get('smskey', '');
$pass = $config->get('smssercet', '');
$signature = $config->get('sing', '');
foreach ($message->getData($this) as $key=>$value){
$content = str_replace('{$code}',$value,$message->getContent($this));
}
$content = '【'.$signature.'】'.$content;
$smsapi = "http://api.smsbao.com/";
$user = $user; //短信平台帐号
$pass = md5($pass); //短信平台密码
$content=$content;//要发送的短信内容
$phone =$to;//要发送短信的手机号码
$sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".$content;
$result =file_get_contents($sendurl);
return $result;
}
}
1:本插件系短信宝针对MeEduoV2.5.2开发,如果你的系统经过二次开发,安装本插件之前,请仔细核对修改
2:将插件内的后台框架前端目录中的src目录覆盖至你MeEdu_V2.5.2前端的根目录
3:将插件内的后台目录覆盖至你MeEdu_V2.5.2后台的根目录
4:进入管理后台-》系统-》设置-》短信,选择短信宝,并填写短信宝账号密码、签名以及模板
模板示例:
密码重置模板:您的密码重置验证码为:{KaTeX parse error: Expected 'EOF', got '}' at position 5: code}̲ 注册模板:您的注册验证码为:…code}
手机号绑定:手机号绑定验证码为:{KaTeX parse error: Expected 'EOF', got '}' at position 5: code}̲ 手机号登陆:您的登陆验证码为…code}
5:如有其它疑问,请咨询短信宝客服。
6:Linux 环境请设置插件文件的读权限(777)
<?php
namespace App\Meedu;
use function GuzzleHttp\default_ca_bundle;
use Illuminate\Http\Request;
use Illuminate\Filesystem\Filesystem;
class Setting
{
const VERSION = 1;
protected $files;
protected $dist;
public function __construct()
{
$this->files = new Filesystem();
$this->dist = config('meedu.save');
}
public function save($param)
{
$data = $param;
if ($data instanceof Request) {
$data = $param->all();
}
$data['version'] = self::VERSION;
$this->put($data);
}
/**
* @param $params
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function append($params)
{
foreach ($params as $key => $item) {
config([$key => $item]);
}
$this->put($this->getCanEditConfig());
}
/**
* 自定义配置同步到Laravel系统中.
*/
public function sync()
{
$saveConfig = $this->get();
if (!isset($saveConfig['version'])) {
// 老版本的配置保存方式
collect($this->get())->map(function ($item, $key) {
config([$key => $item]);
});
} else {
// v1版本的配置保存方式
if ((int)$saveConfig['version'] === self::VERSION) {
$arr = array_compress($saveConfig);
foreach ($arr as $key => $item) {
config([$key => $item]);
}
}
}
$this->specialSync();
}
/**
* 一些特殊配置.
*/
protected function specialSync(): void
{
// 短信服务注册
config(['sms.default.gateways' => [config('meedu.system.sms')]]);
}
/**
* 修改配置.
*
* @param array $setting
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function put(array $setting): void
{
$this->files->put($this->dist, json_encode($setting));
}
/**
* 读取自定义配置.
*
* @return array
*
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
*/
public function get(): array
{
if (!$this->files->exists($this->dist)) {
return [];
}
$jsonContent = $this->files->get($this->dist);
$arrayContent = json_decode($jsonContent, true);
return $arrayContent;
}
/**
* 获取可以编辑的配置
* @return array
*/
public function getCanEditConfig(): array
{
$meedu = config('meedu');
$smsconfig = config('sms');
if (!isset($smsconfig['gateways']['smsbao'])){
$smsconfig['default']['gateways'][0] = 'smsbao';
$smsconfig['gateways']['smsbao'] = array('smskey'=>'','smssercet'=>'','sing'=>'','template'=>array("password_reset"=>'',"register"=>'',"mobile_bind"=>'',"login"=>''));
}
$config = [
'app' => config('app'),
'meedu' => $meedu,
'sms' => $smsconfig,
'services' => config('services'),
'pay' => config('pay'),
'tencent' => config('tencent'),
'filesystems' => config('filesystems'),
];
return $config;
}
}
二次开发 QQ扫一扫