修复bug
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// UserPayViewController.swift
|
||||
// yinmeng-ios
|
||||
//
|
||||
// Created by duoban on 2024/2/29.
|
||||
// Created by yinmeng on 2024/2/29.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
@@ -18,27 +18,10 @@ class UserPayViewController: BaseViewController, HiddenNavigationBarProtocol{
|
||||
requestData()
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(receiveInitiatePaymentNot(not:)), name: NSNotification.Name(rawValue: "kInitiatePayment"), object: nil)
|
||||
}
|
||||
@objc func receiveInitiatePaymentNot(not:Notification) async{
|
||||
if let _data = not.userInfo,let transactionId = _data["transactionId"] as? String{
|
||||
if #available(iOS 15.0, *) {
|
||||
try? await UserPayViewManager.shared._verifyBusinessAccomplish(transaction: transactionId)
|
||||
}
|
||||
self.orderId = ""
|
||||
RequestGet(path: "purse/query", parma: ["channelType":"8"]) { data in
|
||||
|
||||
if let model = Deserialized<UserPayViewModel>.toModel(with: data) {
|
||||
self.pricView.text = model.diamonds
|
||||
}
|
||||
|
||||
} fail: { code, data in
|
||||
print(code)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if let _data = not.userInfo,let recordId = _data["recordId"] as? String,let appAccountToken = _data["appAccountToken"] as? String{
|
||||
try? await self.initiatePaymentAction(recordId: recordId, appAccountToken: appAccountToken)
|
||||
}
|
||||
@objc func receiveInitiatePaymentNot(not:Notification) {
|
||||
//
|
||||
//
|
||||
//
|
||||
}
|
||||
func requestData(){
|
||||
RequestGet(path: "chargeprod/list", parma: ["channelType":"8"]) { data in
|
||||
@@ -186,45 +169,66 @@ class UserPayViewController: BaseViewController, HiddenNavigationBarProtocol{
|
||||
guard let chargeProdId = self.chooseModel?.chargeProdId else{
|
||||
return
|
||||
}
|
||||
MBProgressHUD.showAdded(to: self.view, animated: true)
|
||||
MBProgressHUD.showAdded(to: UIApplication.shared.keyWindow!, animated: true)
|
||||
let uid = "\(AuthManager.userUid)"
|
||||
let ticket = AuthManager.ticket
|
||||
let deviceInfo = UIDevice.current.identifierForVendor?.uuidString ?? ""
|
||||
let clientIp = "0.0.0.0"
|
||||
RequestPost(path: "storeKitV2/placeOrder", parma: ["chargeProdId":chargeProdId,"uid":uid,"ticket":ticket,"deviceInfo":deviceInfo]) { data in
|
||||
|
||||
if let _data = data as? [String : Any]{
|
||||
|
||||
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "kInitiatePayment"), object: nil, userInfo: _data)
|
||||
|
||||
}
|
||||
|
||||
|
||||
if let _data = data as? [String:Any],let recordId = _data["recordId"] as? String,let appAccountToken = _data["appAccountToken"] as? String{
|
||||
self.initiatePaymentAction(recordId: recordId, appAccountToken: appAccountToken)
|
||||
}else{
|
||||
HUDTool.show(with: "购买失败")
|
||||
MBProgressHUD.hide(for: UIApplication.shared.keyWindow!, animated: true)
|
||||
}
|
||||
|
||||
|
||||
} fail: { code, data in
|
||||
MBProgressHUD.hide(for: self.view, animated: true)
|
||||
HUDTool.show(with: data)
|
||||
MBProgressHUD.hide(for: UIApplication.shared.keyWindow!, animated: true)
|
||||
}
|
||||
|
||||
}
|
||||
deinit{
|
||||
NotificationCenter.default.removeObserver(self)
|
||||
}
|
||||
func initiatePaymentAction(recordId:String,appAccountToken:String)async throws{
|
||||
func initiatePaymentAction(recordId:String,appAccountToken:String) {
|
||||
self.orderId = recordId
|
||||
if #available(iOS 15.0, *) {
|
||||
try await UserPayViewManager.shared._demandCommodityThing(productId: recordId, uuid: appAccountToken)
|
||||
UserPayViewManager.shared._ConditionBlock = {[weak self] (state , result) in
|
||||
if state == .Pay || state == .Start || state == .VerifiedServer{
|
||||
|
||||
}else if state == .Unowned{
|
||||
HUDTool.show(with: "出现未知错误,请重新尝试")
|
||||
MBProgressHUD.hide(for: UIApplication.shared.keyWindow!, animated: true)
|
||||
}else{
|
||||
HUDTool.show(with: "购买失败")
|
||||
MBProgressHUD.hide(for: UIApplication.shared.keyWindow!, animated: true)
|
||||
}
|
||||
if state == .VerifiedServer{
|
||||
if let transactionId = result?["transactionId"] as? String{
|
||||
self?.paySuccess(transactionId: transactionId)
|
||||
|
||||
|
||||
if let data = result,let transactionId = data["transactionId"]{
|
||||
self?.paySuccess(transactionId:"\(transactionId)")
|
||||
}else{
|
||||
HUDTool.show(with: "购买失败")
|
||||
MBProgressHUD.hide(for: UIApplication.shared.keyWindow!, animated: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
Task {
|
||||
do {
|
||||
try await UserPayViewManager.shared._demandCommodityThing(productId: self.chooseModel?.chargeProdId ?? "", uuid: appAccountToken)
|
||||
|
||||
}catch{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
HUDTool.show(with: "充值失败。当前仅支持运行iOS15及以上系统的手机进行充值,请升级系统版本后重试。")
|
||||
}
|
||||
@@ -232,18 +236,43 @@ class UserPayViewController: BaseViewController, HiddenNavigationBarProtocol{
|
||||
func paySuccess(transactionId:String){
|
||||
let uid = "\(AuthManager.userUid)"
|
||||
let ticket = AuthManager.ticket
|
||||
|
||||
|
||||
RequestPost(path: "storeKitV2/verifyOrder", parma: ["chooseEnv":"true","uid":uid,"ticket":ticket,"transcationId":transactionId]) { data in
|
||||
MBProgressHUD.hide(for: self.view, animated: true)
|
||||
|
||||
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "kInitiatePayment"), object: nil, userInfo: ["transactionId":transactionId])
|
||||
} fail: { code, data in
|
||||
if code == 1444{
|
||||
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "kInitiatePayment"), object: nil, userInfo: ["transactionId":transactionId])
|
||||
}
|
||||
MBProgressHUD.hide(for: self.view, animated: true)
|
||||
}
|
||||
RequestPost(path: "storeKitV2/verifyOrder", parma: ["chargeRecordId":self.orderId,"chooseEnv":"true","uid":uid,"ticket":ticket,"transcationId":transactionId]) { data in
|
||||
MBProgressHUD.hide(for: UIApplication.shared.keyWindow!, animated: true)
|
||||
|
||||
if #available(iOS 15.0, *) {
|
||||
Task {
|
||||
try await UserPayViewManager.shared._verifyBusinessAccomplish(transaction: transactionId)
|
||||
self.orderId = ""
|
||||
RequestGet(path: "purse/query", parma: ["channelType":"8"]) { data in
|
||||
|
||||
if let model = Deserialized<UserPayViewModel>.toModel(with: data) {
|
||||
self.pricView.text = model.diamonds
|
||||
}
|
||||
|
||||
} fail: { code, data in
|
||||
print(code)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} fail: { code, data in
|
||||
if code == 1444{
|
||||
Task {
|
||||
if #available(iOS 15.0, *) {
|
||||
try await UserPayViewManager.shared._verifyBusinessAccomplish(transaction: transactionId)
|
||||
} else {
|
||||
// Fallback on earlier versions
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
HUDTool.show(with: data)
|
||||
MBProgressHUD.hide(for: UIApplication.shared.keyWindow!, animated: true)
|
||||
}
|
||||
}
|
||||
@objc func backBtnAction(){
|
||||
self.navigationController?.popViewController(animated: true)
|
||||
|
Reference in New Issue
Block a user