supermeteor/sdk-php

此库用于使用HTTP请求创建短信和电子邮件消息

v1.7.0 2024-04-03 16:25 UTC

This package is auto-updated.

Last update: 2024-09-03 17:33:53 UTC


README

Supermeteor是一个PHP SDK,用于创建云消息:WhatsApp、短信和电子邮件等

如何使用

使用Composer安装

composer require supermeteor/sdk-php

在你的文件中包含vendor/autoload.php

require_once '../vendor/autoload.php';
use Supermeteor\Client;

初始化SDK对象

$sm = new Supermeteor('<secret_key>');

1. 发送短信

将类型、电话、消息作为函数参数传递,以下是发送短信的示例函数调用。

类型必须是:sms

$result = $sm->SendMessage('<type>', '+XXXXXXXXX', 'your message');

2. 发送电子邮件

重要:必须预置自定义电子邮件发送者

将电子邮件、主题、消息作为函数参数传递,以下是发送电子邮件的示例函数调用。

$result = $sm->sendEmail('mail@email.com', 'subject', 'your message');

发送简单的WhatsApp消息

将免费消息作为函数参数传递,以下是发送WhatsApp的示例函数调用。

$fromPhone = '+852 6444 4444'
$toPhone = '+852 6888 8888'
$result = $sm->sendWhatsapp($fromPhone, $toPhone, 'your message');

WhatsApp模板消息

消息类型概述(示例)

SESSION消息示例

{
  "fromPhone": "+852 6111 2222",
  "secret": "{{secret}}",
  "phone": "+852 6333 4444",
  "message": "free text blah blah blah..."
}

代码示例

$supermeteor->sendWhatsapp($fromPhone, $toPhone, 'free text blah blah blah...');

模板消息示例

重要:模板消息必须与预定义的相同

示例:booking_confirmation

预先批准的消息

您好 {{1}},这是您在 {{2}} 的咨询确认。⭐我们目前在 {{3}}。⭐

{
  "fromPhone": "+852 6111 2222",
  "secret": "{{secret}}",
  "phone": "+852 6333 4444",
  "message": "",
  "template": {
    "name": "booking_confirmation",
    "language": {
      "policy": "deterministic",
      "code": "en"
    },
    "components": [
      {
        "type": "body",
        "parameters": [
          {
            "type": "text",
            "text": "Krishna"
          },
          {
            "type": "text",
            "text": "2022-06-11 10:00"
          },
          {
            "type": "text",
            "text": "4214 Lynn Street, Milton, MA"
          }
        ]
      }
    ]
  }
}

代码示例

$template = new \Supermeteor\WhatsappTemplateMessage(
    'booking_confirmation',
    'en',
    ['John', '2019-01-12']
);

// send a whatsapp template message
$supermeteor->sendWhatsapp($fromPhone, $toPhone, $template);

示例:call_back

预先批准的消息

您好 {{1}},刚刚给您打电话但未能接通,您何时方便回电在 {{2}}?

{
  "fromPhone": "+852 6111 2222",
  "secret": "{{secret}}",
  "phone": "+852 6333 4444",
  "template": {
    "name": "call_back",
    "language": {
      "policy": "deterministic",
      "code": "en"
    },
    "components": [
      {
        "type": "body",
        "parameters": [
          {
            "type": "text",
            "text": "Krishna"
          },
          {
            "type": "text",
            "text": "2022-06-11 10:00"
          }
        ]
      }
    ]
  }
}

示例:reminder

预先批准的消息

您好 {{1}},这是您在 {{2}} 的咨询提醒。⭐{{3}}⭐

{
  "fromPhone": "+852 6111 2222",
  "secret": "{{secret}}",
  "phone": "+852 6333 4444",
  "template": {
    "name": "greeting",
    "language": {
      "policy": "deterministic",
      "code": "en"
    },
    "components": [
      {
        "type": "body",
        "parameters": [
          {
            "type": "text",
            "text": "Krishna"
          },
          {
            "type": "text",
            "text": "2022-06-11 10:00"
          },
          {
            "type": "text",
            "text": "4214 Lynn Street, Milton, MA"
          }
        ]
      }
    ]
  }
}