CCAvenue:"错误!!在解密应用程序请求中"



我正在尝试将CCAvenue支付网关集成到我的iOS应用程序中,该应用程序是用swift4开发的。 我正在得到

"错误!!应用程序请求解密问题">

我已经检查了答案:https://stackoverflow.com/a/37327122/3548469 但我的情况没有运气。

这是我从文档中尝试的内容

private func gettingRsaKey(completion: @escaping (_ success: Bool, _ object: AnyObject?) -> ()){
let serialQueue = DispatchQueue(label: "serialQueue", qos: .userInitiated)
serialQueue.sync {
print("access_code=(CC_AVENUE_ACCESSKEY)")
print("order_id=(self.orderId)")
self.rsaKeyDataStr = "access_code=(CC_AVENUE_ACCESSKEY)&order_id=(self.orderId)"
let requestData = self.rsaKeyDataStr.data(using: String.Encoding.utf8)
guard let urlFromString = URL(string: CC_AVENUE_RSAURL) else{
return
}
var urlRequest = URLRequest(url: urlFromString)
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "content-type")
urlRequest.httpMethod = "POST"
urlRequest.httpBody = requestData
let session = URLSession(configuration: URLSessionConfiguration.default)
print("session",session)

session.dataTask(with: urlRequest as URLRequest) {
(data, response, error) -> Void in
if let response = response as? HTTPURLResponse, 200...299 ~= response.statusCode{
guard let data = data else{
print("No value for data")
completion(false, "Not proper data for RSA Key" as AnyObject?)
return
}
print("data :: ",data)
completion(true, data as AnyObject?)
}
else{
completion(false, "Unable to generate RSA Key please check" as AnyObject?)
}
}.resume()
}
}
var request: NSMutableURLRequest?
private func encyptCardDetails(data: Data){
guard let rsaKeytemp = String(bytes: data, encoding: String.Encoding.ascii) else{
print("No value for rsaKeyTemp")
return
}
rsaKey = rsaKeytemp
rsaKey = self.rsaKey.trimmingCharacters(in: CharacterSet.newlines)
rsaKey =  "-----BEGIN PUBLIC KEY-----n(self.rsaKey)n-----END PUBLIC KEY-----n"
print("rsaKey :: ",rsaKey)
let myRequestString = "amount=(amount)&currency=(getCurrency())"
let ccTool = CCTool()
var encVal = ccTool.encryptRSA(myRequestString, key: rsaKey)
encVal = CFURLCreateStringByAddingPercentEscapes(
nil,
encVal! as CFString,
nil,
"!*'();:@&=+$,/?%#[]" as CFString,
CFStringBuiltInEncodings.UTF8.rawValue) as String?
let urlAsString = "https://secure.ccavenue.com/transaction/initTrans"
let encryptedStr = String(format:"merchant_id=%@&order_id=%@&redirect_url=%@&cancel_url=%@&enc_val=%@&access_code=%@", CC_AVENUE_MERCHANTID, self.orderId, CC_AVENUE_REDIRECTURL, CC_AVENUE_REDIRECTURL, encVal!,CC_AVENUE_ACCESSKEY)
print("access_code=(CC_AVENUE_ACCESSKEY)")
print("order_id=(self.orderId)")
let myRequestData = encryptedStr.data(using: String.Encoding.utf8)
request  = NSMutableURLRequest(url: URL(string: urlAsString)! as URL, cachePolicy: NSURLRequest.CachePolicy.reloadIgnoringCacheData, timeoutInterval: 30)
request?.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "content-type")
request?.setValue(urlAsString, forHTTPHeaderField: "Referer")
request?.httpMethod = "POST"
request?.httpBody = myRequestData
print("nnnwebview :: ",request?.url as Any)
print("nnnwebview :: ",request?.description as Any)
print("nnnwebview :: ",request?.httpBody?.description as Any)
print("nnnwebview :: ",request?.allHTTPHeaderFields! as Any)
let session = URLSession(configuration: URLSessionConfiguration.default)
print("session",session)
session.dataTask(with: request! as URLRequest) {
(data, response, error) -> Void in
if let response = response as? HTTPURLResponse, 200...299 ~= response.statusCode{
guard let data = data else{
print("No value for data")
return
}
DispatchQueue.main.async {
self.viewWeb.loadRequest(self.request! as URLRequest)
}
print("data :: ",data)
}else{
print("into else")
showAlertWithTitleWithMessage(message: "Unable to load webpage currently, Please try again later.")
}
}.resume()
}

