1.首先下载SDK;导入工程;xcode
2.在xcode中打开项目设置URL Schemes:(为本身)APPId;微信
3.导入头文件,在AppDelegate中调用[WXApi registerApp:@"APPId" withDescription:@"weiXinPayDemo"];注册APPID;post
4.调起支付:微信支付
///1.调用微信支付code
let req = PayReq()ip
req.partnerId = model?.partneridit
req.prepayId = model?.prepayidio
req.nonceStr = model?.noncestrclass
req.timeStamp = UInt32((model?.timestamp!)!)object
req.package = model?.package
req.sign = model?.sign
WXApi.send(req)
5.支付结果回调
func onResp(_ resp: BaseResp!){
var strTitle = "支付结果"
var strMsg = "what:\(resp.errCode)"
if "\(resp.classForCoder)" == "PayResp"{
print("retcode = \(resp.errCode), retstr = \(resp.errStr)")
switch resp.errCode
{
case 0 :NotificationCenter.default.post(name: NSNotification.Name(rawValue: "WXPaySuccessNotification"), object: nil)
default:
strMsg = "支付失败,请您从新支付!"
}
}
}