线上网校系统MeEdu二次开发新增短信宝短信插件

线上网校系统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扫一扫
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

linlinlove2

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值