无故事王国
2023-10-09 0408b5d7b07077dc9f451a03a1a859038e4e5bf5
WanPai/YYPaymentManager/YYPaymentManager.swift
@@ -32,6 +32,8 @@
    /// 微信AppID
    private var weChat_appID: String?
   private var weChat_Mini:String?
    private var didReceivePaymentInfos: ((_ result: YYPaymentResult) -> Void)?
}
@@ -49,9 +51,10 @@
    /// 配置微信AppID
    ///
    /// - Parameter appID: 微信AppID
    func configuredWeChat(appID: String,universalLink:String) {
   func configuredWeChat(appID: String,universalLink:String,weChat_Mini:String? = nil) {
        weChat_appID = appID
      self.weChat_Mini = weChat_Mini
        WXApi.registerApp(appID, universalLink: universalLink)
    }
}
@@ -80,25 +83,25 @@
        }
    }
//    /// 拉起小程序支付
//    func sendWXPaymentRequest(_ request: YYWeChatMiniProgramPayRequest,didReceive result: @escaping (YYPaymentResult) -> Void)  {
//
//        guard WXApi.isWXAppInstalled() else {
//            self.delegate?.paymentManager(self, didReceivePayment: .failure(NSError(domain: "com.paymentManager.error", code: -9999, userInfo: [NSLocalizedDescriptionKey: "未安装微信"])))
//            result(.failure(NSError(domain: "com.paymentManager.error", code: -9999, userInfo: [NSLocalizedDescriptionKey: "未安装微信"])))
//            return
//        }
//        let launchMiniProgramReq = WXLaunchMiniProgramReq.object()
//        // /拉起的小程序的username-原始ID
//        launchMiniProgramReq.userName = "gh_33e52f44fac0"
//        // 拉起小程序页面的可带参路径,不填默认拉起小程序首页
//        launchMiniProgramReq.path = "/pages/appPay/appPay?orderId=\(request.orderId ?? 0)&orderType=\(request.orderType ?? 0)&type=\(request.type)&uid=\(request.uid)&userType=\(request.userType)&content=\(request.content ?? "")"
//        launchMiniProgramReq.miniProgramType = .release
////        launchMiniProgramReq.extMsg = request.toJSONString()
//        WXApi.send(launchMiniProgramReq) { (success) in
//
//        }
//    }
    /// 拉起小程序支付
    func sendWXPaymentRequest(_ request: YYWeChatMiniProgramPayRequest,didReceive result: @escaping (YYPaymentResult) -> Void)  {
        guard WXApi.isWXAppInstalled() else {
            self.delegate?.paymentManager(self, didReceivePayment: .failure(NSError(domain: "com.paymentManager.error", code: -9999, userInfo: [NSLocalizedDescriptionKey: "未安装微信"])))
            result(.failure(NSError(domain: "com.paymentManager.error", code: -9999, userInfo: [NSLocalizedDescriptionKey: "未安装微信"])))
            return
        }
        let launchMiniProgramReq = WXLaunchMiniProgramReq.object()
        // /拉起的小程序的username-原始ID
      launchMiniProgramReq.userName = weChat_Mini ?? ""
        // 拉起小程序页面的可带参路径,不填默认拉起小程序首页
        launchMiniProgramReq.path = "/pages/appPay/appPay?orderId=\(request.orderId ?? 0)&orderType=\(request.orderType ?? 0)&type=\(request.type)&uid=\(request.uid)&userType=\(request.userType)&content=\(request.content ?? "")"
        launchMiniProgramReq.miniProgramType = .release
//        launchMiniProgramReq.extMsg = request.toJSONString()
        WXApi.send(launchMiniProgramReq) { (success) in
        }
    }
    /// 发送微信支付请求
    ///
@@ -158,6 +161,11 @@
        return handle(open: url)
    }
   @discardableResult
   func handleApplication(_ userActivity: NSUserActivity)->Bool{
      return WXApi.handleOpenUniversalLink(userActivity, delegate: self)
   }
    private func handle(open url: URL) -> Bool {
        if url.host == "safepay" {
@@ -238,5 +246,10 @@
            }
        }
    }
   func onReq(_ req: BaseReq) {
   }
}