feat: 添加阿里云短信服务支持并优化验证码逻辑

- 引入 alibabacloud/dysmsapi-20170525 依赖,集成阿里云短信服务
- 将短信验证码从6位改为4位,优化用户体验
- 添加聚水潭商品按时间范围同步功能,支持分页拉取
- 增强Cron任务异常处理,添加错误日志记录
- 修复系统附件服务中图片路径处理逻辑
- 更新阿里云SDK相关组件至最新版本
- 添加think-trace调试扩展,便于问题排查
- 优化跨域中间件,使用str_contains替代strpos
This commit is contained in:
2026-04-30 15:19:40 +08:00
parent 0334fef6c1
commit c7f85ffbda
565 changed files with 59742 additions and 3391 deletions

View File

@@ -0,0 +1,54 @@
<?php
namespace app\command;
use app\services\product\product\StoreProductServices;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\console\input\Option;
use think\facade\Db;
class BackfillProductSpu extends Command
{
protected function configure()
{
$this->setName('product:spu:backfill')
->addOption('chunk', null, Option::VALUE_REQUIRED, '单次处理条数', 200)
->addOption('limit', null, Option::VALUE_REQUIRED, '最多处理条数(0不限制)', 0)
->setDescription('Backfill empty product spu');
}
protected function execute(Input $input, Output $output)
{
$chunk = max(1, (int)$input->getOption('chunk'));
$limit = max(0, (int)$input->getOption('limit'));
$handled = 0;
/** @var StoreProductServices $productServices */
$productServices = app()->make(StoreProductServices::class);
while (true) {
$query = Db::name('store_product')->where('spu', '')->where('is_del', 0)->order('id', 'asc')->limit($chunk);
if ($limit > 0) {
$query->limit(min($chunk, $limit - $handled));
}
$rows = $query->field(['id'])->select()->toArray();
if (!$rows) {
break;
}
foreach ($rows as $row) {
$productServices->ensureSpu((int)$row['id']);
$handled++;
if ($limit > 0 && $handled >= $limit) {
break 2;
}
}
$output->info('handled: ' . $handled);
}
$output->info('done: ' . $handled);
return 0;
}
}

View File

@@ -0,0 +1,93 @@
<?php
namespace app\command;
use app\haichao\HaichaoJstServices;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;
class TestJstSpu extends Command
{
protected function configure()
{
$this->setName('test_jst_spu')
->addArgument('spu', Argument::REQUIRED, 'SPU编码')
->setDescription('测试聚水潭按SPU拉取商品接口');
}
protected function execute(Input $input, Output $output)
{
$spu = $input->getArgument('spu');
if (empty($spu)) {
$output->error('请提供SPU编码');
$output->info('用法: php think test_jst_spu SPU编码');
$output->info('示例: php think test_jst_spu test123');
return;
}
$output->info('正在调用聚水潭API获取商品信息...');
$output->info('SPU: ' . $spu);
$output->newLine();
try {
$startTime = microtime(true);
$haichaoJst = HaichaoJstServices::getServices();
$result = $haichaoJst->getProductListKuan($spu);
$endTime = microtime(true);
$costTime = round(($endTime - $startTime) * 1000, 2);
$output->info('✅ API调用成功! 耗时: ' . $costTime . 'ms');
$output->newLine();
if (empty($result)) {
$output->warning('⚠️ 未获取到任何数据');
return;
}
$output->info('📦 获取到的数据:');
$output->write(json_encode($result, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
$output->newLine();
if (isset($result['code'])) {
$output->info('响应码: ' . $result['code']);
}
if (isset($result['msg'])) {
$output->info('响应消息: ' . $result['msg']);
}
if (isset($result['datas'])) {
$output->info('商品数量: ' . count($result['datas']));
if (!empty($result['datas'])) {
$output->newLine();
$output->info('📋 第一个商品信息:');
$firstProduct = $result['datas'][0];
$output->writeln(' - SPU ID: ' . ($firstProduct['i_id'] ?? 'N/A'));
$output->writeln(' - 商品名称: ' . ($firstProduct['name'] ?? 'N/A'));
$output->writeln(' - 售价: ' . ($firstProduct['s_price'] ?? 'N/A'));
$output->writeln(' - 市场价: ' . ($firstProduct['market_price'] ?? 'N/A'));
$output->writeln(' - 成本价: ' . ($firstProduct['c_price'] ?? 'N/A'));
if (isset($firstProduct['skus']) && is_array($firstProduct['skus'])) {
$output->writeln(' - SKU数量: ' . count($firstProduct['skus']));
}
}
}
$output->newLine();
} catch (\Throwable $e) {
$output->error('❌ API调用失败!');
$output->error('错误信息: ' . $e->getMessage());
$output->error('错误文件: ' . $e->getFile() . ':' . $e->getLine());
$output->newLine();
$output->info('堆栈跟踪:');
$output->write($e->getTraceAsString());
}
}
}