如何在PHP

时间:2017-10-10 10:25:45

标签: php wordpress payment

在我的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;

1 个答案:

答案 0 :(得分: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);

试试这个,虽然没经过测试但应该有效。祝你好运。