lihaoxiang 2017-11-13
1,官方帮助文档:https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=11_1
2,下载SDK
3,修改IOS配置:在Build Phases选项卡的Link Binary With Libraries中,增加以下依赖
libz.tbd libsqlite3.0.tbd SystemConfiguration.framework CoreTelephony.framework QuartzCore.framework libWeChatSDK.a
4,注册APP:修改AppDelegate文件
class AppDelegate: UIResponder, UIApplicationDelegate, WXApiDelegate { ...... func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. self.initWeixinPay() return true } func onResp(_ resp: BaseResp!) { var strMsg = "\(resp.errCode)" Logger.debug(strMsg) if resp.isKind(of: PayResp.self) { switch resp.errCode { case 0 : NotificationCenter.default.post(name: PayHelper.Notification_WX_Result, object: nil) case -2: strMsg = "您已取消支付,请尽快完成支付" default: strMsg = "支付失败:\(resp.errStr)" Logger.debug("retcode = \(resp.errCode), retstr = \(resp.errStr)") } } if resp.errCode != 0{ let alert = UIAlertView(title: nil, message: strMsg, delegate: nil, cancelButtonTitle: "好的") alert.show() } } func initWeixinPay(){ WXApi.registerApp(GlobalConstant.WX_APP_ID, withDescription: "APP描述") }
5,注册Schema:图片来源微信官网
支付宝IOS集成