Skip to content

syslogic/php-hms

Repository files navigation

PHP SDK for Huawei REST API

Legal Disclaimer: This product is NOT officially endorsed or certified by Huawei Technologies Co., Ltd.
The trademarks are being referenced for identification purposes only, in terms of a nominative fair use.

The official Huawei repositories can be found there: @HMS-Core.

Goal

This project aims to abstract Huawei REST API, according to the official API documentation.

Project Status

PHP Composer

Class OAuth2 Status Android
Core\Wrapper working
AccountKit working
PushKit working
MapKit working
AdsKit working
AppGallery\AuthService AGC partially
AppGallery\Product AGC working
AppGallery\Project AGC partially
AppGallery\Publishing AGC partially Gradle Plugin
AppGallery\Report AGC working
AnalyticsKit * working
SearchKit * working
DriveKit * partially
WalletKit * partially
GameService - untested
CloudSms - untested

The endpoints marked with an asterisk require interactive two-legged oAuth2 flow; eg. see www
One can run these unit tests only with a previously cached user access token, obtained by login.
The AGC AppGallery Connect endpoints do require "team admin" API client credentials.

Prerequisites

This client can be configured with either an array, or with environmental variables.

AppGallery Connect API:

  • HUAWEI_CONNECT_API_CLIENT_ID
    The client ID can be obtained on the console
    below Users and permissions > API key > Connect API.

  • HUAWEI_CONNECT_API_CLIENT_SECRET
    The client key can be obtained on the console
    below Users and permissions > API key > Connect API.

When creating the API client, project should be set to value "N/A".

MapKit API:

  • HUAWEI_MAPKIT_API_KEY
  • HUAWEI_MAPKIT_SIGNATURE_KEY (optional)

PushKit API Client

  • HUAWEI_OAUTH2_CLIENT_ID The "App ID" is being passed as the Oauth2 client_id.
  • HUAWEI_OAUTH2_CLIENT_SECRET The "App Secret" is being passed as the Oauth2 client_secret.

Please refer to the documentation, which explains how to obtain these values:
Viewing App Basic Information.

PushKit API Server

  • HUAWEI_HMAC_VERIFICATION_KEY (optional)
    The HMAC verification key is unique to each upstream message webhook.
    The value can be obtained from each such webhook configuration form.

DriveKit API:

  • HUAWEI_OAUTH2_REDIRECT_URL A publicly accessible HTTPS URL.
  • HUAWEI_OAUTH2_API_SCOPE Default value: openid profile.

AnalyticsKit API:

  • HUAWEI_CONNECT_PROJECT_ID
Installation

One can manually check out into project directory lib:

mkdir lib
git clone [email protected]:syslogic/php-hms ./lib/php-hms

And then map namespace HMS in composer.json PSR-4 autoload block:

{
  "autoload": {
    "psr-4": {
      "App\\": "src/",
      "HMS\\": "lib/php-hms/src/"
    }
  }
}

One can also add a package repository composer.json:

{
  "repositories": [{
    "type": "package",
    "package": {
      "name": "syslogic/php-hms",
      "version": "master",
      "source": {
        "url": "https://github.com/syslogic/php-hms.git",
        "type": "git",
        "reference": "master"
      }
    }
  }]
}

To set up the environment, for example nano ~/.bashrc:

# General server-side oAuth2 flow.
export HUAWEI_OAUTH2_CLIENT_ID=...
export HUAWEI_OAUTH2_CLIENT_SECRET=...

# DriveKit client-side oAuth2 flow.
export HUAWEI_OAUTH2_REDIRECT_URL=...
export HUAWEI_OAUTH2_API_SCOPE=...

# MapKit API key.
export HUAWEI_MAPKIT_API_KEY=...

# AGC team_client_id.
export HUAWEI_CONNECT_TEAM_CLIENT_ID=...
export HUAWEI_CONNECT_TEAM_CLIENT_SECRET=...

# AGC project_client_id.
export HUAWEI_CONNECT_PROJECT_CLIENT_ID=...
export HUAWEI_CONNECT_PROJECT_CLIENT_SECRET=...

export HUAWEI_CONNECT_PRODUCT_ID=...
export HUAWEI_HMAC_VERIFICATION_KEY=...

PHPUnit

The test suite depends on further environmental variables:

Test Case Environmental Variable Description
PushKitTest PHPUNIT_HCM_TEST_DEVICE_TOKEN The HCM device registration ID, to which the test will push notifications to.
# PHP SDK for Huawei REST API
export PHPUNIT_HCM_TEST_DEVICE_TOKEN=...

Running tests:

composer run-script test

Running tests with code coverage on Windows:

composer run-script coverage_windows

Running tests with code coverage on Linux:

composer run-script coverage_linux

Generate documentation with phpDocumentor:

composer run-script docs

Known Issues

  • When receiving an Error 10021: Invalid clientId this may suggest,
    that the API which one tries to access is not enabled for the project.
    Enabling the desired API on the AppGallery Connect console should help.
  • MapKit endpoint routeService is not the Map Kit API, but Navi Kit API.
  • Huawei Cloud SMS doesn't seem to be available in Europe and Russia.

License

The PHP SDK for Huawei REST API (the library) is licensed under the MIT License.
The usage of these APIs depends on the HUAWEI Developers Service Agreement.

Support