Objective-C macOS如何使用PayPal getBalance NVP API?

时间:2018-07-26 18:23:00

标签: objective-c macos paypal paypal-nvp

我想在我的macOS应用中获取PayPal帐户余额,但仍然没有找到任何解决方案。

getBalance NVP/SOAP Method

下面是我的代码:

NSString *targetUrl = @"https://api-3t.paypal.com/nvp";
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
//Make an NSDictionary that would be converted to an NSData object sent over as JSON with the request body
[request setHTTPMethod:@"POST"];
[request setURL:[NSURL URLWithString:targetUrl]];
NSString *postLength = [NSString stringWithFormat:@"application/x-www-form-urlencoded"];
[request setValue:postLength forHTTPHeaderField:@"Content-Type"];
NSString *postString = @"USER=*******************&PWD=**************&SIGNATURE= **********************&VERSION=101&METHOD=GetBalance&RETURNALLCURRENCIES=1";
[request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"request:%@",request.HTTPBody);
[[[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:
  ^(NSData * _Nullable data,
    NSURLResponse * _Nullable response,
    NSError * _Nullable error) {
       NSLog(@"getPaypalBalance:response:%@",[data class]);
      NSString* newStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
      NSLog(@"newStr:%@",newStr);

      if (error) {
          NSLog(@"getPaypalBalance:error:%@",error);
          completionBlock(nil,error);
      }else{
      }
  }] resume];

0 个答案:

没有答案