Swift微信支付和支付宝支付
pod 'MZPay', '~> 0.0.2'
前往微信开放平台和支付宝开放平台申请支付权限
- InfoPlist添加微信白名单
LSApplicationQueriesSchemes
weixin
weixinULAPI
- 添加URL Schemes
MZPay.registerWechat(appid: "", universalLink: "")
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
let result = MZPay.handleOpenURL(url)
if result {
return result
}
return false
}
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
let result = MZPay.handleOpenUniversalLink(userActivity)
if result {
return result
}
return false
}
- 微信支付
MZPay.payWechat(mchid: "", prepayId: "", appid: "", appKey: "") {
NSLog("支付成功")
} failure: { reason in
NSLog("支付失败")
}
- 支付宝支付
MZPay.payAli(payURL: "", appScheme: "") {
NSLog("支付成功")
} failure: { reason in
NSLog("支付失败")
}