PHP code example of coze / api

1. Go to this page and download the library: Download coze/api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

coze / api example snippets


use GuzzleHttp\Client;
use Coze\Auth\OAuthClient;

$appId = 'your_app_id'; // 应用ID
$publicKey = 'your_app_public_key'; // 公钥指纹
$privateKey = file_get_contents('./private_key.pem'); // 私钥

$client = new Client([
            'base_uri' => 'https://api.coze.cn',
            'timeout' => 5,
        ]);

$oauth = new OAuthClient($clientId, $publicKey, $clientSecret, $client);

$oauth->getAccessToken();
/**
 * [
 *  'expires_in' => 1000000000, 过期时间戳
 *  'access_token' => 'xxxxx'
 * ]
 */

use Coze\Workflow\Run;

$workflowId = 10002312312; // 工作流ID

$run = new Run($client, $workflowId);

$params = []; // 工作流中自定义的传参内容
$run->handle($params)