我在iOS应用中使用非无缝交易类型。我在获取RSA密钥后在UIWebView中加载https://secure.ccavenue.com/transaction/initTrans URL。有时它会被加载,有时它是空白的UIWebView,在这种情况下,虽然是UIWebView的委托方法,
func ApiCallForRSAKey(){
let stringRsaKeyData = "access_code=\(stringAccessCodePayment)&order_id=\(stringGloabalCart_ID)"
stringResultAddress = "\(dictionaryGloabalAddress["address_title"]!)"+","+"\(dictionaryGloabalAddress["address_1"]!)"+","+"\(dictionaryGloabalAddress["address_2"]!)" as NSString
let requestData = NSData(bytes: stringRsaKeyData.cString(using: .utf8), length: stringRsaKeyData.characters.count) as NSData
let rsaRequest = NSMutableURLRequest(url: NSURL(string: urlGetRSAURL) as! URL) as NSMutableURLRequest
rsaRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "content-type")
rsaRequest.httpMethod = "POST"
rsaRequest.addValue("\(accessKey!)", forHTTPHeaderField: "access_key")
rsaRequest.addValue("\(userDictionary.value(forKey: "user_key")!)", forHTTPHeaderField: "user_key")
rsaRequest.httpBody = requestData as Data
let session = URLSession.shared
let task = session.dataTask(with: rsaRequest as URLRequest, completionHandler: {data, response, error -> Void in
do{
let dictionaryResultRSAKey = try JSONSerialization.jsonObject(with: data! as Data, options: .mutableContainers) as! NSDictionary
if dictionaryResultRSAKey.value(forKey: "response_code")! is NSNull {
self.viewForIndicator.isHidden = true
self.viewRetryView.isHidden = false
}else{
if(dictionaryResultRSAKey.value(forKey: "response_code")! as! NSInteger == 1111){
self.viewRetryView.isHidden = true
let dictionary = dictionaryResultRSAKey["data"] as! NSDictionary
var stringRSAKey = "\(dictionary["rsaKey"]!)" as NSString
if(stringRSAKey == ""){
Toast(text: NSLocalizedString("stringSomethingWentWrong", comment: ""), duration: 2).show()
}else{
stringRSAKey = stringRSAKey.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) as NSString
stringRSAKey = "-----BEGIN PUBLIC KEY-----\n\(stringRSAKey)\n-----END PUBLIC KEY-----" as NSString
let stringRequestParam = "amount=\(1)¤cy=\(stringCurrencyValue)"
// let stringRequestParam = "amount=\(stringAmount_Pay)¤cy=\(stringCurrencyValue)"
let ccTool = CCTool()
var stringEncryptValue :NSString = ccTool.encryptRSA(stringRequestParam, key: (stringRSAKey as NSString) as String!) as NSString
let regExpStr : String = "!*'();:@&=+$,/?%#[]"
stringEncryptValue = CFURLCreateStringByAddingPercentEscapes(nil, stringEncryptValue as CFString, nil, (regExpStr as CFString), CFStringBuiltInEncodings.UTF8.rawValue) as String as String as NSString
let stringEncryptedValue = "access_code="+"\(stringAccessCodePayment)"+"&merchant_id="+"\(stringMerchantID)"+"&order_id="+"\(stringGloabalCart_ID)"+"&redirect_url="+"\(urlRedirectURL)"+"&cancel_url="+"\(urlCancelTransactionURL)"+"&enc_val="+"\(stringEncryptValue)"+"&billing_name="+"\(stringPersonName_Order)"+"&billing_address="+"\(self.stringResultAddress)"+"&billing_tel="+"\(stringContactNo_shipping)"+"&billing_city="+"\(dictionaryGloabalAddress["city"]!)"+"&billing_state="+"\(dictionaryGloabalAddress["state"]!)"+"&billing_zip="+"\(dictionaryGloabalAddress["zipcode"]!)"+"&billing_country="+"\(dictionaryGloabalAddress["country"]!)"+"&billing_email="+"\(userDictionary["email"]!)"
print(stringEncryptedValue)
let myRequestData = NSData.init(bytes: stringEncryptedValue.cString(using: .utf8), length: stringEncryptedValue.characters.count) as NSData
let request = NSMutableURLRequest(url: NSURL(string: urlTrasnsactionURL) as! URL) as NSMutableURLRequest
request.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "content-type")
request.setValue(urlTrasnsactionURL, forHTTPHeaderField: "Referer")
request.httpMethod = "POST"
request.httpBody = myRequestData as Data
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(2), execute: {
DispatchQueue.main.async(execute: {
self.webviewForPayment.loadRequest((request as NSMutableURLRequest) as URLRequest)
})
})
}
}else{
}
}
}catch{
}
})
task.resume()
}
正在被召唤。它不会抛出任何错误或其他东西。
以下是相同的代码。
{{1}}