motveu/php-api-sdk
Composer 安装命令:
composer require motveu/php-api-sdk
包简介
PHP SDK for integration with JACON SMS and moTV.eu middleware
README 文档
README
This SDK can be used to integrate with moTV.eu (https://motv.eu) and JACON CSMS (https://jacon.cz).
Installation
The recommended way to install is via Composer:
composer require motveu/php-api-sdk
Usage
Usage is very easy. Just include the composer's autoloader and start using it.
Sample SMS commands
For full API documentation and test API endpoint please get in touch with JACON (or moTV.eu in case it was bundled with moTV.eu middleware).
<?php require_once __DIR__ . '/vendor/autoload.php'; $smsConnector = new \Motv\Connector\Sms\AdminConnector('https://sms.operator.tv', 'Username', 'secret...'); // create sample customer $viewersId = $smsConnector->Integration()->createMotvCustomer('test', 'myPassword'); // check whether there are any allowed products for the created customer $allowedProducts = $smsConnector->Sales()->getAllowedProductsForCustomer($viewersId); if (count($allowedProducts) === 0) { echo "No allowed products found!"; exit(1); } // in a real world, it will not be the first product but rather whatever the customer chooses on the selfcare website for example $products_id = array_pop($allowedProducts)['products_id']; // subscribe to first product $smsConnector->Integration()->subscribe($viewersId, $products_id); // and now let's cancel the subscription $smsConnector->Integration()->cancel($viewersId, $products_id); // get all subscription info $smsConnector->Subscription()->getCustomerSubscriptionInfo($viewersId); // retrieve all data that are saved about the customer (personal data, contacts, addresses, devices) $fullCustomerData = $smsConnector->Customer()->getData($viewersId); // get the moTV.eu device number, this number can be used when querying the MW API $motvDeviceId = $fullCustomerData['devices'][0]['device_motv_motv_id']; // clean up after our tests $smsConnector->Customer()->deleteCustomer($viewersId);
Sample Middleware commands
For full API documentation and test API endpoint please get in touch with moTV.eu.
<?php require_once __DIR__ . '/vendor/autoload.php'; $mwAdminConnector = new \Motv\Connector\Mw\AdminConnector('https://mw.operator.tv', 'Username', 'secret'); // get customer with internal ID 1 $customerEntity = $mwAdminConnector->Customer()->getData(1); $vendorsPairs = $mwAdminConnector->Vendor()->getPairs(); echo 'Login: ' . $customerEntity->customers_login; echo PHP_EOL; echo 'Vendor: ' . $vendorsPairs[$customerEntity->customers_vendors_id];
Works with entities, update, getData and selection
<?php require_once __DIR__ . '/vendor/autoload.php'; $mwAdminConnector = new \Motv\Connector\Mw\AdminConnector('https://mw.operator.tv', 'Username', 'secret'); // It creates input entity and fills it with data $personInputEntity = new \Motv\Connector\Mw\InputEntities\Mw\PersonEntity(); $personInputEntity->persons_type = \Motv\Connector\Mw\Enums\Mw\PersonEnum::ACTOR; $personInputEntity->persons_birthday = '1990-01-01'; // in case of date, both string and DateTime objects are accept $personInputEntity->persons_birthday = (new \DateTimeImmutable)->setTimestamp(strtotime('now')); $personInputEntity->persons_description = 'Popular actor'; $personInputEntity->persons_name = 'John Smith'; // Creates new Person $personsId = $mwAdminConnector->Person()->update(null, $personInputEntity); // Gets the new person we just created $personEntity = $mwAdminConnector->Person()->getData($personsId); echo 'Actor ' . $personEntity->persons_name . ' with ID: ' . $personEntity->persons_id; echo PHP_EOL; // Let's change name of the Person $personInputEntity->persons_name = 'Will Smith'; // Updates the name $mwAdminConnector->Person()->update($personsId, $personInputEntity); // Let's double-check that the changes were actually reflected $personEntity = $mwAdminConnector->Person()->getData($personsId); echo 'Actor ' . $personEntity->persons_name . ' with ID: ' . $personEntity->persons_id; echo PHP_EOL; // Select the person by selection function $selectedActorEntity = $mwAdminConnector->Person()->selection(['persons_name' => 'Will Smith'])['rows'][0]; echo 'Actor ' . $selectedActorEntity->persons_name . ' with ID: ' . $selectedActorEntity->persons_id; echo PHP_EOL; // sending invalid data will result into a neat error, for example $personInputEntity = new \Motv\Connector\Mw\InputEntities\Mw\PersonEntity(); $personInputEntity->persons_name = ''; $personInputEntity->persons_type = \Motv\Connector\Mw\Enums\Mw\PersonEnum::ACTOR; $personInputEntity->persons_birthday = '1990-01-01'; $personInputEntity->persons_description = 'Popular actor'; // Will not create a new person because name is empty, will throw an exception instead $personsId = $mwAdminConnector->Person()->update(null, $personInputEntity);
moTV VOD files upload
Files bigger than 20MB cannot be uploaded via the GUI nor via the API directly as there is limitation on the file size in place. It needs to be uploaded by chunks. We have prepared a sample script VodUpload.php. Please note that the script utilizes shell tool split to split the original file into chunks and therefore this will not work on Windows OS.
<?php require_once __DIR__ . '/vendor/autoload.php'; $vodUpload = new \Motv\Connector\Mw\VodUpload('https://mw.operator.tv', 'Username', 'secret', 'https://storage.operator.tv', 'temp_path'); $vodsId = 1; $this->vodUpload->uploadVodFile($vodsId, '/path/test.mp4');
Catching errors
There might be exceptions thrown in case of unexpected issues, for example that the customer does not exists. There is also UnknownApiException thrown in case when something unpredictable happened. And standard Guzzle (https://github.com/guzzle/guzzle) exceptions are thrown when issue with connection happens.
try { $fullCustomerData = $mwAdminConnector->Customer()->getData($customersId); } catch (\Motv\Mw\CustomerUnknownException $e) { echo "The customer does not exist!"; } catch (\Motv\Mw\UnknownApiException $e) { echo "Something went really wrong!" } catch (\GuzzleHttp\Exception\TransferException $e) { echo "Some connection issues!"; }
Logging
This SDK is shipped with Monolog (https://github.com/Seldaek/monolog) support. You can pass logger to the $connector->setLogger() method and all API communication will be logged
$mwAdminConnector = new \Motv\Connector\Mw\AdminConnector('https://mw.operator.tv', 'Username', 'secret'); $logger = new \Monolog\Logger('API'); $logger->pushHandler(new \Monolog\Handler\RotatingFileHandler('api.log', 14)); $logger->pushHandler(new \Monolog\Handler\StreamHandler('php://stdout')); $mwconnector->setLogger($logger);
Pro TIP
Use modern IDE such as PHP Storm. It will give you hints what are the method names as well as what are the parameter names and their types.
motveu/php-api-sdk 适用场景与选型建议
motveu/php-api-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15.83k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 11 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「sms」 「middleware」 「PHP API」 「motveu」 「jacon」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 motveu/php-api-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 motveu/php-api-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 motveu/php-api-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
SDK for payment gateway PlatbaMobilom.sk for PHP7.0
Slim Framework 3 CSRF protection middleware utilities
Extensible library for building notifications and sending them via different delivery channels.
Cloudflare Middleware For Guzzle
yii2-sms expand
统计信息
- 总下载量: 15.83k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2019-11-11