nextgen-tech / multiinfo
0.0.2
2021-08-17 11:55 UTC
Requires
- guzzlehttp/guzzle: ^6.2.1|^7.3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpstan/phpstan: ^0.12.85
- psy/psysh: ^0.10.4
README
本包旨在帮助与Plus MultiInfo API进行通信。
实现的端点
该包实现了API的大部分请求、解析器和响应
发送
SendSms- 发送短消息(最多160个字符)SendSmsRaw- 发送二进制消息SendSmsLong- 发送长消息(最多1377个字符)Package- 发送短消息包
接收
GetSms- 读取接收到的消息
状态
InfoSms- 获取已发送消息的状态PackageInfo- 获取已发送包的状态
要求
安装
composer require nextgen-tech/multiinfo
使用方法
首先,您需要初始化基本类。
use NGT\MultiInfo\Certificate; use NGT\MultiInfo\Credentials; use NGT\MultiInfo\Handler; use NGT\MultiInfo\Url; use NGT\MultiInfo\Connections\HttpConnection; // Create instance of credentials. $credentials = new Credentials( $login, // Login of API user $password, // Password of API user $serviceId // Service ID ); // Create instance of certificate. $certificate = new Certificate( $path, // Path to certificate (CURLOPT_SSLCERT) $privateKeyPath, // Path to certificate private key (CURLOPT_SSLKEY) $password, // Certificate password (CURLOPT_SSLCERTPASSWD) $type // Certificate type - defaults to PEM (CURLOPT_SSLCERTTYPE) ); // Create instance of API URL. $url = Url::api1(); // or URL::api2(), depends of service configuration // Create instance of connection. $connection = new HttpConnection($url, $certificate); // Create handler instance. $handle = new Handler($connection);
然后您可以创建请求,通过处理器发送它并接收响应。
$request = new \NGT\MultiInfo\Requests\SendSmsRequest($credentials); $request->setContent('message'); // Required, content of the message $request->setDestination('48123456789'); // Required, phone number of the recipient $request->setValidTo(new DateTime('+7 days')); // Optional, period of validity of the message $request->setRequestDeliveryNotification(true); // Optional, indicates whether the delivery notification should be requested $request->setZeroClass(true); // Optional, indicates whether the message should be sent as zero class $request->setAdvancedEncoding(true); // Optional, indicates whether the message should use advanced encoding $request->setDeleteWhenProcessed(true); // Optional, indicates whether the message should be deleted after processing. $request->setReplyTo(12345); // Optional, ID of message to which the message is replying $request->setOrigin('CUSTOM'); // Optional, origin (nadpis) of the message. /** @var \NGT\MultiInfo\Responses\SendSmsResponse */ $response = $handler->handle($request); $response->getMessageId(); // ID of the message $response->getSender(); // Phone number of the sender $response->getReceiver(); // Phone number of the receiver $response->getContentType(); // Content type of the message $response->getContent(); // Content of the message $response->getProtocolId(); // ID of the protocol $response->getCodingScheme(); // Coding scheme $response->getServiceId(); // ID of the service $response->getConnectorId(); // ID of the connector $response->getReceivedAt(); // Date of receiving message
每个端点都有自己的请求、解析器和响应。强烈建议查看Requests和Responses目录,以获取所有可用方法列表。