mogreet/mogreet-php

Mogreet PHP 库

dev-master 2013-11-12 00:34 UTC

This package is not auto-updated.

Last update: 2024-09-24 03:23:23 UTC


README

这是一个 Mogreet API 的 PHP 封装。测试和通过包管理器安装封装器的解决方案即将推出。

安装

目前,您只能通过检出此仓库来使用 mogreet-php。其他方法将在以后添加。

首先克隆 git 仓库

git clone https://github.com/jperichon/mogreet-php.git

然后包含客户端

require_once('/path/to/mogreet-php/Mogreet.php');

使用示例

创建客户端

require_once('/path/to/mogreet-php/Mogreet.php');

$clientId = 'xxxxx' // Your Client ID from https://developer.mogreet.com/dashboard
$token = 'xxxxx' // Your token from https://developer.mogreet.com/dashboard
$client = new Mogreet($clientId, $token);

ping

$response = $client->system->ping();
print $response->message;

向一个收件人发送短信

$response = $client->transaction->send(array(
    'campaign_id' => 'xxxxx', // Your SMS campaign ID from https://developer.mogreet.com/dashboard
    'to' => '9999999999',
    'message' => 'This is super easy!'
));
print $response->messageId;

向一个收件人发送 MMS

$response = $client->transaction->send(array(
    'campaign_id' => 'xxxxx', // Your MMS campaign ID from https://developer.mogreet.com/dashboard
    'to' => '9999999999',
    'message' => 'This is super easy!',
    'content_url' => 'https://wp-uploads.mogreet.com/wp-uploads/2013/02/API-Beer-sticker-300dpi-1024x1024.jpg'
));
print $response->messageId;

上传媒体文件

$response = $client->media->upload(array(
    'type' => 'image',
    'name' => 'mogreet logo',
    'file' => '/path/to/image/mogreet.png',
    // to ingest a file already online, use: 'url' => 'https://wp-uploads.mogreet.com/wp-uploads/2013/02/API-Beer-sticker-300dpi-1024x1024.jpg'
));
print $response->media->smartUrl;
print '<br/>';
print $response->media->contentId;

列出所有媒体

$response = $client->media->listAll();
foreach($response->mediaList as $media) {
    print $media->contentId . ' => ' . $media->name . ' ' . $media->smartUrl . '<br />';
}

注意

使用响应对象,您可以打印 API 调用的纯 JSON 响应(print $response),或者直接访问一个字段(例如:$response->message)。

由于 'list' 关键字限制以及 PHP 中现有的 'empty()' 函数,我更改了以下 API 调用的映射

  • $client->*->listAll() 映射到方法 list
  • $client->list->pruneAll() 映射到 'list.empty'

完整文档

Mogreet API 的完整文档可在此处找到

先决条件

  • PHP >= 5.4
  • PHP JSON 扩展