Ios PayUMoney支付网关问题

Ios PayUMoney支付网关问题,ios,iphone,payu,Ios,Iphone,Payu,我必须在我的iOS应用程序中集成PayUMoney支付网关。他们没有iOS的SDK。因此,我必须在webview中加载一些web URL以进行支付。我的参数是 int i = arc4random() % 9999999999; NSString *strHash = [self createSHA512:[NSString stringWithFormat:@"%d%@",i,[NSDate date]]];// Generatehash512(rnd.ToString() + DateTim

我必须在我的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;
}
NSData*dataValue=[self-getpropertiesadata:parameters];
NSURLRequest*request=[NSURLRequest requestWithURL:[NSURL URLWithString:@]https://test.payu.in/_payment"]];
//创建不可变请求的可变副本并添加更多标头
NSMutableURLRequest*mutableRequest=[请求mutableCopy];
[mutableRequest setHTTPMethod:@“POST”];
[MutableRequestSetHttpBody:dataValue];
请求=[mutableRequest copy];
[\u webviewSample loadRequest:request];
-(NSData*)获取属性数据:(NSDictionary*)dict{
NSMutableData*body=[NSMutableData postData];
[dict enumerateKeysAndObjectsUsingBlock:^(id键,id对象,布尔*停止){
[body addValue:[obj StringByReplacingOfString:@“with String:@”%20“]forKey:key];
}];
返回体;
}
-(NSString*)createSHA512:(NSString*)字符串
{
const char*cstr=[string cStringUsingEncoding:NSUTF8StringEncoding];
NSData*data=[NSData dataWithBytes:cstr-length:string.length];
uint8_t摘要[抄送摘要长度];
CC_SHA512(data.bytes、data.length、digest);
NSMutableString*输出=[NSMutableString stringWithCapacity:CC_SHA512_DIGEST_LENGTH*2];
对于(int i=0;i
但当我运行它时,它会说“缺少必需的参数tnxid”。但是我已经传递了tnxid,您可以在参数字典中看到它。如果我通过一切正确,那么结果将是网页,用户可以选择银行详情等,我必须加载到我的网页视图


请帮助我找出我做错了什么,或者我应该做什么才能得到正确的结果。

我成功地找到了答案。我的工作代码如下所示

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 *hashValue = [NSString stringWithFormat:@"%@|%@|%@|%@|%@|%@|||||||||||GQs7yium",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
                                                                    , nil] forKeys:[NSArray arrayWithObjects:@"txnid",@"key",@"amount",@"productinfo",@"firstname",@"email",@"phone",@"surl",@"furl",@"hash",@"service_provider", nil]];
   __block NSString *post = @"";
    [parameters enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
        if ([post isEqualToString:@""]) {
            post = [NSString stringWithFormat:@"%@=%@",key,obj];
        }else{
            post = [NSString stringWithFormat:@"%@&%@=%@",post,key,obj];
        }

    }];

    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

    NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long)[postData length]];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://test.payu.in/_payment"]]];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];
    [request setHTTPBody:postData];

    [_webviewSample loadRequest:request];
然后是要使用的函数

