其余文件

This commit is contained in:
2026-04-14 17:46:22 +08:00
parent 294b68fe37
commit 3691f4db22
1343 changed files with 189847 additions and 0 deletions

View File

@ -0,0 +1,105 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\server\sms;
use app\common\server\ConfigServer;
use think\facade\Log;
/**
* 短信驱动
* Class Driver
* @package app\common\server\smsEngine
*/
class Driver
{
protected $config;
protected $smsEngine;
protected $defaultEngine;
protected $error;
public function getError()
{
return $this->error;
}
public function __construct()
{
$this->initialize();
}
/**
* @notes 初始化配置
* @throws \Exception
* @author 段誉
* @date 2022/1/10 15:47
*/
public function initialize()
{
$defaultEngine = ConfigServer::get('sms_driver', 'default', '');
if (empty($defaultEngine)) {
throw new \Exception('请开启短信配置');
}
$this->defaultEngine = $defaultEngine;
$classSpace = __NAMESPACE__ . '\\engine\\' . ucfirst($defaultEngine.'Sms');
if (!class_exists($classSpace)) {
throw new \Exception('对应短信配置类不存在');
}
$engineConfig = ConfigServer::get('sms_engine', $defaultEngine, []);
if (empty($engineConfig)) {
throw new \Exception('请在后台设置好('.$defaultEngine.')的配置');
}
$this->smsEngine = new $classSpace($engineConfig);
}
/**
* Notes: 发送短信
* @param $mobile
* @param $data
* @author 段誉(2021/6/22 0:42)
* @return bool
*/
public function send($mobile, $data)
{
try{
$res = $this->smsEngine
->setMobile($mobile)
->setTemplateId($data['template_id'])
->setTemplateParam($data['param'])
->send();
if (false === $res) {
throw new \Exception($this->smsEngine->getError());
}
return $res;
} catch (\Throwable $e) {
Log::write($e->__toString(), 'sms_send_base_error');
$this->error = $e->getMessage();
return false;
}
}
}

View File

@ -0,0 +1,136 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\server\sms\engine;
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
/**
* 阿里短信
* Class AliSms
*/
class AliSms extends Server
{
protected $config;
protected $mobile; //下发手机号
protected $template_code; //验证码
protected $template_param; //模板参数
public function __construct($config = [])
{
if (empty($config)) {
$this->error = '请联系管理员配置参数';
return false;
}
$this->config = $config;
}
/**
* Notes: 设置手机号
* @param string $mobile
* @author 段誉(2021/5/18 17:39)
* @return $this
*/
public function setMobile($mobile = '')
{
$this->mobile = $mobile;
return $this;
}
/**
* Notes: 设置模板id
* @param string $template_code
* @author 段誉(2021/5/18 17:39)
* @return $this
*/
public function setTemplateId($template_code = '')
{
$this->template_code = $template_code;
return $this;
}
/**
* Notes: 设置模板参数
* @param string $template_param
* @author 段誉(2021/5/18 17:39)
* @return $this
*/
public function setTemplateParam($template_param = '')
{
$this->template_param = json_encode($template_param);
return $this;
}
/**
* Notes: 发送短信
* @author 段誉(2021/5/18 17:40)
* @return array|bool
* @throws ClientException
*/
public function send()
{
AlibabaCloud::accessKeyClient($this->config['app_key'], $this->config['secret_key'])
->regionId('cn-hangzhou')
->asDefaultClient();
try {
$result = AlibabaCloud::rpcRequest()
->product('Dysmsapi')
->host('dysmsapi.aliyuncs.com')
->version('2017-05-25')
->action('SendSms')
->method('POST')
->options([
'query' => [
'PhoneNumbers' => $this->mobile, //发送手机号
'SignName' => $this->config['sign'], //短信签名
'TemplateCode' => $this->template_code, //短信模板CODE
'TemplateParam' => $this->template_param, //自定义随机数
],
])
->request();
$res = $result->toArray();
if (isset($res['Code']) && $res['Code'] == 'OK') {
return $res;
}
$message = $res['Message'] ?? $res;
throw new \Exception('短信错误:' . $message);
} catch (ClientException $e) {
$this->error = $e->getErrorMessage();
return false;
} catch (ServerException $e) {
$this->error = $e->getErrorMessage();
return false;
} catch (\Exception $e) {
$this->error = $e->getMessage();
return false;
}
}
}

