如何在PHP中集成Assently API以进行电子签名交易

26
在我的wp项目中,我正在使用Assently进行电子签名实现。虽然我有一个帐户并创建了一个pdf表单文件供用户填写,但我无法继续下去。我发现文档不清楚。 同时,我不清楚需要做什么才能向用户显示表单以处理交易。 因此,任何帮助/建议都将不胜感激。 我已尝试了基于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;

https://test.assently.com/api#communication 有什么不清楚的地方吗? - Stefan
@Stefan,我不知道如何在点击后显示可填写的PDF表格,然后完成整个交易。 - samjhana joshi
@Stefan,你能提供一些代码或者在这里指导我吗? - samjhana joshi
您在请求中没有发送身份验证。您已经通过身份验证,但在请求中没有发送身份验证信息。请检查一下。 - rkj
@RKJ 不行,它没有起作用 :( - samjhana joshi
显示剩余2条评论
1个回答

1
在 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);

尝试这个,虽然没有经过测试但应该可以工作。祝好运。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接