我能够生成无法进一步的 RSA 密钥。

注意*

我有真实账户,我正在使用访问代码商家密钥作为账户 AccessCode 和 orderId 与用于生成 RSA 密钥的 AccessCode 和 orderId 相同。

嘿,我遇到了同样的问题。这是因为新的CCAvenue SDK。CCAvenue 加载页面请求的流程分为三个步骤。

1) 我们从服务器获取 RSA 密钥。

2) 我们使用此 RSA 密钥加密订单详细信息并创建 Web 请求。

3) 在 Web 视图中打开请求。

当步骤 1 和步骤 3 之间没有剩余延迟时,就会出现问题。为了克服此问题,新的SDK引入了创建延迟的新步骤。

1) 我们从服务器获取 RSA 密钥。

2) 我们使用此 RSA 密钥加密订单详细信息并创建 Web 请求。

3) CCAvenue在这里引入了一个新的URLRequest,只是为了延迟步骤1和4

4) 在 Web 视图中打开请求。

这在大多数情况下都有效,但是当步骤 3 在毫秒内完成时它会失败,或者换句话说,步骤 1 和步骤 4 中没有延迟或几乎没有延迟。

因此,此处的解决方法是在步骤 1 和步骤 4 中创建手动延迟。

因此,将您的函数更改为以下内容:

private func encyptCardDetails(data: Data){
guard let rsaKeytemp = String(bytes: data, encoding: String.Encoding.ascii) else{
print("No value for rsaKeyTemp")
return
}
rsaKey = rsaKeytemp
rsaKey = self.rsaKey.trimmingCharacters(in: CharacterSet.newlines)
rsaKey =  "-----BEGIN PUBLIC KEY-----n(self.rsaKey)n-----END PUBLIC KEY-----n"
print("rsaKey :: ",rsaKey)
let myRequestString = "amount=(amount)&currency=(getCurrency())"
let ccTool = CCTool()
var encVal = ccTool.encryptRSA(myRequestString, key: rsaKey)
encVal = CFURLCreateStringByAddingPercentEscapes(
nil,
encVal! as CFString,
nil,
"!*'();:@&=+$,/?%#[]" as CFString,
CFStringBuiltInEncodings.UTF8.rawValue) as String?
let urlAsString = "https://secure.ccavenue.com/transaction/initTrans"
let encryptedStr = String(format:"merchant_id=%@&order_id=%@&redirect_url=%@&cancel_url=%@&enc_val=%@&access_code=%@", CC_AVENUE_MERCHANTID, self.orderId, CC_AVENUE_REDIRECTURL, CC_AVENUE_REDIRECTURL, encVal!,CC_AVENUE_ACCESSKEY)
print("access_code=(CC_AVENUE_ACCESSKEY)")
print("order_id=(self.orderId)")
let myRequestData = encryptedStr.data(using: String.Encoding.utf8)
request  = NSMutableURLRequest(url: URL(string: urlAsString)! as URL, cachePolicy: NSURLRequest.CachePolicy.reloadIgnoringCacheData, timeoutInterval: 30)
request?.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "content-type")
request?.setValue(urlAsString, forHTTPHeaderField: "Referer")
request?.httpMethod = "POST"
request?.httpBody = myRequestData
print("nnnwebview :: ",request?.url as Any)
print("nnnwebview :: ",request?.description as Any)
print("nnnwebview :: ",request?.httpBody?.description as Any)
print("nnnwebview :: ",request?.allHTTPHeaderFields! as Any)
let session = URLSession(configuration: URLSessionConfiguration.default)
print("session",session)
session.dataTask(with: request! as URLRequest) {
(data, response, error) -> Void in
if let response = response as? HTTPURLResponse, 200...299 ~= response.statusCode{
guard let data = data else{
print("No value for data")
return
}
// Create the delay here
DispatchQueue.main.asyncAfter(deadline: .now()+1.0, execute: {
self.viewWeb.loadRequest(self.request! as URLRequest)
}
print("data :: ",data)
}else{
print("into else")
showAlertWithTitleWithMessage(message: "Unable to load webpage currently, Please try again later.")
}
}.resume()
}

相关内容

最新更新