定制 cherrypepper/adspower-api-client 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

cherrypepper/adspower-api-client

最新稳定版本:v0.1.3

Composer 安装命令:

composer require cherrypepper/adspower-api-client

包简介

A PHP client library for interacting with the AdsPower API.

README 文档

README

A PHP library for interacting with the AdsPower API.

Installation

You can install this package via Composer

  composer require cherrypepper/adspower-api-client

Requirements

  • PHP 7.4 or higher
  • PHP JSON extension
  • PHP cURL extension
  • Guzzle HTTP client

Configuration

<?php
use CherryPepper\AdsPower\AdsPowerClient;
use GuzzleHttp\Client;
use CherryPepper\AdsPower\Config\AdsPowerConfig;

$httpClient = new Client();
$config = new AdsPowerConfig(
    baseUri: 'http://local.adspower.net:50325',
    retryAttempts: 3,
    sleepDuration: 2
);

$adsPowerClient = new AdsPowerClient($httpClient, $config);

Usage

Starting browser:

<?php
use CherryPepper\AdsPower\AdsPowerClient;
use CherryPepper\AdsPower\DTO\Browser\BrowserStartParameters;
use CherryPepper\AdsPower\Exceptions\AdsPowerException;

// Initialize the client
$adsPowerClient = new AdsPowerClient($httpClient, $config);

// Parameters for starting the browser
$params = new BrowserStartParameters();
$params->user_id = 'h1yynkm'; // Replace with your actual user_id
$params->open_tabs = 1;
$params->launch_args = ["--window-position=400,0", "--blink-settings=imagesEnabled=false", "--disable-notifications"];

try {
    // Start the browser
    $browserResponse = $adsPowerClient->browser->start($params);
    echo "Browser started successfully." . PHP_EOL;
    print_r($browserResponse->data);
} catch (AdsPowerException $e) {
    echo "Error starting browser: " . $e->getMessage() . PHP_EOL;
}

Creating a Profile:

<?php
use CherryPepper\AdsPower\AdsPowerClient;
use CherryPepper\AdsPower\DTO\Profile\ProfileCreateParameters;
use CherryPepper\AdsPower\Exceptions\AdsPowerException;

// Initialize the client
$adsPowerClient = new AdsPowerClient($httpClient, $config);

// Parameters for creating a profile
$params = new ProfileCreateParameters();
$params->name = 'User A';
$params->group_id = '100'; // Replace with a valid group_id
$params->fingerprint_config = [
    'automatic_timezone' => '1',
    'language' => ['en-US', 'en'],
    'flash' => 'block',
    'fonts' => ['all'],
    'webrtc' => 'disabled',
    'ua' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)...',
];

try {
    // Create the profile
    $profileCreateResponse = $adsPowerClient->profiles->create($params);
    echo "Profile created with ID: " . $profileCreateResponse->data['id'] . PHP_EOL;
} catch (AdsPowerException $e) {
    echo "Error creating profile: " . $e->getMessage() . PHP_EOL;
}

Conclusion

This library provides a convenient way to interact with the AdsPower API to automate tasks related to managing browsers and profiles. You can extend the functionality by using other available methods in the client.

Note: Make sure to replace the example data (such as user_id and group_id) with actual values from your environment.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

If you have suggestions or want to contribute improvements, please create an issue or pull request in the project’s repository.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-23