PHP code example of qingze-lab / esignbao-sdk-php

1. Go to this page and download the library: Download qingze-lab/esignbao-sdk-php 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/ */

    

qingze-lab / esignbao-sdk-php example snippets


use QingzeLab\ESignBao\Client;
use QingzeLab\ESignBao\Config\Configuration;

$config = new Configuration(
    appId: 'your_app_id',
    appSecret: 'your_app_secret',
    apiBaseUrl: 'https://smlopenapi.esign.cn' // 沙箱环境
);

$client = new Client($config);

// 1. 上传文件
$uploadResult = $client->file()->uploadFileByPath('./contract.pdf');
$fileId = $uploadResult['data']['fileId'];

// 2. 创建签署流程
$flowResult = $client->signFlow()->createByFile(
    docs: [
        ['fileId' => $fileId, 'fileName' => '合同.pdf']
    ],
    signFlowConfig: [
        'signFlowTitle' => '测试合同签署',
        'autoStart' => true,
        'autoFinish' => true
    ],
    signers: [
        [
            'signerType' => 0, // 个人签署
            'psnSignerInfo' => ['psnAccount' => '188****8888'],
            'signFields' => [
                ['fileId' => $fileId, 'posPage' => '1', 'posX' => 100, 'posY' => 100]
            ]
        ]
    ]
);
$signFlowId = $flowResult['data']['signFlowId'];

// 3. 获取签署链接
$signUrl = $client->signFlow()->getSignUrl(
    signFlowId: $signFlowId,
    operator: ['psnAccount' => '188****8888']
);

echo "签署链接: " . $signUrl['data']['shortUrl'];