chore: 重写初始提交(清空历史,整理后全量提交)

This commit is contained in:
ywxapp
2026-08-16 16:54:14 +08:00
commit 6c1a106bc1
1808 changed files with 238144 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
<?php
// +----------------------------------------------------------------------
// | YwxApp [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2026-2036 http://ywxapp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: ywxapp<admin@ywxapp.cn>
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace addon\smssend;
use ywxapp\AddonBase;
/**
* Addon 类
*
* @author ywxapp <admin@ywxapp.cn>
*/
class Addon extends addon
{
public function install()
{
return true;
}
public function uninstall()
{
return true;
}
public function enable()
{
return true;
}
public function disable()
{
return true;
}
}
+22
View File
@@ -0,0 +1,22 @@
# smssend — 生产版短信发送插件
监听 `ywxapp\library\Sms` 触发的 `SmsSend` 事件,在生产环境真正调用可配置网关下发短信。
## 与开发模式的关系
`ywxapp\service\AppService` 默认注册了一个 `SmsSend` 监听:
- **开发环境(app_debug=1**:返回 `true`(仅记录验证码到日志并回传前端 `debug_code`),不下发。
- **生产环境(app_debug=0**:返回 `null`,此时必须启用本插件,`onSend` 返回 `true` 短信才会真正发出并落库。
## 配置(后台“插件配置”)
| 配置项 | 说明 |
|--------|------|
| `api_url` | 网关地址,GET 方式提交参数 |
| `account` | 网关账号 |
| `password` | 网关密码 |
| `sign` | 短信签名(内容前缀【签名】) |
| `template`| 模板,支持 `{code}` `{mobile}` 占位 |
默认按短信宝协议判断:网关返回 `0` 表示成功。若使用其它网关,请修改 `subscribe/Sender.php`
对返回值的判定逻辑(如阿里云、腾讯云等返回 JSON,需相应解析)。
+47
View File
@@ -0,0 +1,47 @@
<?php
// +----------------------------------------------------------------------
// | YwxApp [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2026-2036 http://ywxapp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: ywxapp<admin@ywxapp.cn>
// +----------------------------------------------------------------------
// 生产版短信插件配置项(后台“插件配置”页数据源;实际值存于统一配置表 wxapp_addon_config
// 默认值仅为占位,请在生产环境替换为自有网关账号与签名。
return [
[
'name' => 'api_url',
'title' => '网关地址',
'type' => 'string',
'value' => 'https://api.smsbao.com/sms',
'tip' => '短信网关 URLGET 方式提交参数)',
],
[
'name' => 'account',
'title' => '网关账号',
'type' => 'string',
'value' => '',
'tip' => '短信平台账号',
],
[
'name' => 'password',
'title' => '网关密码',
'type' => 'string',
'value' => '',
'tip' => '短信平台密码',
],
[
'name' => 'sign',
'title' => '短信签名',
'type' => 'string',
'value' => '示例',
'tip' => '短信内容前缀【签名】',
],
[
'name' => 'template',
'title' => '短信模板',
'type' => 'textarea',
'value' => '您的验证码为:{code},请勿泄露给他人',
'tip' => '支持占位符 {code} 与 {mobile}',
],
];
+29
View File
@@ -0,0 +1,29 @@
<?php
// +----------------------------------------------------------------------
// | YwxApp [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2026-2036 http://ywxapp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: ywxapp<admin@ywxapp.cn>
// +----------------------------------------------------------------------
return [
'name' => 'smssend',
'title' => '生产版短信发送',
'intro' => '生产环境真正下发短信:监听 SmsSend 事件,调用可配置网关 HTTP 接口',
'author' => 'Ywxapp',
'website' => '',
'version' => '1.0.1',
'state' => 1,
'url' => '/smssend',
'license' => '',
'licenseto' => 0,
'config' => [],
// eventPrefix='Sms'onSend -> SmsSendonNotice -> SmsNotice
'events' => [
'subscribe' => [
'addon\smssend\subscribe\Sender',
],
],
'middleware' => [],
'services' => [],
];
+95
View File
@@ -0,0 +1,95 @@
<?php
// +----------------------------------------------------------------------
// | YwxApp [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2026-2036 http://ywxapp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: ywxapp<admin@ywxapp.cn>
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace addon\smssend\subscribe;
use ywxapp\service\AddonService;
use ywxapp\utils\HttpClient;
use think\facade\Env;
use think\facade\Log;
/**
* 生产版短信发送订阅器
*
* 监听 ywxapp\library\Sms 触发的事件:
* - onSend($sms) -> SmsSend 验证码下发(返回 true/false 决定 Sms::send 是否成功落库)
* - onNotice($sms) -> SmsNotice 通知类短信(可选)
*
* 开发环境(app_debug=1)下不真正外发,避免无谓网络请求;生产环境调用配置的网关。
*
* 注意:ywxapp\service\AppService 默认已注册一个 SmsSend 监听——
* 开发环境返回 true(仅记录验证码);生产环境返回 null(交由本插件真正发送)。
* 因此生产环境务必启用本插件,否则 Sms::send 将因无监听器返回真值而失败。
*/
class Sender
{
protected $eventPrefix = 'Sms';
/**
* 下发验证码
* @param mixed $sms Sms 模型对象,可用 $sms['mobile']/$sms['code']/$sms['event'] 访问
* @return bool 发送是否成功(true 才会保留短信记录)
*/
public function onSend($sms): bool
{
$cfg = AddonService::config('smssend');
$api = $cfg['api_url'] ?? '';
if (!$api) {
Log::warning('[smssend] 未配置 api_url,无法发送短信');
return false;
}
// 开发环境不真正外发,避免无谓网络请求与密钥泄露
if (Env::get('app_debug')) {
Log::info('[smssend][DEV] 模拟发送 -> ' . ($sms['mobile'] ?? '') . ' code=' . ($sms['code'] ?? ''));
return true;
}
$sign = $cfg['sign'] ?? '';
$content = '【' . $sign . '】' . str_replace(
['{code}', '{mobile}'],
[$sms['code'] ?? '', $sms['mobile'] ?? ''],
$cfg['template'] ?? '您的验证码为:{code},请勿泄露给他人'
);
$params = [
'u' => $cfg['account'] ?? '',
'p' => $cfg['password'] ?? '',
'm' => $sms['mobile'],
'c' => $content,
];
try {
$client = new HttpClient();
$resp = $client->get($api, $params);
if ($resp === false) {
Log::error('[smssend] 请求失败: ' . $client->getError());
return false;
}
// 示例按短信宝协议判断:返回 "0" 表示成功,其余为错误码
$resp = trim((string) $resp);
if ($resp === '0') {
return true;
}
Log::error('[smssend] 网关返回异常: ' . $resp);
return false;
} catch (\Throwable $e) {
Log::error('[smssend] 发送异常: ' . $e->getMessage());
return false;
}
}
/**
* 通知类短信(可选实现)
*/
public function onNotice($sms): bool
{
return true;
}
}