Collection of Tencent Cloud Communication Web Services API Adapter for Laravel 5
Provides convenient way of setting up and making requests to Tencent Cloud Communication Web Services API from Laravel application., (*1)
For services documentation, APP key and Usage Limits visit:
* Tencent Cloud Communication Services Documentation
* Tencent Cloud Communication Services APP Key
* Tencent Cloud Communication Services Price and Quota
* Tencent Cloud Communication Services Usage Limit, (*2)
**SPECIAL THANKS TO Alexpechkarev. Part of web services engine is borrowed from Alexpechkarev/google-maps., (*3)
- Account Management
- Send Message
- Push Notifications
- Group Management
- Profile Picture Management
- Chain Relationship Management
- Chat Censor Management
- Data Download
- Online Status
- Global Chat Restriction Management
Dependency
Installation
Issue following command in console:, (*4)
composer require imphinite/tencent-cloudcomm
Alternatively edit composer.json by adding following line and run composer update
, (*5)
"require": {
....,
"imphinite/tencent-cloudcomm",
},
Configuration
Register package service provider and facade in 'config/app.php', (*6)
'providers' => [
...
CloudComm\ServiceProvider\CloudCommServiceProvider::class,
]
'aliases' => [
...
'CloudComm' => CloudComm\Facades\CloudComm::class,
]
Publish configuration file using php artisan vendor:publish --tag=cloudcomm --force
or simply copy package configuration file and paste into config/cloudcomm.php
, (*7)
Open configuration file config/cloudcomm.php
and
1. Add your app key
2. Add your appication admin identifier
3. Add your admin usersig
(All of above are obtained from your App in Tencent Cloud Communication Services Console), (*8)
/*
|----------------------------------
| SDK App ID
|------------------------------------
*/
'sdkappid' => 'YOUR APP ID',
...,
/*
|----------------------------------
| Identifier
|------------------------------------
*/
'identifier' => 'YOUR APP ADMIN IDENTIFIER',
...,
/*
|----------------------------------
| UserSig
|------------------------------------
*/
'usersig' => 'YOUR ADMIN USERSIG',
If you like to use different admins for any of the services, you can overwrite master admin identifier and usersig by specifying them in the service
array for selected web service., (*9)
Usage
Import this package at the top of your file:, (*10)
use CloudComm;
...
Here is an example of making request to Tencent-hosted Account Registration API:, (*11)
$service = CloudComm::load('register-account')
->setParam([
'Identifier' => 'testaccount1',
'IdentifierType' => 3, // refer to Tencent documentation
'Password' => 'Testaccount1Password!'
]);
$response = $service->get();
...
Alternatively parameters can be set using setParamByKey()
method. For deeply nested array use "dot" notation as per example below., (*12)
$service = CloudComm::load('register-account')
->setParamByKey('Identifier', 'testaccount1')
->setParamByKey('IdentifierType', 3)
->setParamByKey('Password', 'Testaccount1Password!'); //return $this
...
Another example showing request to Get User Status API:, (*13)
$service = CloudComm::load('get-user-status')
->setParam([
'To_Account' => [
'testaccount1',
'testaccount2'
]
]);
$response = $service->get();
...
Available methods
load( $serviceName )
- load web service by name, (*14)
Accepts string as parameter, web service name as specified in configuration file.
Returns reference to it's self., (*15)
CloudComm::load('nearbysearch')
...
setParamByKey( $key, $value )
- set request parameter using key:value pair, (*16)
Accepts two parameters:
* key
- body parameter name
* value
- body parameter value, (*17)
Deeply nested array can use 'dot' notation to assign value.
Returns reference to it's self., (*18)
$service = CloudComm::load('register-account')
->setParamByKey('Identifier', 'testaccount1')
->setParamByKey('IdentifierType', 3)
->setParamByKey('Password', 'Testaccount1Password!'); //return $this
...
setParam( $parameters )
- set all request parameters at once, (*19)
Accepts array of parameters
Returns reference to it's self., (*20)
$service = CloudComm::load('register-account')
->setParam([
'Identifier' => 'testaccount1',
'IdentifierType' => 3, // refer to Tencent documentation
'Password' => 'Testaccount1Password!'
]);
...
* get()
- perform web service request (irrespectively to request type POST or GET ), (*21)
$response = CloudComm::load('register-account')
->setParam([
'Identifier' => 'testaccount1',
'IdentifierType' => 3, // refer to Tencent documentation
'Password' => 'Testaccount1Password!'
])->get();
var_dump(json_decode($response)); // output
...
MIT License
Collection of Tencent Cloud Communication Web Services API Adapter for Laravel 5 is released under the MIT License., (*22)