82 lines
3.3 KiB
PHP
82 lines
3.3 KiB
PHP
<?php
|
|
/**
|
|
* SAAS应用系统 --- 十年开发经验汇集巨献!
|
|
* ==========================================================
|
|
* Copy right 2020-2050 成都众联思索科技有限公司,保留所有权利。
|
|
* ----------------------------------------------------------
|
|
* 官方网址: https://www.zoomtk.com
|
|
* 这不是自由软件!未经允许不得用于商业目或程序代码摘取及修改。
|
|
* 任何企业和个人不允许对程序代码以任何形式任何目的再发布传播。
|
|
* 唯一发布渠道www.zoomtk.com;非官方渠道统一视为侵权行为。
|
|
* ==========================================================
|
|
*/
|
|
namespace addon\cossms\model;
|
|
use app\model\BaseModel;
|
|
use Overtrue\EasySms\EasySms;
|
|
use Overtrue\EasySms\Exceptions\InvalidArgumentException;
|
|
use Overtrue\EasySms\Exceptions\NoGatewayAvailableException;
|
|
use Overtrue\EasySms\Strategies\OrderStrategy;
|
|
/**
|
|
* 腾讯云短信
|
|
*/
|
|
class Sms extends BaseModel
|
|
{
|
|
/**
|
|
* 短信发送
|
|
* @param array $param
|
|
* @return array|mixed
|
|
* @throws InvalidArgumentException
|
|
*/
|
|
public function send($param = [])
|
|
{
|
|
$config_model = new Config();
|
|
$site_id=$param['site_id']??0;
|
|
$app_module=$param['app_module']??'shop';
|
|
$config_result = $config_model->getSmsConfig($site_id,$app_module);
|
|
if ($config_result["data"]["is_use"]) {
|
|
$config = $config_result["data"]["value"];
|
|
$sms_info = $param["message_info"]["sms_json_array"];//消息类型模板 短信模板信息
|
|
if (empty($sms_info)) return $this->error([], "消息模板尚未配置");
|
|
$sms_info = $sms_info[ "cossms" ];
|
|
$var_parse = $param["var_parse"];//变量解析
|
|
$account = $param["sms_account"]??$param['mobile'];//发送手机号
|
|
$template = $sms_info["template_id"]??'';//发送模板ID
|
|
//加入腾讯云短信配置
|
|
$sms_config = [
|
|
// HTTP 请求的超时时间(秒)
|
|
'timeout' => 5.0,
|
|
// 默认发送配置
|
|
'default' => [
|
|
// 网关调用策略,默认:顺序调用
|
|
'strategy' => OrderStrategy::class,
|
|
// 默认可用的发送网关
|
|
'gateways' => ['qcloud'],
|
|
],
|
|
// 可用的网关配置
|
|
'gateways' => [
|
|
'qcloud' => [
|
|
'sdk_app_id' => $config["sdk_app_id"], // SDK APP ID
|
|
'app_key' => $config["sdk_app_key"],// APP KEY
|
|
'secret_id' =>$config['secret_id'], //'AKIDARZRAj9KGySjmaBalgbT8oaCau21nLgo', // SECRET ID
|
|
'secret_key' =>$config['secret_key'], //'8DGOXYRBsS3b2Mdp15xb2W3RluqhNnzw', // SECRET KEY
|
|
'sign_name' =>$config['smssign'] //'恒泰茶缘网络', // 短信签名
|
|
]
|
|
],
|
|
];
|
|
try {
|
|
unset($var_parse['site_name']);
|
|
$easySms = new EasySms($sms_config);
|
|
$easySms->send($account, [
|
|
'template' => $template, // 模板ID
|
|
'content' =>$sms_info["content"], // 模板内容
|
|
'data' => $var_parse
|
|
]);
|
|
return $this->success([ "addon" => "cossms", "addon_name" => "腾讯云短信", "content" => $sms_info["content"] ]);
|
|
} catch (NoGatewayAvailableException $exception) {
|
|
$message = $exception->getException('qcloud')->getMessage();
|
|
return $this->error([ "content" => $sms_info["content"] ], $message ? : '短信发送异常');
|
|
}
|
|
}
|
|
}
|
|
}
|