softcomtecnologia/

softcom-api-php

1.0.7 2019-05-15 13:08 UTC

This package is not auto-updated.

Last update: 2024-09-29 04:37:10 UTC


README

本包旨在提供对Softcom API资源集成的抽象

安装

本包可通过Composer轻松安装。只需将以下代码段添加到项目中的composer.json文件即可:

    {
        "require": {
            "softcomtecnologia/softcom-api-php": "*"
        }
    }

使用示例

获取令牌

    $options = [
        'domain'        => 'http://<url-softcom>/softauth',
        'clientId'      => '<your-client-id>',
        'clientSecret'  => '<your-client-secret>',
        'deviceId'      => '<your-device-id>',
        'deviceName'    => '<name-for-your-device>',
    ];
    
    $provider = new SoftcomProvider($options);
    $token = $provider->getAccessToken(new SoftcomCredentials());
    
    echo $token;//your token ex.: 301b7689eb926495a02fe4ba4932d7bfa80aa202

执行请求

GET

    $options = [...];
    $provider = new SoftcomProvider($options);
    $token = 'your-token-string';//or SoftcomAccessToken object
    $url = '/api/example';//without domain
    $params = [
        'key' => 'value',
        //...
    ];
    
    $resource = $provider->get($token, $url, $params);
    
    echo json_decode($resource->getContents(), 1);
    /*
     * [
     *      "code" => 1,
     *      "message" => "OK",
     *      "human" => "Sucesso",
     *      "data" => [
     *          "username" => "my username",
     *          "name" => "softcom",
     *      ],
     *      "meta" => []
     * ]
     */

POST

    $options = [...];
    $provider = new SoftcomProvider($options);
    $token = 'your-token-string';//or SoftcomAccessToken object
    $url = '/api/example';//without domain
    $params = [
        'key' => 'value',
        //...
    ];
    
    $resource = $provider->post($token, $url, $params);
    
    echo json_decode($resource->getContents(), 1);
    /*
     * [
     *      "code" => 1,
     *      "message" => "OK",
     *      "human" => "Sucesso",
     *      "data" => [
     *          "username" => "my username",
     *          "name" => "softcom",
     *      ],
     *      "meta" => []
     * ]
     */