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

131 lines
4.7 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.
This file contains Unicode characters that might be confused with other characters. 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';
echo "========================================\n";
echo "聚水潭Token状态检查\n";
echo "========================================\n\n";
$app = new App();
$app->initialize();
echo "✅ 应用初始化成功!\n\n";
try {
echo "1️⃣ 读取当前配置...\n\n";
$envFile = __DIR__ . '/.env';
$envContent = file_get_contents($envFile);
preg_match('/JST_APP_KEY\s*=\s*(.*)/', $envContent, $matches);
$appKey = isset($matches[1]) ? trim($matches[1]) : '';
preg_match('/JST_APP_SECRET\s*=\s*(.*)/', $envContent, $matches);
$appSecret = isset($matches[1]) ? trim($matches[1]) : '';
preg_match('/JST_ACCESS_TOKEN\s*=\s*(.*)/', $envContent, $matches);
$accessToken = isset($matches[1]) ? trim($matches[1]) : '';
echo "JST_APP_KEY: " . $appKey . "\n";
echo "JST_APP_SECRET: " . (empty($appSecret) ? '❌ 未配置' : '✅ 已配置') . "\n";
echo "JST_ACCESS_TOKEN: " . (empty($accessToken) ? '❌ 未配置' : substr($accessToken, 0, 20) . '...') . "\n\n";
if (empty($appKey) || empty($appSecret) || empty($accessToken)) {
echo "⚠️ 配置不完整,请检查.env文件\n\n";
exit(1);
}
echo "2️⃣ 测试当前Token是否有效...\n\n";
try {
$haichaoJst = \app\haichao\HaichaoJstServices::getServices();
echo "正在调用API测试Token...\n";
$result = $haichaoJst->getProductListStand();
echo "✅ Token有效!\n\n";
if (!empty($result)) {
echo "📦 获取到 " . count($result) . " 条商品数据\n\n";
if (isset($result[0])) {
echo "📋 示例商品:\n";
$product = $result[0];
echo json_encode($product, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . "\n\n";
}
}
} catch (\Throwable $e) {
echo "❌ Token无效: " . $e->getMessage() . "\n\n";
echo "3️⃣ 尝试通过用户名密码登录获取新Token...\n\n";
preg_match('/JST_LOGIN_ACCOUNT\s*=\s*(.*)/', $envContent, $matches);
$loginAccount = isset($matches[1]) ? trim($matches[1]) : '';
preg_match('/JST_LOGIN_PASSWORD\s*=\s*(.*)/', $envContent, $matches);
$loginPassword = isset($matches[1]) ? trim($matches[1]) : '';
echo "登录账号: " . (empty($loginAccount) ? '❌ 未配置' : $loginAccount) . "\n";
echo "登录密码: " . (empty($loginPassword) ? '❌ 未配置' : '✅ 已配置') . "\n\n";
if (empty($loginAccount) || empty($loginPassword)) {
echo "⚠️ 无法刷新Token,缺少登录凭证\n";
echo "请在.env文件中添加:\n";
echo "JST_LOGIN_ACCOUNT=你的聚水潭账号\n";
echo "JST_LOGIN_PASSWORD=你的聚水潭密码\n\n";
exit(1);
}
echo "正在尝试登录...\n";
try {
$haichaoJst->authLogin($loginAccount, $loginPassword);
$envContent = file_get_contents($envFile);
preg_match('/JST_ACCESS_TOKEN\s*=\s*(.*)/', $envContent, $matches);
$newToken = isset($matches[1]) ? trim($matches[1]) : '';
echo "✅ 登录成功! 新Token: " . substr($newToken, 0, 20) . "...\n\n";
echo "4️⃣ 再次测试API...\n\n";
$result = $haichaoJst->getProductListStand();
echo "✅ API调用成功!\n\n";
if (!empty($result)) {
echo "📦 获取到 " . count($result) . " 条商品数据\n\n";
if (isset($result[0])) {
echo "📋 示例商品:\n";
$product = $result[0];
echo json_encode($product, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . "\n\n";
}
}
} catch (\Throwable $e2) {
echo "❌ 登录失败: " . $e2->getMessage() . "\n\n";
echo "请检查:\n";
echo "1. 聚水潭账号密码是否正确\n";
echo "2. 聚水潭应用是否已授权\n";
echo "3. 应用Key和Secret是否正确\n\n";
}
}
echo "========================================\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);
}