redeemly-likecard/luckycode-package
Composer 安装命令:
composer require redeemly-likecard/luckycode-package
包简介
Seamlessly integrate Redeemly LuckyCode rewards into any PHP application. This framework-agnostic PHP client provides full API coverage (pull, reveal, redeem, customer logs) with dedicated service providers and facades for Laravel, and straightforward integration for CodeIgniter and other PHP framew
README 文档
README
LuckyCode Integration Helper is a PHP library for integrating with the LuckyCode API. It provides a clean abstraction layer with typed request/response DTOs, automatic token management, and optional Laravel support for quick and seamless integration.
🧩 Features
✅ Framework-agnostic core (works with Laravel, Symfony, CodeIgniter, etc.) ✅ Optional Laravel bridge (Service Provider, Config, Routes) ✅ Guzzle-based HTTP client ✅ In-memory token caching and auto-refresh ✅ Strongly typed DTOs and consistent ApiResponse model ✅ Optional PSR-3 compatible logging
⚙ Requirements
- PHP 8.2+
- Composer
- Optional: Laravel 11 or 12
📦 Installation
🧱 Option 1 — Local Path Repository
In your main project’s composer.json, add the local path repository:
json { "repositories": [ { "type": "path", "url": "./laravel" } ] }
Then require the package:
bash composer require luckycode/integration-helper:dev-main
⚙ Configuration
Add the following environment variables (or your framework’s equivalent):
bash LUCKYCODE_BASE_URL=https://api.example.com LUCKYCODE_API_KEY=your_api_key_here LUCKYCODE_CLIENT_ID=your_client_id_here LUCKYCODE_SSL_VERIFY=true
💡 Usage (Framework-Agnostic)
php use LuckyCode\IntegrationHelper\Services\LuckyCodeService; use LuckyCode\IntegrationHelper\Models\PullCodeRequest;
$service = new LuckyCodeService( baseUrl: getenv('LUCKYCODE_BASE_URL') ?: 'https://api.example.com', apiKey: getenv('LUCKYCODE_API_KEY') ?: '', clientId: getenv('LUCKYCODE_CLIENT_ID') ?: '', sslVerify: true );
$request = new PullCodeRequest([ 'orderRef' => 'ORDER-001', 'customerRef' => 'CUST-001' ]);
$response = $service->pullCode($request);
if ($response->success) { print_r($response->data); } else { echo "Error: " . $response->error->message; }
🧩 Laravel Integration (Optional)
1️⃣ Publish Configuration (optional)
bash php artisan vendor:publish --tag=config --provider="LuckyCode\IntegrationHelper\IntegrationHelperServiceProvider"
This will create the config file:
config/luckycode.php
2️⃣ Add environment variables in .env
bash LUCKYCODE_BASE_URL=https://api.example.com LUCKYCODE_API_KEY=your_api_key_here LUCKYCODE_CLIENT_ID=your_client_id_here LUCKYCODE_SSL_VERIFY=true
3️⃣ Use it in your Laravel code
php use LuckyCode\IntegrationHelper\Services\Contracts\LuckyCodeServiceContract; use LuckyCode\IntegrationHelper\Models\PullCodeRequest;
$service = app(LuckyCodeServiceContract::class);
$response = $service->pullCode(new PullCodeRequest([ 'orderRef' => 'ORD-123', 'customerRef' => 'CUST-456', ]));
if ($response->success) { dd($response->data); } else { dd($response->error); }
🌐 Available Laravel Routes
If routes are enabled in your project, the following endpoints will be available:
| HTTP | Endpoint | Description |
|---|---|---|
| POST | /api/lucky-code/pull | Pull a single code |
| POST | /api/lucky-code/reveal | Reveal a code |
| POST | /api/lucky-code/redeem | Redeem a code |
| POST | /api/lucky-code/multi-pull | Pull multiple codes at once |
| GET | /api/lucky-code/check-serialcode?serialCode=CODE123 | Validate a serial code |
| GET | /api/lucky-code/customer-log?page=1&pageSize=30&customerRef=CUST001 | Retrieve customer code log |
🪵 Logging (Optional)
You can pass any PSR-3 compatible logger, or leave it null to disable logging.
php use Monolog\Logger; use Monolog\Handler\StreamHandler; use LuckyCode\IntegrationHelper\Services\LuckyCodeService;
$logger = new Logger('luckycode'); $logger->pushHandler(new StreamHandler(DIR.'/luckycode.log', Logger::INFO));
$service = new LuckyCodeService( baseUrl: 'https://api.example.com', apiKey: 'your_api_key', clientId: 'your_client_id', sslVerify: true, logger: $logger );
🔐 Security Notes
⚠ Never commit your API keys or client IDs to source control. Always use environment variables or a secure secret store.
🧾 Directory Structure
src/ ├── Models/ # DTO classes (PullCodeRequest, RevealCodeRequest, etc.) ├── Services/ # Service logic for LuckyCode API ├── Support/ # ApiResponse, ErrorDto, Helpers ├── Http/Controllers/ # Laravel bridge (optional) ├── IntegrationHelperServiceProvider.php # Laravel service provider config/ └── luckycode.php
🧠 Tips
-
Use multi-pull when you need to pull several codes in one request.
-
Use getCustomersLog to retrieve the customer’s prize or code history.
-
Every API call returns an ApiResponse object:
php $response->success; // bool $response->data; // mixed $response->error; // ErrorDto|null
🧰 Troubleshooting
| Problem | Possible Cause | Solution |
|---|---|---|
| SSL error | Self-signed certificate | Set LUCKYCODE_SSL_VERIFY=false (only in development) |
| “401 Unauthorized” | Invalid API key or client ID | Check .env values |
| Empty response | Wrong base URL | Make sure LUCKYCODE_BASE_URL points to the correct API |
| Timeout | API not reachable | Verify the endpoint or network connectivity |
🧩 License
MIT License © Redeemly LuckyCode Integration Helper
redeemly-likecard/luckycode-package 适用场景与选型建议
redeemly-likecard/luckycode-package 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 redeemly-likecard/luckycode-package 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 redeemly-likecard/luckycode-package 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 24
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 30
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-10-23