vhtvn/vht-rest-client

vht 网络服务的示例库

v1.0.2 2017-01-21 08:58 UTC

This package is auto-updated.

Last update: 2024-08-29 03:58:09 UTC


README

VHT RESTful API 的示例代码

简介

特性

该库的特性包括以下内容。

安装

此库可在 Packagist 上获取。安装此库的推荐方法是使用 Composer

$ php composer.phar require vhtvn/vht-rest-client dev-master

用法

在测试以下代码之前,我们必须引入 php 文件 "autoload.php"

require(BASE_DIR . 'vendor/autoload.php');

空时

$apiKey       = ''; // your apikey
$apiSecretKey = ''; // your apisecret
$mac          = \Vht\Common\VhtHelper::buildMacForAuthentication(array($apiKey, $apiSecretKey));
$airtime      = new \Vht\Airtime($apiKey, $mac);

$balance      = $airtime->get('getbalances');
if ($airtime->getLastResponse()['headers']['http_code'] === 200) {
    echo "Success\n";
    print_r($balance);
} else {
    echo "Fail\n";
    print_r($airtime->getLastRequest());
    print_r($airtime->getLastResponse());
    print_r($balance);
}

--
$params = array(
    'action' => $action,
    'apikey' => $apiKey,
    'servicecode' => $serviceCode,
    'account' => $account,
    'amount' => $amount,
    'trace' => $trace,
    'timestamp' => $timeStamp,
);
$mac          = \Vht\Common\VhtHelper::buildMacForAuthentication(array($action, $apiKey, $serviceCode, $account, $amount, $trace, $timeStamp, $apiSecretKey));
$airtime      = new \Vht\Airtime($apiKey, $mac);

$topup  = $airtime->get('topups', $params);
if ($airtime->getLastResponse()['headers']['http_code'] === 200) {
    echo "Success\n";
    print_r($topup);
} else {
    echo "Fail\n";
    print_r($airtime->getLastRequest());
    print_r($airtime->getLastResponse());
    print_r($topup);
}

ZMS

$apiKey       = ''; // your apikey
$apiSecretKey = ''; // your apisecret
$zmsObj       = new \Vht\Zms($apiKey, $apiSecretKey);

$params = array(
    'phone' => '',
    'message' => 'The content of the message',
    'sms' => 'Content of SMS message',
    'is_notify' => true,
);

$result = $zmsObj->post('zalophones/text', $params);
if ($zmsObj->getLastResponse()['headers']['http_code'] === 201) {
    echo "Success\n";
} else {
    echo "Fail\n";
    print_r($zmsObj->getLastRequest());
    print_r($zmsObj->getLastResponse());
    print_r($result);
}

SMS

$apiKey    = ''; // your apikey
$apiSecret = ''; // your apisecret
$brandName = new \Vht\SmsBrandName($apiKey);
//$brandName->verifySsl = false;

$params['submission'] = array(
    'api_key' => $apiKey,
    'api_secret' => $apiSecret,
    'sms' => array(
        array(
            'id' => (string) \Ramsey\Uuid\Uuid::uuid4(),
            'brandname' => 'VHT',
            'text' => 'Form VHT with love',
            'to' => '' //your phone 0xxx
        )
    )
);

$result = $brandName->post('ccsms', ($params));
if ($brandName->getLastResponse()['headers']['http_code'] === 200) {
    echo "Success\n";
} else {
    echo "Fail\n";
    print_r($brandName->getLastRequest());
    print_r($brandName->getLastResponse());
    print_r($brandName->getLastError());
    print_r($result);
}