微信支付那點事

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 = "支付失敗,請您從新支付!"

            }

        }

    }

相關文章
相關標籤/搜索