aracoool/salesforce-client

SalesForce REST API 客户端

1.0.4 2019-05-02 16:43 UTC

This package is auto-updated.

Last update: 2024-09-14 03:20:47 UTC


README

Salesforce / Force.com REST API PHP 客户端。虽然它更像是对 API 方法的包装,但它应该为您提供与 Salesforce REST API 交互所需的所有灵活性。

此组件基于以下文档的说明 这里

安装

composer require "aracoool/salesforce-client:^1.0"

使用方法

获取特定账户的信息

use SalesForce\Authentication\Authentication;
use SalesForce\Authentication\PasswordAuthentication;

require __DIR__ . '/vendor/autoload.php';

$client = new \SalesForce\ClientFactory::create(new PasswordAuthentication(
    Authentication::LIVE_HOST,
    'client id',
    'client secret',
    'username',
    'password + access token'
));

try {
    $result = $client->get('/sobjects/Account/0013600001UltKTAAZ');
    print_r($result);
} catch (Exception $e) {
    echo $e->getMessage() . PHP_EOL;
}

结果

stdClass Object
(
    [attributes] => stdClass Object
        (
            [type] => Account
            [url] => /services/data/v42.0/sobjects/Account/0013600001UltKTAAZ
        )

    [Id] => 0013600001UltKTAAZ
    ...
)

SOQL 和 SOQL 查询构建器的使用

...

$soqlBuilder = new \SalesForce\Soql\Builder();
$soqlBuilder->select(['name'])
    ->from('Account');

try {
    $result = $client->get($soqlBuilder->build());
    print_r($result);
} catch (Exception $e) {
    echo $e->getMessage() . PHP_EOL;
}

结果

stdClass Object
(
    [totalSize] => 10845
    [done] => 
    [nextRecordsUrl] => /services/data/v42.0/query/01g0x000004qMUXAA2-2000
    [records] => Array
        (
            [0] => stdClass Object
                (
                    [attributes] => stdClass Object
                        (
                            [type] => Account
                            [url] => /services/data/v42.0/sobjects/Account/0010x000003mP6UAAU
                        )

                    [Name] => John Smith
                )
                
                ...
        )
)