View File

@ -0,0 +1,23 @@
<?php
namespace app\common\server\sms\engine;
class Server
{
/**
* 错误信息
* @var
*/
protected $error;
/**
* 返回错误信息
* @return mixed
*/
public function getError()
{
return $this->error;
}
}

View File

@ -0,0 +1,137 @@
<?php
// +----------------------------------------------------------------------
// | likeshop开源商城系统
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | gitee下载https://gitee.com/likeshop_gitee
// | github下载https://github.com/likeshop-github
// | 访问官网https://www.likeshop.cn
// | 访问社区https://home.likeshop.cn
// | 访问手册http://doc.likeshop.cn
// | 微信公众号likeshop技术社区
// | likeshop系列产品在gitee、github等公开渠道开源版本可免费商用未经许可不能去除前后端官方版权标识
// | likeshop系列产品收费版本务必购买商业授权购买去版权授权后方可去除前后端官方版权标识
// | 禁止对系统程序代码以任何目的,任何形式的再发布
// | likeshop团队版权所有并拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeshop.cn.team
// +----------------------------------------------------------------------
namespace app\common\server\sms\engine;
use TencentCloud\Sms\V20190711\SmsClient;
use TencentCloud\Sms\V20190711\Models\SendSmsRequest;
use TencentCloud\Common\Exception\TencentCloudSDKException;
use TencentCloud\Common\Credential;
use TencentCloud\Common\Profile\ClientProfile;
use TencentCloud\Common\Profile\HttpProfile;
/**
* 腾讯云短信
* Class TcSms
*/
class TcSms extends Server
{
protected $config;
protected $mobile; //下发手机号码
protected $template_id; //模板id
protected $template_param ; //模板参数
public function __construct($config)
{
if (empty($config)) {
$this->error = '请联系管理员配置参数';
return false;
}
$this->config = $config;
}
/**
* Notes: 设置手机号
* @param string $mobile
* @author 段誉(2021/5/18 17:41)
* @return $this
*/
public function setMobile($mobile = '')
{
$this->mobile = $mobile;
return $this;
}
/**
* Notes: 设置模板id
* @param null $template_id
* @author 段誉(2021/5/18 17:41)
* @return $this
*/
public function setTemplateId($template_id = null)
{
$this->template_id = $template_id;
return $this;
}
/**
* Notes: 设置模板参数
* @param null $template_param
* @author 段誉(2021/5/18 17:42)
* @return $this
*/
public function setTemplateParam($template_param = null)
{
$this->template_param = $template_param;
return $this;
}
/**
* @notes 发送 (此处$config[app_key]为系统统一命名,原腾讯云命名为secret_id)
* @return false|mixed
* @author 段誉
* @date 2021/8/4 10:40
*/
public function send()
{
try {
$cred = new Credential($this->config['app_key'], $this->config['secret_key']);
$httpProfile = new HttpProfile();
$httpProfile->setEndpoint("sms.tencentcloudapi.com");
$clientProfile = new ClientProfile();
$clientProfile->setHttpProfile($httpProfile);
$client = new SmsClient($cred, "", $clientProfile);
$req = new SendSmsRequest();
$params = [
'PhoneNumberSet' => ['+86'.$this->mobile],
'TemplateID' => $this->template_id,
'Sign' => $this->config['sign'],
'TemplateParamSet' => $this->template_param,
'SmsSdkAppid' => $this->config['app_id'],
];
$req->fromJsonString(json_encode($params));
$resp = json_decode($client->SendSms($req)->toJsonString(), true);
if (isset($resp['SendStatusSet']) && $resp['SendStatusSet'][0]['Code'] == 'Ok') {
return $resp;
} else {
$message = $res['SendStatusSet'][0]['Message'] ?? json_encode($resp);
throw new \Exception('短信错误:' . $message);
}
} catch (TencentCloudSDKException $e) {
$this->error = $e->getMessage();
return false;
} catch (\Exception $e) {
$this->error = $e->getMessage();
return false;
}
}
}