-(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, (CC_LONG)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;
}
-(NSString*)createSHA512:(NSString*)字符串
{
const char*cstr=[string cStringUsingEncoding:NSUTF8StringEncoding];
NSData*data=[NSData dataWithBytes:cstr-length:string.length];
uint8_t摘要[抄送摘要长度];
CC_SHA512(data.bytes,(CC_LONG)data.length,摘要);
NSMutableString*输出=[NSMutableString stringWithCapacity:CC_SHA512_DIGEST_LENGTH*2];
对于(int i=0;i
最后,我解决了关于PayU India的问题(不包括PayU,PayU和Payundia有一点不同)集成(以上代码是为PayU Money help alot编写的) 下载

您只需要删除一个额外的参数,即值为payu paisa的服务提供商。

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 = @"YOURKEY";
    NSString *salt = @"YOURSALTKEY";

    NSString *amount = @"100";
    NSString *productInfo = @"Niceproduct";
    NSString *firstname = @"Deepak";
    NSString *email = @"iphonemaclover@gmail.com";
    NSString *phone = @"9212138007";
    NSString *surl = @"www.google.com";
    NSString *furl = @"www.google.com";


    NSString *hashValue = [NSString stringWithFormat:@"%@|%@|%@|%@|%@|%@|||||||||||%@",key,txnid1,amount,productInfo,firstname,email,salt];
    NSString *hash = [self createSHA512:hashValue];
    NSDictionary *parameters = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:txnid1,key,amount,productInfo,firstname,email,phone,surl,furl,hash
                                                                    , nil] forKeys:[NSArray arrayWithObjects:@"txnid",@"key",@"amount",@"productinfo",@"firstname",@"email",@"phone",@"surl",@"furl",@"hash", nil]];
   __block NSString *post = @"";
    [parameters enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
        if ([post isEqualToString:@""]) {
            post = [NSString stringWithFormat:@"%@=%@",key,obj];
        }else{
            post = [NSString stringWithFormat:@"%@&%@=%@",post,key,obj];
        }

    }];

    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];

    NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long)[postData length]];
    NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
    [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://test.payu.in/_payment"]]];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];
    [request setHTTPBody:postData];

    [_webviewSample loadRequest:request];
编辑:如何处理URL付款成功与否

-(void)webViewDidFinishLoad:(UIWebView *)webView{
        if (web_view_PayU.isLoading)
        return;
    NSURL *requestURL = [[web_view_PayU request] URL];

    NSLog(@"requestURL=%@",requestURL);

    NSString *getStringFromUrl=[NSString stringWithFormat:@"%@",requestURL];

    if ([getStringFromUrl isEqualToString:@"https://test.payu.in/yoursucessurladdedhere "]||[getStringFromUrl isEqualToString:@"https://secure.payu.in/yoursucessurladdedhere "])
    {
       //SUCCESS ALERT
       //jump to place order API

    }
   else if ([getStringFromUrl isEqualToString:@"https://test.payu.in/yourfailureurladdedhere "]||[getStringFromUrl isEqualToString:@"https://secure.payu.in/yourfailureurladdedhere"])
    {
        // FAIL ALERT
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Sorry!" message:@"Your Order Not Successfull!" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
        alert.tag=2222;

        [alert show];
    }

}

对于Pay U的Android集成

我向PayUMoney技术团队发送了邮件,并得到了我的答案,为什么我会收到错误“对不起,出现了一些问题。”

得到了技术团队的快速回复:

Recently, we have done some modifications in test environment due to which test key-JBZaLc and salt-GQs7yium will not work anymore.

In order to test the gateway using a test key and salt, kindly follow these steps:
1 - Go on https://test.payumoney.com
2 - Sign up as a merchant - use any of your valid email ids - kindly do not use a random email id.
3 - Complete the "Business Details"  - you may use PAN no. ABCDE1234F and DOB - 01/04/1990
4 - Complete "Bank Account Details" (You may use IFSC- ALLA0212632)
5 - Go to below mentioned location to get the Test Merchant Id :     
 Seller Dashboard -> Settings -> My account -> Profile Settings

Once you provide your test merchant id, we will approve it so that you can find your test key and salt at :
Seller Dashboard -> Settings -> My account -> Merchant Key - Salt
下载

获取swift版本

1) 导入到桥接头中

**导入CommonCrypto/CommonDigest.h**

2) 之后

func-sha512Hex(字符串:字符串)->string{
变量摘要=[UInt8](重复:0,计数:Int(抄送摘要长度))
如果let data=string.data(使用:string.Encoding.utf8){
设值=数据为NSData
CC_SHA512(value.bytes、CC_LONG(data.count)和摘要)
}
var digestHex=“”

对于0中的索引..您好,我在使用merchent键和salt键通过测试url发送数据时出错…很抱歉,出现了一些问题。如何修复它?我首先在SHA256中转换了tnx1,然后根据需要将postData转换为Base64编码…在Android版本中工作正常?有解决方案吗?请检查我的更新答案Hello Mani,我有c见鬼,它又给了我同样的错误..发生了一个错误,很抱歉出现了一些问题…甚至我已经更改了我的商户密钥和盐。你知道如何使用它吗?请帮助。如果可能的话,请给我发送示例代码dsrawat4u@gmail.com?谢谢,现在开始工作了(y)请删除您的测试盐密钥,这样就没有人使用它。您是使用Payumoney的真实凭据进行测试的吗?您在Payumoney中有帐户吗?您好,有什么想法吗?出现错误,抱歉,发生了一些问题。您使用的是payUmonkey盐密钥和商户密钥。您使用的是Payumoney吗?因为我正在使用PayUindia,而不是使用他们提供的密钥。欢迎任何帮助@iphonemaclover@hello,我使用的是相同的代码,在某些情况下可以正常工作。表示如果我使用此键=“gtkfx”和salt="eCwWELxi',它将不起作用。请告诉我这背后的原因。@iphonemaclover、Payundia和payUmoney是不同的?可以在这里找到测试凭据。有人能告诉我如何知道我的支付成功或失败吗?上面的代码对我来说运行良好,并显示支付屏幕,但支付结果如何?请回答请帮助我,因为我非常渴望得到答案。我被困在这一点上。你好,pratik,请检查github repo,它包括处理失败、快速点击付款成功的代码,只需检查webview委托方法中的成功和失败url加载,并根据它添加您的条件…希望它能帮助您非常感谢您的回复iphonemaclover。我已经按照您的示例实现了。但我的主要观点是如何在-(void)webViewDidFinishLoad:(UIWebView*)中知道付款成功与否webView方法?我已经使用校验和提出了请求,并且使用webView进行了所有操作,但这是我坚持的观点。现在检查我的编辑答案,类似地将加载url与url进行比较你得到了一些url
func sha512Hex( string: String) -> String {
    var digest = [UInt8](repeating: 0, count: Int(CC_SHA512_DIGEST_LENGTH))
    if let data = string.data(using: String.Encoding.utf8) {
        let value =  data as NSData
        CC_SHA512(value.bytes, CC_LONG(data.count), &digest)

    }
    var digestHex = ""
    for index in 0..<Int(CC_SHA512_DIGEST_LENGTH) {
        digestHex += String(format: "%02x", digest[index])
    }

    return digestHex
}