imphinite/tencent-cloudcomm

This is a Laravel package for server-end Tencent Cloud Communications API

1.0.0 2018-02-08 22:30 UTC

This package is not auto-updated.

Last update: 2024-05-21 02:58:20 UTC


README

Provides convenient way of setting up and making requests to Tencent Cloud Communication Web Services API from Laravel application.

For services documentation, APP key and Usage Limits visit:

**SPECIAL THANKS TO Alexpechkarev. Part of web services engine is borrowed from Alexpechkarev/google-maps.

Features

  • 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:

composer require imphinite/tencent-cloudcomm

Alternatively edit composer.json by adding following line and run composer update

"require": { 
		....,
		"imphinite/tencent-cloudcomm",
	
	},

Configuration

Register package service provider and facade in 'config/app.php'

'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

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)
    /*
    |----------------------------------
    | 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.

Usage

Import this package at the top of your file:

use CloudComm;
...

Here is an example of making request to Tencent-hosted Account Registration API:

$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.

$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:

$service = CloudComm::load('get-user-status')
    ->setParam([
        'To_Account'            => [
            'testaccount1',
            'testaccount2'
        ]
    ]);
$response = $service->get();
...

Available methods

load( $serviceName ) - load web service by name

Accepts string as parameter, web service name as specified in configuration file.
Returns reference to it's self.

CloudComm::load('nearbysearch') 
...

setParamByKey( $key, $value ) - set request parameter using key:value pair

Accepts two parameters:

  • key - body parameter name
  • value - body parameter value

Deeply nested array can use 'dot' notation to assign value.
Returns reference to it's self.

$service = CloudComm::load('register-account')
    ->setParamByKey('Identifier', 'testaccount1')
    ->setParamByKey('IdentifierType', 3)
    ->setParamByKey('Password', 'Testaccount1Password!');  //return $this
...

setParam( $parameters ) - set all request parameters at once

Accepts array of parameters
Returns reference to it's self.

$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 )
$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.