gpt4 book ai didi

ios - CCAvenue: "Error!!! in decrypting application request"

转载 作者:搜寻专家 更新时间:2023-10-31 08:21:56 28 4
gpt4 key购买 nike

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

"Error!!! Problem in decrypting application request"

我已检查给出的答案: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("\n\n\nwebview :: ",request?.url as Any)
print("\n\n\nwebview :: ",request?.description as Any)
print("\n\n\nwebview :: ",request?.httpBody?.description as Any)
print("\n\n\nwebview :: ",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 key ,但无法继续。

注意*

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

最佳答案

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

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

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

3) 在 WebView 中打开请求。

当第 1 步和第 3 步之间没有延迟时,就会出现此问题。为解决此问题,新 SDK 引入了一个创建延迟的新步骤。

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

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

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

4) 在 WebView 中打开请求。

这在大多数情况下都有效,但当步骤 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("\n\n\nwebview :: ",request?.url as Any)
print("\n\n\nwebview :: ",request?.description as Any)
print("\n\n\nwebview :: ",request?.httpBody?.description as Any)
print("\n\n\nwebview :: ",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()
}

关于ios - CCAvenue: "Error!!! in decrypting application request",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49463678/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com