isapp/ai-spamdetector 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

isapp/ai-spamdetector

最新稳定版本:1.0.0

Composer 安装命令:

composer require isapp/ai-spamdetector

包简介

Protect your contact forms from spam and bots using AI. Lightweight, flexible, and powered by OpenAI GPT for smarter filtering.

README 文档

README

AI SpamDetector is a lightweight, framework-agnostic PHP library designed to intelligently detect spam in form submissions using OpenAI’s GPT models. It analyzes message content, user metadata, and email patterns to help you prevent unwanted or bot-generated form entries with minimal setup.

AI SpamDetector Latest Version on Packagist Total Downloads

Installation

You can install the package via composer:

composer require isapp/ai-spamdetector

Basic Usage

use Isapp\AiSpamdetector\Client;use Isapp\AiSpamdetector\FormData;use Isapp\AiSpamdetector\SpamDetector;

$client = new Client(apiKey: getenv('OPENAI_API_KEY'), organization: getenv('OPENAI_ORGANIZATION'),model: 'gpt-4');
$detector = new SpamDetector(client: $client);

$form = new FormData(
    name: 'James Bond',
    email: 'freeprizes@cheapbiz.com',
    message: 'Click here for FREE cash!!!',
    userAgent: $_SERVER['HTTP_USER_AGENT'] ?? null,
);

$isNotSpam = $detector->analyze($form); // returns true if message is not spam

Class: FormData

The FormData class acts as a structured container for submitted form data. It supports optional fields and omits null values when serialized to JSON.

Constructor

new FormData(
    string $email,
    string $message,
    ?string $name = null,
    ?string $firstName = null,
    ?string $lastName = null,
    ?string $phoneNumber = null,
    ?string $userAgent = null
)

Properties

Property Type Description
name ?string Full name (if not split into first/last)
firstName ?string First name
lastName ?string Last name
phoneNumber ?string Phone number
email ?string Email address
message string The message content
userAgent ?string Browser user-agent (optional)

Methods

  • toJson(): string
    Serializes the form to JSON, skipping all null fields.

Class: Client

The Client class is a lightweight wrapper around the official OpenAI PHP client. It simplifies authentication and allows you to specify a model.

Constructor

new Client(
    string $apiKey,
    ?string $organization = null,
    string $model = 'gpt-4'
)

Methods

  • make(): \OpenAI\Client
    Returns the underlying openai-php/client instance.

  • getModel(): string
    Returns the currently configured OpenAI model (e.g., gpt-4).

These methods allow you to configure the client before making requests:

  • setApiKey(string $apiKey): static - Sets a new OpenAI API key.

  • setModel(string $model): static - Sets the model to be used (e.g. gpt-4, gpt-3.5-turbo).

  • setOrganization(?string $organization): static - Sets the OpenAI organization ID (optional).

  • setProject(?string $project): static - Sets the OpenAI project ID (optional).

  • setBaseUri(string $baseUri): static - Sets a custom API base URI (default: api.openai.com/v1).

All setters return $this, allowing fluent configuration.

Contributing

Contributions are welcome! If you have suggestions for improvements, new features, or find any issues, feel free to submit a pull request or open an issue in this repository.

Thank you for helping make this package better for the community!

License

This project is open-sourced software licensed under the MIT License.

You are free to use, modify, and distribute it in your projects, as long as you comply with the terms of the license.

Maintained by ISAPP and ISAP OÜ.
Check out our software development services at isap.me.

统计信息

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

GitHub 信息

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

其他信息

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