GMO Sign: Request for Timestamp

GMO Sign: Request for Timestamp

GMO サイン: タイムスタンプ付与依頼

This item send file and request add timestamp to GMO Sign.

Auto Step icon
Configs for this Auto Step
conf_OAuth2
C1: Secret Key *
cusId
C2: Customer id *#{EL}
accessUrl
C3: Access url *#{EL}
registFile
C5: File(Document) for timestamp *
confirmationId
C6: Confirmation Id *
Script (click to open)


//ファイルサイズ制限50MB
//https://helpcenter.gmosign.com/hc/ja/articles/900005461666
const SIZE_LIMIT = 52428800; //File size border of Box

/*
JSON例

・アクセストークン生成 AccessToken_Generate_Post
{
  "secret_key": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "cus_id": "XXXXXXXXXX"
}

・タイムスタンプ付与 Timestamp_Register_Post
{
  "secret_key": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  "cus_id": "XXXXXXXXXX",
  "access_token": "(取得したトークン)",
  "document": "(Base64変換したファイル)"
}
*/


main();

function main() {

    //// == 工程コンフィグの参照 / Config Retrieving ==
    //シークレットキーはHTTP認証設定のトークン直接指定に入れてもらう
    const key = configs.getObject("conf_OAuth2").getToken() + "";
    const cusId = configs.get("cusId") + "";
    const accessUrl = configs.get("accessUrl") + "";

    const dataId_accessToken = configs.get("accessToken");
    const dataId_confirmationId = configs.get("confirmationId");

    //// == ワークフローデータの参照 / Data Retrieving ==
    const files = engine.findData(configs.getObject("registFile"));


    //// == 演算 / Calculating ==

    //アクセストークン取得
    let accessToken = getAccessToken(key, cusId, accessUrl);

    //タイムスタンプ付与依頼
    let confirmationId = registFileForTimestamp(key, cusId, accessUrl, accessToken, files);


    //// == ワークフローデータへの代入 / Data Updating ==
    engine.setDataByNumber( dataId_confirmationId, confirmationId );


/* アクセスログがあれば
    if ( dataId_log !== "" ) {
        engine.setDataByNumber( dataId_log, accessLog );
    }
*/

}


/**
  * アクセストークン取得
  * @param {String} key  シークレットキー
  * @param {String} cusId  顧客ID
  * @param {String} accessUrl  接続先URL
  * @returns {String} アクセストークン
  */
function getAccessToken(key, cusId, accessUrl) {

    //JSON準備
    let requestObj = {};
    requestObj.secret_key = key;
    requestObj.cus_id = cusId;


    //HTTPリクエスト送付
    const url = "https://" + accessUrl + "/agree-api/v0/api/accesstoken/generate";
    const response = httpClient.begin()
        .body( JSON.stringify(requestObj), "application/json" )
        .post(url);
    const status = response.getStatusCode();
    const responseStr = response.getResponseAsString();
    if (status !== 200) {
        engine.log(responseStr);
        throw `Failed to get access token. status: ${status}`;
    }

    engine.log("responseStr:" + responseStr);//検証用
    const json = JSON.parse(responseStr);
    return json['result']['access_token'];
}


/**
  * タイムスタンプ付与
  * @param {String} key  シークレットキー
  * @param {String} cusId  顧客ID
  * @param {String} accessUrl  接続先URL
  * @param {String} accessToken  アクセストークン
  * @param {object} files  ファイル
  * @returns {String} 予約ID
  */
function registFileForTimestamp(key, cusId, accessUrl, accessToken, files) {

    //JSON準備
    let requestObj = {};
    requestObj.secret_key = key;
    requestObj.cus_id = cusId;
    requestObj.access_token = accessToken;

    //1ファイルのみかチェック
    if (( !files ) || ( files.length != 1 )) {
        throw `PDF File Num invalid.`;
    }
    const file = files.get(0);

    //ファイルサイズチェック
    if ( file.getLength() > SIZE_LIMIT ) {
        throw `PDF File size over.`;
    }

    //ファイルBase64変換
    let base64Text = "";
    fileRepository.readFile(file, SIZE_LIMIT, function(bytes) {
        base64Text += base64.encodeToString(bytes);
    });

    engine.log("requestObj:" + JSON.stringify(requestObj));//検証用、ファイルデータをいれる前をログ出力(ファイルデータが入ると長くなりすぎるので)
    requestObj.document = base64Text;


    //HTTPリクエスト送付
    const url = "https://" + accessUrl + "/agree-api/v0/api/ts/register";
    const response = httpClient.begin()
        .body( JSON.stringify(requestObj), "application/json" )
        .post(url);
    const status = response.getStatusCode();
    const responseStr = response.getResponseAsString();
    if (status !== 200) {
        engine.log(responseStr);
        throw `Failed to regist file. status: ${status}`;
    }

    engine.log("responseStr:" + responseStr);//検証用
    const json = JSON.parse(responseStr);
    return json['result']['confirmation_id'];
}

  
    

Download

warning Freely modifiable JavaScript (ECMAScript) code. No warranty of any kind.
(Installing Addon Auto-Steps are available only on the Professional edition.)

Notes

  • GMO Sign is a service provided by GMO GlobalSign Holdings, Inc.
  • GMO Sign’s time stamping is included in the Scan Document Management function, which is included in the Security and Internal Control Pack (Information current as of 2024-07-25. The configuration may change, so please check with the provider.)
  • To add a timestamp using GMO Sign, you need to use a combination of GMO Sign: Request for Timestamp and GMO Sign: Retrieve Timestamped File URL.
  • For “Secret Key”, “Customer ID”, and “Access URL”, please specify the values ​​provided by GMO GlobalSign Holdings, Inc. For “Secret Key”, please specify “Direct token specification” in “HTTP authentication settings”.

Capture

See Also

Scroll to Top

Discover more from Questetra Support

Subscribe now to keep reading and get access to the full archive.

Continue reading