如何在提升集成密钥后将文档签名演示配置为实时



我使用了嵌入式签名,在演示上成功运行后,提升了集成密钥并通过了审核。 我需要在代码中进行哪些更改?我需要在哪里放置提升的集成密钥?我知道现场没有像演示那样的令牌密钥集成,它只有 8 小时。

我把 https://demo.docusign.net/restapi 改成了 https://www.docusign.net/restapi

$dsConfig = array(
'ds_client_id' => isset($session->data['user_id']) ? $session->data['user_id'] : "1",
'ds_client_secret' => 'eyJ0eXAiOiJNVCIsImFsZxxxxxxxxxxxxxx',
'signer_email' => $customer->isLogged() ? $customer->getEmail() : 'user@example.com',
'signer_name' => $customer->isLogged() ? $customer->getFirstName() . ' ' . $customer->getLastName() : 'John Doe',
'app_url' => HTTPS_SERVER . 'public/agreement-accept.html',
'authorization_server' => 'https://demo.docusign.net/restapi',
'session_secret' => isset($session->data['token']) ? $session->data['token'] : md5(time()),
'allow_silent_authentication' => true,
'accountId' => 'xxxxxxx',
'templateId' => 'xxxxx-xxxx-xxx-xxx-xxxx'
);
$config = new Configuration();
$config->setHost($dsConfig['authorization_server']);
$config->addDefaultHeader(
"Authorization",
"Bearer " . $dsConfig['ds_client_secret']
);
$apiClient = new ApiClient($config);
https://docusign.net/restapi

不是有效的 API 端点。

要使用集成密钥进行 API 调用,您需要实施身份验证工作流之一,如下所述:https://developers.docusign.com/esign-rest-api/guides/authentication/

获得有效令牌后,需要进行用户信息调用以确定帐户的基本 URI:https://developers.docusign.com/esign-rest-api/guides/authentication/user-info-endpoints

我通过在 ApiClient Class 中创建 generateRefreshToken(( 函数来做到这一点:

public function generateRefreshToken($client_id = null, $client_secret = null, $refresh_token = null)
{
if (!$client_id) {
throw new InvalidArgumentException('Missing the required parameter $client_id when calling generateAccessToken');
}
if (!$client_secret || !$refresh_token) {
throw new InvalidArgumentException('Missing the required parameter $client_secret when calling generateAccessToken');
}
if (!$refresh_token) {
throw new InvalidArgumentException('Missing the required parameter $refresh_token when calling generateAccessToken');
}
$resourcePath = "/oauth/token";
$queryParams = array();
$integrator_and_secret_key = "Basic " . utf8_decode(base64_encode("{$client_id}:{$client_secret}"));
$headers = array(
"Authorization" => $integrator_and_secret_key,
"Content-Type" => "application/x-www-form-urlencoded",
);
$postData = array(
"grant_type" => "refresh_token",
"refresh_token" => $refresh_token
);
list($response, $statusCode, $httpHeader) = $this->callApi($resourcePath, self::$POST, $queryParams, $postData, $headers, null, null, true);
if(isset($response->access_token))
$this->config->addDefaultHeader("Authorization", "{$response->token_type} {$response->access_token}");
return array($this->getSerializer()->deserialize($response, 'DocuSigneSignClientAuthOAuthToken', $httpHeader), $statusCode, $httpHeader);
}
protected static function requestNewToken($refresh_token) {
$config = new Configuration();
$apiClient = new ApiClient($config);
$token = $apiClient->generateRefreshToken('clientid', 'secret_key', $refresh_token); 
return array($token[0]['access_token'],$token[0]['refresh_token'],time() + 86400 * 27);
}

protected static function getToken() {
$tokenFile = __DIR__ . '/token.json';
$access_token = null;
if (file_exists($tokenFile)) {
$data = json_decode(file_get_contents($tokenFile), true);
$access_token = $data['access_token']; // todo consider field names
$refresh_token = $data['refresh_token']; // todo consider field names
$expires_in = $data['expires_in']; // todo consider field names
if ($expires_in <= time()) {
$access_token = null;
}
}
if (!$access_token) {
list($access_token,$refresh_newtoken,$expires_in) = self::requestNewToken($refresh_token);
if (!$access_token || !$refresh_newtoken || !$expires_in) {
throw new Exception('Could not request new token.');
}
file_put_contents($tokenFile, json_encode(array(
'access_token' => $access_token, 
'refresh_token' => $refresh_newtoken, 
'expires_in' => $expires_in 
)));
}
return $access_token;
}

此外,https://www.docusign.net/restapi 是用于生产的有效 API 终结点。它对我有用。https://和万维网应该在那里...

$dsConfig = array(
'ds_client_id' => isset($session->data['user_id']) ? $session->data['user_id'] : "1",
// The app's DocuSign integration key's secret
'ds_client_secret' => $token,
'signer_email' => $customer->isLogged() ? $customer->getEmail() : 'user@example.com',
'signer_name' => $customer->isLogged() ? $customer->getFirstName() . ' ' . $customer->getLastName() : 'John Doe',
// return url
'app_url' => HTTPS_SERVER . 'public/agreement-accept.html',
'authorization_server' => 'https://www.docusign.net/restapi',
'session_secret' => isset($session->data['token']) ? $session->data['token'] : md5(time()),
'allow_silent_authentication' => true,
'accountId' => 'xxx',
'templateId' => 'xxxx'
);

最新更新