在Laravel 6中使用DocuSign,可以通过以下步骤实现:
composer require docusign/esign-client
config/docusign.php
的配置文件,并添加以下内容:return [
'integrator_key' => 'YOUR_INTEGRATOR_KEY',
'username' => 'YOUR_USERNAME',
'password' => 'YOUR_PASSWORD',
'base_path' => 'https://demo.docusign.net/restapi',
];
将YOUR_INTEGRATOR_KEY
替换为你的DocuSign集成商密钥,YOUR_USERNAME
和YOUR_PASSWORD
替换为你的DocuSign账户凭证。
app/Providers/DocuSignServiceProvider.php
的文件,并添加以下内容:<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use DocuSign\eSign\Client\ApiClient;
class DocuSignServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->singleton(ApiClient::class, function ($app) {
$config = $app['config']['docusign'];
$apiClient = new ApiClient($config['base_path']);
$apiClient->getOAuth()->setBasePath($config['base_path']);
$apiClient->configureJWTAuthorizationFlow(
$config['integrator_key'],
$config['username'],
$config['password'],
storage_path('docusign')
);
return $apiClient;
});
}
}
config/app.php
文件中,将DocuSignServiceProvider
添加到providers
数组中:'providers' => [
// ...
App\Providers\DocuSignServiceProvider::class,
],
ApiClient
来使用DocuSign服务。以下是一个示例控制器方法,用于创建一个DocuSign签署请求:<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DocuSign\eSign\Client\ApiClient;
use DocuSign\eSign\Model\EnvelopeDefinition;
use DocuSign\eSign\Model\Signer;
use DocuSign\eSign\Model\SignHere;
class DocuSignController extends Controller
{
public function createSignatureRequest(ApiClient $apiClient)
{
$envelopeDefinition = new EnvelopeDefinition([
'email_subject' => 'Please sign this document',
'documents' => [
[
'document_base64' => base64_encode(file_get_contents('path/to/document.pdf')),
'name' => 'Document.pdf',
'file_extension' => 'pdf',
'document_id' => '1',
],
],
'recipients' => new Signers([
'signers' => [
new Signer([
'email' => 'recipient@example.com',
'name' => 'Recipient Name',
'recipient_id' => '1',
'tabs' => new Tabs([
'sign_here_tabs' => [
new SignHere([
'document_id' => '1',
'page_number' => '1',
'recipient_id' => '1',
'tab_label' => 'SignHereTab',
'x_position' => '100',
'y_position' => '100',
]),
],
]),
]),
],
]),
'status' => 'sent',
]);
$envelopeApi = $apiClient->getEnvelopeApi();
$results = $envelopeApi->createEnvelope($accountId, $envelopeDefinition);
// 处理结果...
return response()->json(['message' => 'Signature request created']);
}
}
以上代码示例中,createSignatureRequest
方法使用ApiClient
实例创建了一个DocuSign签署请求。你可以根据实际需求进行修改和扩展。
这是在Laravel 6中使用DocuSign的基本步骤。对于更详细的文档和示例代码,你可以参考腾讯云的DocuSign产品介绍页面。
领取专属 10元无门槛券
手把手带您无忧上云