我必须在我的 iOS 应用程序中集成 PayUMoney 支付网关。他们没有适用于 iOS 的 SDK。所以我必须在 webview 中加载一些 web URL 以进行付款。我的参数是
int i = arc4random() % 9999999999;
NSString *strHash = [self createSHA512:[NSString stringWithFormat:@"%d%@",i,[NSDate date]]];// Generatehash512(rnd.ToString() + DateTime.Now);
NSString *txnid1 = [strHash substringToIndex:20];
NSLog(@"tnx1 id %@",txnid1);
NSString *key = @"JBZaLc";
NSString *amount = @"1000";
NSString *productInfo = @"Nice product";
NSString *firstname = @"Mani";
NSString *email = @"mani.ingenius@gmail.com";
NSString *phone = @"1234566";
NSString *surl = @"www.google.com";
NSString *furl = @"www.google.com";
NSString *serviceprovider = @"payu_paisa";
NSString *action = @"https://test.payu.in/_payment";
NSString *hashValue = [NSString stringWithFormat:@"%@|%@|%@|%@|%@|%@|udf1|udf2|udf3|udf4|udf5||||||salt",key,txnid1,amount,productInfo,firstname,email];
NSString *hash = [self createSHA512:hashValue];
NSDictionary *parameters = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:txnid1,key,amount,productInfo,firstname,email,phone,surl,furl,hash,serviceprovider,action, nil] forKeys:[NSArray arrayWithObjects:@"txnid",@"key",@"amount",@"productinfo",@"firstname",@"email",@"phone",@"surl",@"furl",@"hash",@"service_provider",@"action", nil]];
我必须对我的测试 URL ( ) 使用 POST 方法https://test.payu.in/_payment
并且需要传递参数。我在字典(“参数”)中有所有带有键和值的参数。所以我尝试了以下代码
NSData *dataValue = [self getPropertiesAsData:parameters];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://test.payu.in/_payment"]];
// Create a mutable copy of the immutable request and add more headers
NSMutableURLRequest *mutableRequest = [request mutableCopy];
[mutableRequest setHTTPMethod: @"POST"];
[mutableRequest setHTTPBody: dataValue];
request = [mutableRequest copy];
[_webviewSample loadRequest:request];
-(NSData *)getPropertiesAsData :(NSDictionary *)dict{
NSMutableData *body = [NSMutableData postData];
[dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
[body addValue:[obj stringByReplacingOccurrencesOfString:@" " withString:@"%20"] forKey:key];
}];
return body;
}
-(NSString *)createSHA512:(NSString *)string
{
const char *cstr = [string cStringUsingEncoding:NSUTF8StringEncoding];
NSData *data = [NSData dataWithBytes:cstr length:string.length];
uint8_t digest[CC_SHA512_DIGEST_LENGTH];
CC_SHA512(data.bytes, data.length, digest);
NSMutableString* output = [NSMutableString stringWithCapacity:CC_SHA512_DIGEST_LENGTH * 2];
for(int i = 0; i < CC_SHA512_DIGEST_LENGTH; i++)
[output appendFormat:@"%02x", digest[i]];
return output;
}
但是当我运行它时,它会显示“缺少强制参数 tnxid”。但是我已经传递了您可以在参数字典中看到的 tnxid。如果我正确传递了所有内容,那么结果将是用户可以选择银行详细信息等的网页,我必须将其加载到我的网络视图中。
请帮助我找出我做错了什么或应该做些什么来获得正确的结果。