2017-10-10 79 views
9

在我的wp項目中,我使用Assently來實現電子簽名。雖然我有一個帳戶,並創建了一個由用戶填寫的PDF格式文件,但我無法繼續。我發現文檔不清楚。 另外我不清楚需要做什麼,以便用戶將被顯示出來處理交易。如何在PHP中集成電子簽名交易的異步API

因此,任何幫助/建議繼續前進表示讚賞。

我嘗試了以下基於assently-laravel。但它要求我登錄。這裏有什麼錯誤? 代碼:

define('ASSENTLY_DEBUG', true); 
define('ASSENTLY_KEY', 'key'); 
define('ASSENTLY_SECRET', 'secret-generated'); 

include_once('assently/Assently.php'); 
$assently = new Assently(); 
$assently->authenticate(ASSENTLY_KEY, ASSENTLY_SECRET); 

$url = 'https://test.assently.com/api/v2/createcasefromtemplate'; 
$default = array(
    'Id' => '5a0e0869-'.rand(1111, 9999).'-4b79-'.rand(1111, 9999).'-466ea5cca5ce' 
); 
$data = array(
    'auth' => $assently->auth(), 
    'templateId' => '0e004e2b-b192-4ce2-8f47-d7a4576d7df6', 
    'newCaseId' => '5a0e0869-'.rand(1111, 9999).'-4b79-'.rand(1111, 9999).'-466ea5cca5ce', 
    'agentUsername' => '' 
); 

$data = array(
     'json' => $data 
    ); 
    $options = array(
     'http' => array(
      'header' => "Content-type: application/json; charset=utf-8\r\n", 
      'method' => 'POST', 
      'content' => http_build_query($data) 
     ) 
    ); 
    $context = stream_context_create($options); 
    $result = file_get_contents($url, false, $context); 
    echo '<pre>'; print_r($result);die; 
+0

https://test.assently.com/api#communication什麼不清楚? – Stefan

+0

@Stefan我無法理解如何在點擊後顯示pdf可填寫表格,然後完成整個交易。 –

+0

@Stefan你可以提供一些關於如何做或在這裏指導我的代碼。 –

回答

0

創建這個類裏面assently文件夾

use Assently\AssentlyCase; 
use Exception; 

class CustomAssentlyCase extends AssentlyCase 
{ 
    public function createFromTemplate($data) 
    { 
     $default = [ 
      'newCaseId' => '5a0e0869-'.rand(1111, 9999).'-4b79-'.rand(1111, 9999).'-466ea5cca5ce' 
     ]; 

     $json = array_merge($default, $data); 

     try{ 
      $response = $this->client->post($this->url('createcasefromtemplate'), [ 
       'auth' => $this->assently->auth(), 
       'json' => $json 
      ]); 

     }catch(Exception $e){ 
      print_r($e->getMessage()); 
     } 
     return $response; 
    } 
} 

使用

define('ASSENTLY_DEBUG', true); 
define('ASSENTLY_KEY', 'key'); 
define('ASSENTLY_SECRET', 'secret-generated'); 

include_once('assently/Assently.php'); 
include_once('assently/CustomAssentlyCase.php'); 
$assently = new Assently(); 
$assently->authenticate(ASSENTLY_KEY, ASSENTLY_SECRET); 

$data = array(
    'templateId' => '0e004e2b-b192-4ce2-8f47-d7a4576d7df6', 
    'newCaseId' => '5a0e0869-'.rand(1111, 9999).'-4b79-'.rand(1111, 9999).'-466ea5cca5ce', 
    'agentUsername' => 'agentUsername' // PUT your agent username here it is required 
); 

$customAssentlyCase = new CustomAssentlyCase($assently); 
$result = $customAssentlyCase->createFromTemplate($data); 
print_r($result); 

試試這個,雖然沒有測試,但應該工作。祝你好運。