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

124 lines
4.9 KiB
PHP
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env php
<?php
namespace think;
require __DIR__ . '/vendor/autoload.php';
$spu = $argv[1] ?? '';
echo "========================================\n";
echo "聚水潭商品拉取接口测试\n";
echo "========================================\n\n";
$app = new App();
$app->initialize();
echo "✅ 应用初始化成功!\n\n";
try {
echo "1️⃣ 测试HaichaoJstServices方法...\n\n";
try {
$haichaoJst = \app\haichao\HaichaoJstServices::getServices();
if (empty($spu)) {
echo "用法: php test_haichao.php SPU编码\n";
echo "示例: php test_haichao.php test123\n";
echo " php test_haichao.php SPU001,SPU002\n\n";
echo "2️⃣ 尝试获取示例数据(getProductListStand)...\n\n";
try {
echo "正在调用聚水潭API...\n";
$result = $haichaoJst->getProductListStand();
echo "✅ API调用成功!\n\n";
if (empty($result)) {
echo "⚠️ 未获取到任何数据\n";
echo "可能原因:\n";
echo " 1. 聚水潭系统中没有商品\n";
echo " 2. 时间范围内没有修改过的商品\n";
echo " 3. API配置有误\n\n";
} else {
echo "📦 获取到 " . count($result) . " 条商品数据\n\n";
if (!empty($result) && isset($result[0])) {
echo "📋 示例商品:\n";
$product = $result[0];
echo json_encode($product, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . "\n\n";
}
}
} catch (\Throwable $e) {
echo "❌ getProductListStand失败: " . $e->getMessage() . "\n";
echo "错误文件: " . $e->getFile() . ":" . $e->getLine() . "\n\n";
}
exit(0);
}
echo "正在调用HaichaoJstServices::getProductListKuan...\n";
echo "SPU: " . $spu . "\n\n";
$result = $haichaoJst->getProductListKuan($spu);
echo "✅ API调用成功!\n\n";
if (empty($result)) {
echo "⚠️ 未获取到任何数据\n\n";
} else {
echo "📦 获取到的数据:\n\n";
echo json_encode($result, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . "\n\n";
if (isset($result['code'])) {
echo "响应码: " . $result['code'] . "\n";
}
if (isset($result['msg'])) {
echo "响应消息: " . $result['msg'] . "\n";
}
if (isset($result['datas'])) {
echo "商品数量: " . count($result['datas']) . "\n";
if (!empty($result['datas'])) {
echo "\n📋 第一个商品信息:\n";
$firstProduct = $result['datas'][0];
echo " - SPU ID: " . ($firstProduct['i_id'] ?? 'N/A') . "\n";
echo " - 商品名称: " . ($firstProduct['name'] ?? 'N/A') . "\n";
echo " - 售价: " . ($firstProduct['s_price'] ?? 'N/A') . "\n";
echo " - 市场价: " . ($firstProduct['market_price'] ?? 'N/A') . "\n";
echo " - 成本价: " . ($firstProduct['c_price'] ?? 'N/A') . "\n";
if (isset($firstProduct['skus']) && is_array($firstProduct['skus'])) {
echo " - SKU数量: " . count($firstProduct['skus']) . "\n";
if (!empty($firstProduct['skus'])) {
echo "\n 📋 第一个SKU:\n";
$firstSku = $firstProduct['skus'][0];
echo " - SKU ID: " . ($firstSku['sku_id'] ?? 'N/A') . "\n";
echo " - SKU名称: " . ($firstSku['properties_value'] ?? 'N/A') . "\n";
echo " - 售价: " . ($firstSku['sale_price'] ?? 'N/A') . "\n";
}
}
}
}
}
} catch (\Throwable $e) {
echo "❌ HaichaoJstServices测试失败: " . $e->getMessage() . "\n";
echo "错误文件: " . $e->getFile() . ":" . $e->getLine() . "\n";
echo "\n堆栈跟踪:\n" . $e->getTraceAsString() . "\n\n";
}
echo "\n========================================\n";
echo "测试完成\n";
echo "========================================\n";
} catch (\Throwable $e) {
echo "\n❌ 发生错误!\n";
echo "错误信息: " . $e->getMessage() . "\n";
echo "错误文件: " . $e->getFile() . ":" . $e->getLine() . "\n";
echo "\n堆栈跟踪:\n" . $e->getTraceAsString() . "\n";
exit(1);
}