0

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

这就是我正在做的

  1. 获取账户信息
  2. 从模板创建信封为“已创建(草稿)”状态
  3. 添加收件人
  4. 添加签名选项卡
  5. 将信封状态从“已创建”更新为“已发送”
  6. 设置收件人的签名图像。

一切似乎都运行良好,没有任何错误。但我没有看到图像。如果我做错了什么或者您有任何将签名图像发送到信封的示例,请告诉我。

4

1 回答 1

0

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

签名视图可以显示在 iOS 应用程序的 web 视图中。

//
//  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;
}
于 2013-07-23T16:34:25.840 回答