krve/inmobile

此包已被放弃,不再维护。未建议替代包。

用于发送短信的Inmobile PHP SDK

v0.4.0 2021-05-06 15:29 UTC

This package is auto-updated.

Last update: 2024-02-10 02:14:53 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

Inmobile SMS网关

此存储库已被废弃,取而代之的是新的Inmobile PHP API客户端:官方SDK

这是一个PHP包,用于使用Inmobile发送短信。Inmobile是一个短信网关。

有关其API的更多信息,请参阅此处:https://docs.inmobile.dk/

入门

使用composer安装此包,并查看以下文档以了解如何使用此包。

composer require krve/inmobile

发送消息

use Krve\Inmobile\Gateway;
use Krve\Inmobile\Message;

$gateway = new Gateway('api-key');

$response = $gateway->send(
    Message::create('Hello World')
        ->from('MyCompany')
        ->to(4500000000)
);

$response->toArray();

/**
 * [
 *     ['msisdn' => '4500000000', 'id' => 'id-1']
 * ] 
 */

设置回调URL

use Krve\Inmobile\Gateway;
use Krve\Inmobile\Message;

$gateway = new Gateway('api-key');

$response = $gateway->send(
    Message::create('Hello World')
        ->from('MyCompany')
        ->to(4500000000),
    'https://example.com/callback'
);

错误处理

如果您向Inmobile发送请求,并且请求失败,它会抛出GatewayErrorException异常。此异常包含Inmobile错误代码以及根据代码的异常消息。

// Response code is -11

$exception->getMessage(); // "Inmobile error: OverchargeDonationLimitExceeded"
$exception->getInmobileErrorCode(); // -11 

如果未找到Inmobile的状态代码,它具有以下异常消息

$exception->getMessage(); // "ERROR: unknown response from inmobile. Response code was {statusCode}"