为无帐户签名者DocuSign设置签名图像

时间:2013-07-23 02:32:32

标签: docusignapi

我想使用自己的逻辑来请求签名,但签名完成后,我想将签名图像(作为png)发送到DocuSign Envelope。我查看了“为无帐户签名者设置签名图像”流程,它似乎工作正常,但签名图像没有嵌入我的信封中。

这就是我正在做的事情

  1. 获取帐户信息
  2. 将模板中的信封创建为“已创建(草稿)”状态
  3. 添加收件人
  4. 添加签名选项卡
  5. 将信封状态从“已创建”更新为“已发送”
  6. 设置收件人的签名图像。
  7. 一切似乎都没有任何错误。但我没看到图像。如果我做错了或者您有任何将签名图像发送到信封的示例,请告诉我。

1 个答案:

答案 0 :(得分:0)

请随时与我们联系以获得更具创意的解决方案,但在iPad上获取签名的最简单方法是将签名图像集合委托给DocuSign。这是一种在模板上获取签名的方法(您也可以使用文档字节流)。这取自GitHub要点:https://gist.github.com/Ergin008/5645812

签名视图可以在iOS应用中的网页浏览中显示。

//
//  API Walkthrough 8 - Launch the signing (recipient) view of an envelope in an embedded session
//
//  To run this sample:
//      1.  Copy the below code into your iOS project
//      2.  Enter your email, password, integrator key, name, templateId, and roleName and save
//      3.  Run the code
//

