messageway / messagewayphp
此 SDK 允许您从 PHP 应用程序连接到 MSGWay.com 服务器。
v2.0.0
2023-10-29 11:12 UTC
Requires
- php: >=7.4
- ext-curl: *
- ext-json: *
Requires (Dev)
- phpunit/phpunit: 9.5.x-dev
README
MessageWay PHP SDK
MessageWay API 的 PHP SDK。 (波斯语 🇮🇷)
可用方法
要求
- 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