用于生成 HelloSign 模板和签名 url 的 Nodejs 代码:
const opts = {
clientId,
test_mode: 1,
template_id: 'template_id',
/* title: 'embedded draft Title',
subject: 'embedded draft sub',
message: 'embedded draft msg', */
signers: [
{
name: 'Sherlock',
role: 'LandLord',
email_address: 'sherlock@holmes.co.uk',
}, {
name: 'Watson',
role: 'Tenant',
email_address: 'watson@holmesdetective.co.uk'
}
],
custom_fields: [
{
// name: '6d3683a7-38bd-4e19-93e7-e56ccb38dc50',
name: 'FullNameLL',
value: 'Sherlock',
required: true,
editor: 'LandLord'
},
{
// name: 'c8c2a147-0ddc-4db8-aa8f-0ed3476635e7',
name: 'EmailLL',
value: 'sherlock@holmes.co.uk',
required: true,
editor: 'LandLord'
},
{
// name: '0197265f-842e-4acd-928c-fe02ff91536b',
name: 'FullNameT',
value: 'Watson',
required: true,
editor: 'Tenant'
},
{
// name: 'd852aa44-e766-4682-93b1-8064ed4bee5a',
name: 'EmailT',
value: 'watson@holmesdetective.co.uk',
required: true,
editor: 'Tenant'
}]
};
const rslt = await hellosign.signatureRequest.createEmbeddedWithTemplate(opts);
const landlordSign = rslt.signature_request.signatures[0];
const tenantSign = rslt.signature_request.signatures[1];
console.info(rslt.signature_request);
const signatureId = landlordSign.status_code === 'signed' ? tenantSign.signature_id : landlordSign.signature_id;
const url = await hellosign.embedded.getSignUrl(signatureId);
// console.info(url);
return res.status(http_status.OK).send(url);
在前端,只需使用 npm 包 hellosign-embedded 到 client.open 签名 url。
import HelloSign from 'hellosign-embedded';
client.open(signUrl, {
testMode: true,
debug: true,
});
client.on('sign', () => {
alert('The document has been signed!');
});
当模板在 iFrame 中打开以进行签名时,自定义字段不会预先填充上面 opts 中使用的客户数据。