bahricanli/netgsm-php

Netgsm API 的 PHP 客户端库

1.0.1 2023-04-04 13:48 UTC

This package is not auto-updated.

Last update: 2024-09-18 17:08:02 UTC


README

Latest Version on Packagist Software License Build Status StyleCI Scrutinizer Code Quality Code Coverage Total Downloads

本包提供了一种易于使用的 Netgsm 服务,它可以与 XML 和 Http API 一起使用。

此包提供了一种同时使用 XML 和 Http API 的 Netgsm 服务。

要查看土耳其语版本,请访问: BENIOKU

内容

安装

您可以通过 composer 安装此包。

composer require bahricanli/Netgsm-php

设置 Netgsm 服务

您需要注册 Netgsm 才能使用此通道。

使用方法

首先,使用您希望的客户实现启动 NetgsmService。

  • NetgsmXmlClient
  • NetgsmHttpClient(这是一个实际类似 Rest 的客户端,但供应商将他们的 API 这样命名。)
require __DIR__ . '/../vendor/autoload.php';

use BahriCanli\Netgsm\NetgsmService;
use BahriCanli\Netgsm\NetgsmService;
use BahriCanli\Netgsm\ShortMessageFactory;
use BahriCanli\Netgsm\Http\Clients\NetgsmXmlClient;
use BahriCanli\Netgsm\Http\Clients\NetgsmHttpClient;
use BahriCanli\Netgsm\ShortMessageCollectionFactory;

$service = new NetgsmService(new NetgsmXmlClient(
    'sms.Netgsm.net/xml',
    'username',
    'password',
    'outboxname'
), new ShortMessageFactory(), new ShortMessageCollectionFactory());

// ya da

$service = new NetgsmService(new NetgsmHttpClient(
    new GuzzleHttp\Client(),
    'https://sms.Netgsm.net/http',
    'username',
    'password',
    'outboxname'
), new ShortMessageFactory(), new ShortMessageCollectionFactory());

可用方法

成功启动您的 NetgsmService 实例后,使用以下方法之一发送短信消息。

单条消息 - 单个或多个收件人

$response = $service->sendShortMessage(['5530000000', '5420000000'], 'This is a test message.');

if($response->isSuccessful()) {
    // storeGroupIdForLaterReference is not included in the package.
    storeGroupIdForLaterReference($response->groupId());
} else {
    var_dump($response->message());
    var_dump($response->statusCode());
    var_dump($response->status());
}

多条消息 - 多个收件人

请注意,如果您使用该方法,每条消息只能有一个收件人。(这也是一个 API 限制,我没有破解。)

$response2 = $service->sendShortMessages([[
    'recipient' => '5530000000',
    'message' => 'This is a test.',
], [
    'recipient' => '5420000000',
    'message' => 'This is another test.',
]]);

if($response2->isSuccessful()) {
    // storeGroupIdForLaterReference is not included in the package.
    storeGroupIdForLaterReference($response2->groupId());
} else {
    var_dump($response2->message());
    var_dump($response2->statusCode());
    var_dump($response2->status());
}

交叉引用

$response->groupId() 如果客户端是 NetgsmHttpClient 将引发 BadMethodCallException。 $response->messageReportIdentifiers() 如果客户端是 NetgsmXmlClient 将引发 BadMethodCallException。

小心更改客户端实现。

变更日志

有关最近更改的更多信息,请参阅 CHANGELOG

测试

$ composer test

安全

如果您发现任何安全相关的问题,请通过电子邮件 bahri@bahri.info 而不是使用问题跟踪器。

贡献

有关详细信息,请参阅 CONTRIBUTING

鸣谢

许可

MIT 许可证(MIT)。有关更多信息,请参阅 许可文件