messagemedia/webhooks-sdk

MessageMedia Webhooks 允许您订阅一个或多个事件。当其中一个事件被触发时,会向您选择的 URL 发送 HTTP 请求,附带消息或有效负载。简单来说,它允许应用程序“交流”并自动接收通知。

1.0.0 2018-06-26 05:30 UTC

This package is auto-updated.

Last update: 2024-09-16 19:21:05 UTC


README

Travis Build Status Pull Requests Welcome PHP version

MessageMedia Webhooks 允许您订阅一个或多个事件。当其中一个事件被触发时,会向您选择的 URL 发送 HTTP 请求,附带消息或有效负载。简单来说,它允许应用程序“交流”并自动接收通知。

Webhooks Flow

目录

🔐 身份验证

身份验证通过 API 密钥完成。在 https://developers.messagemedia.com/register/ 上注册以获取您的 API 密钥。

请求通过 HTTP Basic Auth 或 HMAC 进行身份验证。将您的 API 密钥作为 auth_user_name,将 API 密钥作为 auth_password。

⁉️ 错误

我们的 API 返回标准的 HTTP 成功或错误状态码。对于错误,我们还会在响应中编码额外的错误信息。下面列出了最常见的状态码。

HTTP 状态码

📰 信息

Slack 和邮件列表

如果您有任何问题、评论或担忧,请加入我们的 Slack 频道: https://developers.messagemedia.com/collaborate/slack/

或者您可以通过电子邮件联系我们: developers@messagemedia.com

错误报告

如果您发现 SDK 中存在问题,我们希望了解。您可以通过 问题 报告或发送电子邮件至: developers@messagemedia.com

贡献

我们欢迎您对如何最好地提供 SDK 以简化您在应用程序中消费我们服务的想法。您可以创建分支和拉取请求以添加您希望看到的任何功能或通过 问题 报告

⭐ 安装

运行 Composer 命令安装 Messages SDK 的最新稳定版本

composer require messagemedia/webhooks-sdk

🎬 入门

入门非常简单。只需将您从 MessageMedia 开发者门户 获得的 API 密钥和密钥输入到下面的代码片段中。

创建 webhook

<?php
require_once('vendor/autoload.php');

$basicAuthUserName = 'YOUR_API_KEY'; // The username to use with basic authentication
$basicAuthPassword = 'YOUR_SECRET_KEY'; // The password to use with basic authentication

$client = new MessageMediaWebhooksLib\MessageMediaWebhooksClient($basicAuthUserName, $basicAuthPassword);

$webhooks = $client->getWebhooks();

$body = new MessageMediaWebhooksLib\Models\CreateWebhookRequest();
$body->url = "http://webhook.com/asdasd";
$body->method = "POST";
$body->encoding = "JSON";
$body->headers = array("x-your-webhook-custom-header" => "custom-value");
$body->events = array("RECEIVED_SMS");
$body->template = '{"id":"$mtId","status":"$statusCode"}';

$result = $webhooks->createWebhook($body);

检索所有 webhook

<?php
require_once('vendor/autoload.php');

$basicAuthUserName = 'YOUR_API_KEY'; // The username to use with basic authentication
$basicAuthPassword = 'YOUR_SECRET_KEY'; // The password to use with basic authentication

$client = new MessageMediaWebhooksLib\MessageMediaWebhooksClient($basicAuthUserName, $basicAuthPassword);

$webhooks = $client->getWebhooks();

$page  =  0;
$pageSize  =  10;

$result  =  $webhooks->retrieveWebhook($page, $pageSize);
print_r($result);

更新 webhook

您可以通过查看上面示例的响应中每个 webhook 的 id 来获取 webhook ID。

<?php
require_once('vendor/autoload.php');

$basicAuthUserName = 'YOUR_API_KEY'; // The username to use with basic authentication
$basicAuthPassword = 'YOUR_SECRET_KEY'; // The password to use with basic authentication

$client = new MessageMediaWebhooksLib\MessageMediaWebhooksClient($basicAuthUserName, $basicAuthPassword);

$webhooks = $client->getWebhooks();

$webhookId = "YOUR_WEBHOOK_ID";

$body = new MessageMediaWebhooksLib\Models\CreateWebhookRequest();
$body->url = "http://webhook.com/some_new_url";
$body->method = "POST";
$body->encoding = "JSON";
$body->headers = array("Account" => "teasdasdst");
$body->events = array("RECEIVED_SMS");
$body->template = '{"id":"$mtId","status":"$statusCode"}';


$result = $webhooks->updateWebhook($webhookId, $body);

删除 webhook

您可以通过查看检索 webhook 示例的响应中每个 webhook 的 id 来获取 webhook ID。

<?php
require_once('vendor/autoload.php');

$basicAuthUserName = 'YOUR_API_KEY'; // The username to use with basic authentication
$basicAuthPassword = 'YOUR_SECRET_KEY'; // The password to use with basic authentication

$client = new MessageMediaWebhooksLib\MessageMediaWebhooksClient($basicAuthUserName, $basicAuthPassword);

$webhooks = $client->getWebhooks();

$webhookId = "YOUR_WEBHOOK_ID";

$webhooks->deleteWebhook($webhookId);

📕 API 参考文档

查看完整的API文档以获取更详细的信息。

😕需要帮助吗?

请联系开发者支持邮箱developers@messagemedia.com,或访问开发者门户developers.messagemedia.com

📃 许可证

Apache许可证。请参阅LICENSE文件。