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)。有关更多信息,请参阅许可证文件