承接 buchin/sendfox-integration 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

buchin/sendfox-integration

最新稳定版本:v0.1.2

Composer 安装命令:

composer require buchin/sendfox-integration

包简介

A Laravel package for integrating with the SendFox API.

README 文档

README

This package provides a simple integration with the SendFox API for Laravel applications. It allows you to create contacts using the SendFox API.

Installation

  1. Add the package to your Laravel project:

    composer require buchin/sendfox-integration
  2. Publish the configuration file:

    php artisan vendor:publish --tag=config
  3. Add the required environment variables to your .env file:

    SENDFOX_TOKEN=your_sendfox_api_token
    SENDFOX_URL=https://api.sendfox.com/contacts
    SENDFOX_LIST_ID=your_list_id

Usage

Creating a Contact

You can use the SendFoxService to create a contact:

use Buchin\SendFoxIntegration\SendFoxService;

$service = new SendFoxService();

$user = (object) [
    'email' => 'test@example.com',
    'first_name' => 'Test',
    'last_name' => 'User',
];

$response = $service->createContact($user);

if ($response->successful()) {
    echo "Contact created successfully!";
} else {
    echo "Failed to create contact.";
}

Automatically Sending User to SendFox on Creation

You can use Laravel's model events to automatically send a user to SendFox when a user is created. For example, in your User model:

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;
use Buchin\SendFoxIntegration\SendFoxService;

class User extends Model
{
    protected static function booted()
    {
        static::created(function ($user) {
            $service = new SendFoxService();

            $nameParts = explode(' ', $user->name, 2);
            $firstName = $nameParts[0] ?? '';
            $lastName = $nameParts[1] ?? '';

            $response = $service->createContact((object) [
                'email' => $user->email,
                'first_name' => $firstName,
                'last_name' => $lastName,
            ]);

            if ($response->successful()) {
                Log::info('Contact created successfully in SendFox.');
            } else {
                Log::error('Failed to create contact in SendFox.', $response->json());
            }
        });
    }
}

Testing

The package includes its own tests. To run the tests, navigate to the package directory and run:

php artisan test packages/SendFoxIntegration/tests

Contributing

Contributions are welcome! Please submit a pull request or open an issue to discuss your ideas.

License

This package is open-sourced software licensed under the MIT license.

统计信息

  • 总下载量: 2.64k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-04