- (void)embeddedSigning
{
    // Enter your info:
    NSString *email = @"<#email#>";
    NSString *password = @"<#password#>";
    NSString *integratorKey = @"<#integratorKey#>";
    NSString *name = @"<#name#>";

    // use same name as template role you saved through the Console UI
    NSString *roleName = @"<#roleName#>";

    // need to login to the console and copy a valid templateId into this string
    NSString *templateId = @"<#templateId#>";

    ///////////////////////////////////////////////////////////////////////////////////////
    // STEP 1 - Login (retrieves accountId and baseUrl)
    ///////////////////////////////////////////////////////////////////////////////////////

    NSString *loginURL = @"https://demo.docusign.net/restapi/v2/login_information";

    NSMutableURLRequest *loginRequest = [[NSMutableURLRequest alloc] init];
    [loginRequest setHTTPMethod:@"GET"];
    [loginRequest setURL:[NSURL URLWithString:loginURL]];

    // set JSON formatted X-DocuSign-Authentication header (XML format also accepted)
    NSDictionary *authenticationHeader = @{ @"Username": email, @"Password" : password, @"IntegratorKey" : integratorKey };

    // jsonStringFromObject() function defined below...
    [loginRequest setValue:[self jsonStringFromObject:authenticationHeader] forHTTPHeaderField:@"X-DocuSign-Authentication"];

    // also set the Content-Type header (other accepted type is application/xml)
    [loginRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

    //*** make an asynchronous web request
    [NSURLConnection sendAsynchronousRequest:loginRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *loginResponse, NSData *loginData, NSError *loginError) {

        if (loginError) {   // succesful GET returns status 200
            NSLog(@"Error sending request %@. Got Response %@ Error is: %@", loginRequest, loginResponse, loginError);
            return;
        }

        // we use NSJSONSerialization to parse the JSON formatted response
        NSError *jsonError = nil;
        NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:loginData options:kNilOptions error:&jsonError];
        NSArray *loginArray = responseDictionary[@"loginAccounts"];

        // parse the accountId and baseUrl from the response and use in the next request
        NSString *accountId = loginArray[0][@"accountId"];
        NSString *baseUrl = loginArray[0][@"baseUrl"];

        //--- display results
        NSLog(@"\naccountId = %@\nbaseUrl = %@\n", accountId, baseUrl);

        ///////////////////////////////////////////////////////////////////////////////////////
        // STEP 2 - Create Envelope via Template and send the envelope
        ///////////////////////////////////////////////////////////////////////////////////////

        // append "/envelopes" URI to your baseUrl and use as endpoint for signature request call
        NSString *envelopesURL = [NSString stringWithFormat:@"%@/envelopes",baseUrl];

        NSMutableURLRequest *signatureRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:envelopesURL]];

        [signatureRequest setHTTPMethod:@"POST"];
        [signatureRequest setURL:[NSURL URLWithString:envelopesURL]];

        // construct a JSON formatted signature request body (multi-line for readability)
        NSDictionary *signatureRequestData = @{@"accountId": accountId,
                                               @"emailSubject" : @"Embedded Sending API call",
                                               @"emailBlurb" : @"email body goes here",
                                               @"templateId" : templateId,
                                               @"templateRoles" : [NSArray arrayWithObjects: @{@"email":email, @"name": name, @"roleName": roleName, @"clientUserId": @"1001" }, nil ],
                                               @"status" : @"sent"
                                               };

        // convert request body into an NSData object
        NSData* data = [[self jsonStringFromObject:signatureRequestData] dataUsingEncoding:NSUTF8StringEncoding];

        // attach body to the request
        [signatureRequest setHTTPBody:data];

        // authentication and content-type headers
        [signatureRequest setValue:[self jsonStringFromObject:authenticationHeader] forHTTPHeaderField:@"X-DocuSign-Authentication"];
        [signatureRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

        // Send the signature request...
        [NSURLConnection sendAsynchronousRequest:signatureRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *envelopeResponse, NSData *envelopeData, NSError *envelopeError) {

            NSError *jsonError = nil;
            NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:envelopeData options:kNilOptions error:&jsonError];
            NSLog(@"Signature request sent, envelope info is: \n%@\n", responseDictionary);

            // parse envelopeId from resposne as it will be used in next request
            NSString *envelopeId = responseDictionary[@"envelopeId"];

            ///////////////////////////////////////////////////////////////////////////////////////
            // STEP 3 - Get the Embedded Signing View (aka recipient view) of the envelope
            ///////////////////////////////////////////////////////////////////////////////////////

            // append /envelopes/{envelopeId}/views/recipient to baseUrl and use in request
            NSString *embeddedURL = [NSString stringWithFormat:@"%@/envelopes/%@/views/recipient", baseUrl, envelopeId];

            NSMutableURLRequest *embeddedRequest = [[NSMutableURLRequest alloc] init];
            [embeddedRequest setHTTPMethod:@"POST"];
            [embeddedRequest setURL:[NSURL URLWithString:embeddedURL]];

            // simply set the returnUrl in the request body (user is directed here after signing)
            NSDictionary *embeddedRequestData = @{@"returnUrl": @"http://www.docusign.com/devcenter",
                                                  @"authenticationMethod" : @"none",
                                                  @"email" : email,
                                                  @"userName" : name,
                                                  @"clientUserId" : @"1001" // must match clientUserId set is step 2
                                                  };

            // convert request body into an NSData object
            NSData* data = [[self jsonStringFromObject:embeddedRequestData] dataUsingEncoding:NSUTF8StringEncoding];

            // attach body to the request
            [embeddedRequest setHTTPBody:data];

            // set JSON formatted X-DocuSign-Authentication header (XML format also accepted)
            NSDictionary *authenticationHeader = @{ @"Username": email, @"Password" : password, @"IntegratorKey" : integratorKey };

            // jsonStringFromObject() function defined below...
            [embeddedRequest setValue:[self jsonStringFromObject:authenticationHeader] forHTTPHeaderField:@"X-DocuSign-Authentication"];

            // also set the Content-Type header (other accepted type is application/xml)
            [embeddedRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

            //*** make an asynchronous web request
            [NSURLConnection sendAsynchronousRequest:embeddedRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *embeddedResponse, NSData *embeddedData, NSError *embeddedError) {

                if (embeddedError) {   // succesful POST returns status 201
                    NSLog(@"Error sending request %@. Got Response %@ Error is: %@", embeddedRequest, embeddedResponse, embeddedError);
                    return;
                }

                // we use NSJSONSerialization to parse the JSON formatted response
                NSError *jsonError = nil;
                NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:embeddedData options:kNilOptions error:&jsonError];
                NSString *embeddedURLToken = responseDictionary[@"url"];

                //--- display results
                NSLog(@"URL token created - please navigate to the following URL to start the embedded signing workflow:\n\n%@\n\n", embeddedURLToken);
            }];
        }];
    }];
}

- (NSString *)jsonStringFromObject:(id)object {
    NSString *string = [[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:object options:0 error:nil] encoding:NSUTF8StringEncoding];
    return string;
}