HEX
Server: nginx/1.28.1
System: Linux 10-41-63-61 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User: www (1001)
PHP: 7.4.33
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/ly.fwmnzf.com/addons/easysms/Easysms.php
<?php
// +----------------------------------------------------------------------
// | Yzncms [ 御宅男工作室 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2018 http://yzncms.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 御宅男 <530765310@qq.com>
// +----------------------------------------------------------------------

// +----------------------------------------------------------------------
// | 短信插件
// +----------------------------------------------------------------------
namespace addons\easysms;

use sys\Addons;

class Easysms extends Addons
{
    public $config = [
        // HTTP 请求的超时时间(秒)
        'timeout'  => 5.0,

        // 默认发送配置
        'default'  => [
            // 网关调用策略,默认:顺序调用
            'strategy' => \Overtrue\EasySms\Strategies\OrderStrategy::class,

            // 默认可用的发送网关
            'gateways' => [
                //阿里云
                'aliyun',
            ],
        ],
        // 可用的网关配置
        'gateways' => [
            'errorlog' => [
                'file' => APP_PATH . 'runtime/tmp/easy-sms.log',
            ],
            //阿里云
            'aliyun'   => [
                'access_key_id'     => '',
                'access_key_secret' => '',
                'sign_name'         => '',
            ],
        ],
    ];

    protected function init()
    {
        $config                                        = $this->getAddonConfig();
        $this->config['default']['gateways']           = (array) $config['gateways'];
        $this->config['gateways'][$config['gateways']] = (array) $config['config'];
    }

    /**
     * 插件安装方法
     * @return bool
     */
    public function install()
    {
        return true;
    }

    /**
     * 插件卸载方法
     * @return bool
     */
    public function uninstall()
    {
        return true;
    }

    /**
     * 短信发送行为
     * @param   Sms     $params
     * @return  boolean
     */
    public function smsSend($params)
    {
        $this->init();
        $config  = $this->getAddonConfig();
        $easySms = new \Overtrue\EasySms\EasySms($this->config);
        try {
            $result = $easySms->send($params->mobile, [
                'content'  => '您的验证码为: ' . $params->code,
                'template' => isset($config['template'][$params->event]) ? $config['template'][$params->event] : 0,
                'data'     => [
                    'code' => $params->code,
                ],
            ]);
        } catch (\Exception $e) {
            //var_dump($e->getResults());
            return false;
        }
        $is_suc = false;
        foreach ($result as $v) {
            if ($v['status'] == 'success') {
                $is_suc = true;
                break;
            }
        }
        return $is_suc;
    }

    /**
     * 短信发送通知
     * @param   array   $params
     * @return  boolean
     */
    public function smsNotice($params)
    {
        $this->init();
        $easySms = new \Overtrue\EasySms\EasySms($this->config);
        try {
            $result = $easySms->send($params['mobile'], [
                'content'  => $params['msg'],
                'template' => $params['template'],
                'data'     => isset($params['data']) ? $params['data'] : [],
            ]);
        } catch (\Exception $exception) {
            return false;
        }
        $is_suc = false;
        foreach ($result as $v) {
            if ($v['status'] == 'success') {
                $is_suc = true;
                break;
            }
        }
        return $is_suc;
    }

    /**
     * 检测验证是否正确
     * @param   Sms     $params
     * @return  boolean
     */
    public function smsCheck($params)
    {
        return true;
    }

}