php Laravel中的Docusign远程签名集成

pwuypxnk  于 2023-02-15  发布在  PHP
关注(0)|答案(1)|浏览(141)

有没有人能提供laravel中docusign远程签名的参考我知道在github上已经有纯php中可用的代码,但它对我不起作用,我搜索了与laravel相关的代码,但在互联网上的任何地方都没有找到。
我期待在laravel中的引用,而不是在普通的php中。有人能帮助我吗?

wljmcqd8

wljmcqd81#

https://www.docusign.com/blog/developers/send-document-laravel-jwt-grant-authentication提供了使用Laravel执行此操作的所有详细信息
下面是PHP代码:

$apiClient = new ApiClient();
$apiClient->getOAuth()->setOAuthBasePath(env('DS_AUTH_SERVER')); 
try{
    $accessToken = $this->getToken($apiClient);
} catch (\Throwable $th) {
    return back()->withError($th->getMessage())->withInput();
}
$userInfo = $apiClient->getUserInfo($accessToken);
$accountInfo = $userInfo[0]->getAccounts();
$envelopeDefenition = $this->buildEnvelope($request);
try {            
     $envelopeApi = new EnvelopesApi($apiClient);
     $result = $envelopeApi->createEnvelope($accountInfo[0]->getAccountId(), $envelopeDefenition);
     } catch (\Throwable $th) {
        return back()->withError($th->getMessage())->withInput();
}  

private function getToken(ApiClient $apiClient) : string{
        try {
            $privateKey = file_get_contents(storage_path(env('DS_KEY_PATH')),true);
            $response = $apiClient->requestJWTUserToken(
                $ikey = env('DS_CLIENT_ID'),
                $userId = env('DS_IMPERSONATED_USER_ID'),
                $key = $privateKey,
                $scope = env('DS_JWT_SCOPE')
            );        
            $token = $response[0];
            $accessToken = $token->getAccessToken();
        } catch (\Throwable $th) {
            throw $th;
        }    
        return $accessToken;        
}

相关问题