messageway/messagewayphp

此 SDK 允许您从 PHP 应用程序连接到 MSGWay.com 服务器。

v2.0.0 2023-10-29 11:12 UTC

This package is auto-updated.

Last update: 2024-08-29 13:06:26 UTC


README

messageWay

Latest Version on Packagist Total Downloads Swagger MessageWay

MessageWay PHP SDK

MessageWay API 的 PHP SDK。 (波斯语 🇮🇷)

可用方法

  • 短信(伊朗:2000,3000,9000,50004)
  • 全球短信(带 Twilio)
  • 消息传递
  • IVR

要求

  • PHP 7.4 或更高版本
  • ext-curl
  • ext-json
  • composer

安装

使用 Composer

$ composer require messageway/messagewayphp

要求

require dirname(__FILE__) . '/../vendor/autoload.php';
use MessageWay\Api\MessageWayAPI;

// Get apiKey from https://MSGWay.com/dashboard/document/
$apiKey = "";
$mobile = "";
$templateID = 3;
$messageWay = new MessageWayAPI($apiKey);

不使用 Composer

$ git clone git@github.com:MessageWay/MessageWayPHP.git

要求

require dirname(__FILE__) . '/MessageWayPHP/src/MessageWayAPI.php';
use MessageWay\Api\MessageWayAPI;

// Get apiKey from https://MSGWay.com/dashboard/document/
$apiKey = "";
$mobile = "";
$templateID = 3;
$messageWay = new MessageWayAPI($apiKey);

发送 OTP

通过短信

try {
	$otp = $messageWay->sendViaSMS($mobile, $templateID);
	echo "referenceID: " . $otp['referenceID'] . PHP_EOL;
	echo "sender: " . $otp['sender'] . PHP_EOL;
} catch (Exception $e) {
	echo "Error: " . $e->getMessage();
}

通过消息传递

try {
	$provider = $messageWay->getProviderByName('gap');
	$otp = $messageWay->sendViaMessenger($mobile, $templateID, $provider);
	echo "referenceID: " . $otp['referenceID'] . PHP_EOL;
	echo "sender: " . $otp['sender'] . PHP_EOL;
} catch (Exception $e) {
	echo "Error: " . $e->getMessage();
}

通过 IVR

$templateID = 2;
try {
	$otp = $messageWay->sendViaIVR($mobile, $templateID);
	echo "referenceID: " . $otp['referenceID'] . PHP_EOL;
	echo "sender: " . $otp['sender'] . PHP_EOL;
} catch (Exception $e) {
	echo "Error: " . $e->getMessage();
}

验证

try {
	$verify = $messageWay->verifyOTP($OTP, $mobile);
	echo "OTPVerify: " . $verify['status'] . PHP_EOL;
} catch (Exception $e) {
	echo "Error: " . $e->getMessage();
}

状态

try {
	$status = $messageWay->getStatus($OTPRefrenceID);
    echo "OTPStatus: " . $status['OTPStatus'] . PHP_EOL;
	echo "OTPVerified: " . $status['OTPVerified'] . PHP_EOL;
	echo "OTPMethod: " . $status['OTPMethod'] . PHP_EOL;
} catch (Exception $e) {
	echo "Error: " . $e->getMessage();
}

许可证

MIT