fix
杨锴
2025-05-06 fdb1d18a0b4b941b986d55f66c589e29836494eb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//
//  VIPCenterVC.swift
//  DolphinEnglishLearnStudent
//
//  Created by 无故事王国 on 2024/7/1.
//
 
import UIKit
import WebKit
import StoreKit
 
class VIPCenterVC: BaseVC {
 
                private var btn_vip:UIButton!
                private var webView:WKWebView!
                private var inpurchaseManager = InPurchaseManager.instance()
                private var products = Set<SKProduct>()
 
                override func viewDidLoad() {
                                super.viewDidLoad()
 
                                yy_popBlock = {[weak self] () in
                                                guard let weakSelf = self else { return }
                                                var toVC:UIViewController?
                                                for subVC in weakSelf.navigationController?.viewControllers ?? []{
                                                                if subVC.isKind(of: HomeListenVC.self){
                                                                                toVC = subVC;break
                                                                }
                                                }
 
                                                if toVC != nil{
                                                                weakSelf.navigationController?.popToViewController(toVC!, animated: true)
                                                }else{
                                                                weakSelf.navigationController?.popViewController(animated: true)
                                                }
                                }
 
                                Services.vipInfo().subscribe(onNext: {data in
                                                if let model = data.data?.first{
                                                                self.webView.loadHTMLString(model.info.jq_wrapHtml(edge: UIEdgeInsets(top: 0, left: 10, bottom: 3, right: 0)), baseURL: nil)
                                                }
                                }).disposed(by: disposeBag)
 
                                inpurchaseManager.test1()
                                inpurchaseManager.setProductList([ProductMemberID]) {[weak self] m in
                                                self?.products = m
                                }
                }
 
                override func setUI() {
 
                                view.backgroundColor = .white
                                webView = WKWebView(frame: .zero)
                                view.addSubview(webView)
                                webView.snp.makeConstraints { make in
                                                make.left.right.top.equalToSuperview()
                                                make.bottom.equalToSuperview().offset(-150)
                                }
 
 
                                btn_vip = UIButton(type: .custom)
                                btn_vip.setTitle("成为会员", for: .normal)
                                btn_vip.setTitleColor(.white, for: .normal)
                                btn_vip.backgroundColor = UIColor(hexStr: "#41A2EB")
                                btn_vip.titleLabel?.font = .systemFont(ofSize: 16, weight: .medium)
                                btn_vip.addTarget(self, action: #selector(becomeVIPAction), for: .touchUpInside)
                                btn_vip.jq_cornerRadius = 8
                                view.addSubview(btn_vip)
                                btn_vip.snp.makeConstraints { make in
                                                make.width.equalTo(316)
                                                make.height.equalTo(49)
                                                make.bottom.equalTo(-91)
                                                make.centerX.equalToSuperview()
                                }
                }
 
                @objc func becomeVIPAction(){
                                #if DEBUG
                                toPay()
                                #else
                                ParentVerifiyView.show {[unowned self] in
                                                self.toPay()
                                }
                                #endif
                }
 
                private func toPay(){
                                guard let userId = UserViewModel.getUserInfo()?.user?.id.string else {alert(msg: "请先登录");return}
                                guard let product = products.first else {alert(msg: "获取内购失败");return}
 
                                Services.orderStudent(count: 12, price: product.price.doubleValue).subscribe(onNext: {[unowned self] data in
                                                if let m = data.data{
                                                                showHUD("正在购买")
                                                                InPurchaseManager.purchaseProduct(ID: ProductMemberID, applicationUsername: userId) {[unowned self] model in
                                                                                let transactionIdentifier = model.receipt?.in_app.first?.original_transaction_id ?? ""
 
                                                                                hiddenHUD()
                                                                                Services.pay(orderId: m.orderId, transactionIdentifier: transactionIdentifier).subscribe(onNext: {[unowned self] data in
                                                                                                var count = 0
                                                                                                showHUD("正在查询支付结果")
                                                                                                let t = Timer(timeInterval: 2.0, repeats: true) {[unowned self] timer in
                                                                                                                Services.queryOrderState(orderId: m.orderId).subscribe(onNext: {[unowned self]status in
                                                                                                                                if status.data == true{
                                                                                                                                                alertSuccess(msg: "购买成功")
                                                                                                                                                DispatchQueue.main.asyncAfter(deadline: .now()+1) {[unowned self] in
                                                                                                                                                                navigationController?.popViewController()
                                                                                                                                                                NotificationCenter.default.post(name: MeUserInfoUpdate_Noti, object: nil)
                                                                                                                                                }
                                                                                                                                                timer.invalidate()
                                                                                                                                                return
                                                                                                                                }
                                                                                                                                count += 1
                                                                                                                                if count >= 15{
                                                                                                                                                hiddenHUD()
                                                                                                                                                print("循环结束")
                                                                                                                                                showHUD("查询结果失败,请联系客服")
                                                                                                                                                timer.invalidate()
                                                                                                                                }
                                                                                                                },onError: {error in
                                                                                                                                timer.invalidate()
                                                                                                                }).disposed(by: disposeBag)
                                                                                                }
                                                                                                t.fire()
                                                                                                RunLoop.current.add(t, forMode: .common)
                                                                                }).disposed(by: disposeBag)
 
                                                                } errorClouse: { error in
                                                                                hiddenHUD()
                                                                                alert(msg: error.localizedDescription)
                                                                }
                                                }
                                }).disposed(by: disposeBag)
                }
}