slicklabs/mailchimp 问题修复 & 功能扩展

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

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

slicklabs/mailchimp

Composer 安装命令:

composer require slicklabs/mailchimp

包简介

MailChimp API v3 wrapper for PHP

README 文档

README

Created with the single purpose to communicate with the MailChimp API v3 as straight forward as possible with proper error handling.

  • Uses Guzzle to make HTTP requests to the MailChimp API
  • Build for the future, PSR-1, PSR-2 & PSR-7 compliant
  • Very flexible, easily extend the MailChimp class and create your own business logic
  • Able to set MailChimp API key on the fly

Usage

Because the simple nature of this library you can call the MailChimp API methods by the desired HTTP request method.

First of all you have to include the MailChimp class.

require 'vendor/autoload.php';

use SlickLabs\MailChimp\MailChimp;
use SlickLabs\MailChimp\Exception\ResponseException;

$MailChimp = new MailChimp('MAILCHIMP-API-KEY');

For retrieving the MailChimp lists

try {
    $response = $MailChimp->get("lists");
    echo '<pre>'; print_r($response->getBody()); echo '</pre>';
} catch(ResponseException $e) {
    echo $e->getStatusCode().'<br />';
    echo $e->getTitle().'<br />';
    echo $e->getType().'<br />';
    echo $e->getDetail().'<br />';
}

Or adding a new subscriber to a list.

$args = [
    "body" => [
        "email_address" => "myemail@myemail.com",
        "status" => "pending"
    ]
];

try {
    $response = $MailChimp->post("lists/LIST-ID/members", $args);
    echo '<pre>'; print_r($response->getBody()); echo '</pre>';
} catch(ResponseException $e) {
    echo $e->getStatusCode().'<br />';
    echo $e->getTitle().'<br />';
    echo $e->getType().'<br />';
    echo $e->getDetail().'<br />';
}

Or updating an existing subscriber of a list.

use SlickLabs\MailChimp\Subscriber;

$args = [
    "body" => [
        "status" => "subscribed"
    ]
];

$subscriberHash = Subscriber::hash("myemail@myemail.com");

try {
    $response = $MailChimp->put('lists/LIST-ID/members/'.$subscriberHash, $args);
    echo '<pre>'; print_r($response->getBody()); echo '</pre>';
} catch(ResponseException $e) {
    echo $e->getStatusCode().'<br />';
    echo $e->getTitle().'<br />';
    echo $e->getType().'<br />';
    echo $e->getDetail().'<br />';
}

Or deleting a subscriber of a list.

use SlickLabs\MailChimp\Subscriber;

$subscriberHash = Subscriber::hash("myemail@email.com");
try {
    $response = $MailChimp->delete("lists/LIST-ID/members/".$subscriberHash);
    echo '<pre>'; print_r($response->getBody()); echo '</pre>';
} catch(ResponseException $e) {
    echo $e->getStatusCode().'<br />';
    echo $e->getTitle().'<br />';
    echo $e->getType().'<br />';
    echo $e->getDetail().'<br />';
}

Installation

Add MailChimp to your composer.json file. If you are not using Composer, you should be. It's an excellent way to manage dependencies in your PHP application.

{  
  "require": {
    "slicklabs/mailchimp": "dev-master"
  }
}

Then at the top of your PHP script require the autoloader:

require 'vendor/autoload.php';

Contributing

This is a fairly simple wrapper, but it can be made much better by contributions from those using it. If you'd like to suggest an improvement, please raise an issue to discuss it before making your pull request.

Pull requests for bugs are more than welcome - please explain the bug you're trying to fix in the message.

统计信息

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

GitHub 信息

  • Stars: 3
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-06-23