pod 'AlipaySDK-iOS'
桥接文件
#import <AlipaySDK/AlipaySDK.h>
image
- appdelegate里加
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
if url.host == "safepay"{
AlipaySDK.defaultService().processOrder(withPaymentResult: url){
value in
let code = value!
let resultStatus = code["resultStatus"] as!String
var content = ""
print(resultStatus)
switch resultStatus {
case "9000":
content = "支付成功"
NotificationCenter.default.post(name: NSNotification.Name(rawValue: aliPaySucceess), object: content)
case "8000":
content = "订单正在处理中"
NotificationCenter.default.post(name: NSNotification.Name(rawValue: aliPayUnknowStatus), object: content)
case "4000":
content = "支付失败"
NotificationCenter.default.post(name: NSNotification.Name(rawValue: aliPayDefeat), object: content)
case "5000":
content = "重复请求"
NotificationCenter.default.post(name: NSNotification.Name(rawValue: aliPayDefeat), object: content)
case "6001":
content = "中途取消"
NotificationCenter.default.post(name: NSNotification.Name(rawValue: aliPayDefeat), object: content)
case "6002":
content = "网络连接出错"
NotificationCenter.default.post(name: NSNotification.Name(rawValue: aliPayDefault), object: content)
case "6004":
content = "支付结果未知"
NotificationCenter.default.post(name: NSNotification.Name(rawValue: aliPayUnknowStatus), object: content)
default:
content = "支付失败"
NotificationCenter.default.post(name: NSNotification.Name(rawValue: aliPayDefeat), object: content)
break
}
}
}
return true
}
- 调用 orderStr为后台返回的字符串
AlipaySDK.defaultService()?.payOrder(orderStr, fromScheme: ZhifuBaoScheme, callback: { (result) in print(result) })