1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
let partner = ""; let seller = ""; let privateKey = "";
if((partner as NSString).length == 0){ return; } if((seller as NSString).length == 0){ return; } if((privateKey as NSString).length == 0){ return; }
let order = Order(); order.partner = partner; order.seller = seller; order.tradeNO = "order002"; order.productName = "商品标题"; order.productDescription = "商品描述"; order.amount = "0.01"; order.notifyURL = "http://www.xxx.com"; order.service = "mobile.securitypay.pay"; order.paymentType = "1"; order.inputCharset = "utf-8"; order.itBPay = "30m"; order.showUrl = "m.alipay.com";
let appScheme = "alisdkyidaisong";
let orderSpec = order.description;
let signer = CreateRSADataSigner(privateKey); let signedString = signer.signString(orderSpec);
var orderString:String? = nil; if (signedString != nil) { orderString = NSString(format: "%@&sign=\"%@\"&sign_type=\"%@\"", orderSpec, signedString, "RSA") as String; AlipaySDK.defaultService().payOrder(orderString, fromScheme: appScheme, callback: { (resultDic) -> Void in if let Alipayjson = resultDic{ let resultStatus = Alipayjson["resultStatus"] as! String if resultStatus == "9000"{ print("付款成功"); }else if resultStatus == "8000" { print("正在处理中"); self.navigationController?.popViewControllerAnimated(true) }else if resultStatus == "4000" { print("订单支付失败"); self.navigationController?.popViewControllerAnimated(true) }else if resultStatus == "6001" { print("用户中途取消"); self.navigationController?.popViewControllerAnimated(true) }else if resultStatus == "6002" { print("网络连接出错"); self.navigationController?.popViewControllerAnimated(true) } } }) }
|