|
@@ -13,12 +13,293 @@ class KMPurchaseEmbeddedWindowController: NSWindowController {
|
|
|
super.windowDidLoad()
|
|
|
|
|
|
// Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
|
|
|
+
|
|
|
+ #if DEBUG
|
|
|
+ let btn = NSButton()
|
|
|
+ let wh: CGFloat = 100
|
|
|
+ let x = (NSWidth(self.window?.frame ?? .zero) - wh) * 0.5
|
|
|
+ let y = (NSHeight(self.window?.frame ?? .zero) - wh) * 0.5
|
|
|
+ btn.frame = NSMakeRect(x, y, wh, wh)
|
|
|
+
|
|
|
+ btn.target = self
|
|
|
+ btn.action = #selector(btnAction)
|
|
|
+ self.window?.contentView?.addSubview(btn)
|
|
|
+ #endif
|
|
|
}
|
|
|
|
|
|
-
|
|
|
override func showWindow(_ sender: Any?) {
|
|
|
NSApp.runModal(for: self.window!)
|
|
|
}
|
|
|
|
|
|
+ @objc func btnAction() {
|
|
|
+// self.subscriptions()
|
|
|
+ self.retrieval()
|
|
|
+ }
|
|
|
+
|
|
|
+ func getPriceUrl() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ func retrieval() {
|
|
|
+ let urlString = kVerificationServer + "/api/coupons/retrieval"
|
|
|
+
|
|
|
+ let productCode = "com.brother.pdfreaderpro.windows.product_1"
|
|
|
+ let app_code = MainBundle.km_infoDictionary()?["CFBundleIdentifier"] ?? ""
|
|
|
+ let params = [
|
|
|
+ // 优惠卷id
|
|
|
+ "code" : "E85B-9C31-6EAB",
|
|
|
+ "app_code" : app_code,
|
|
|
+ "product_code" : productCode]
|
|
|
+ KMAdvertisementRequestServer.requestServer.request(urlString: urlString, method: "GET", params: params) { [self] task, responseObject, error in
|
|
|
+
|
|
|
+ if (error == nil && responseObject != nil) {
|
|
|
+ let array = responseObject?["data"] as? NSDictionary
|
|
|
+ if array != nil {
|
|
|
+ //解析数据
|
|
|
+ print("开始解析数据")
|
|
|
+ for model in array as! [NSDictionary] {
|
|
|
+ let jsonString: String = (model["detail"] as? String) ?? ""
|
|
|
+ let jsonData: Data = jsonString.data(using: .utf8)!
|
|
|
+ let dict = try?JSONSerialization.jsonObject(with: jsonData)
|
|
|
+// infoDict = dict as! NSDictionary
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ print("解析数据失败array")
|
|
|
+// completion(nil, responseObject, error)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ print("解析数据失败数据不存在")
|
|
|
+// completion(nil, responseObject, error)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func getOrderStatus(trade_no: String) {
|
|
|
+ let urlString = kVerificationServer + "/api/orders/getOrderStatus"
|
|
|
+
|
|
|
+ // 升级产品
|
|
|
+ let paraDict = ["token" : trade_no]
|
|
|
+ var postData = try! JSONSerialization.data(withJSONObject: paraDict)
|
|
|
+ var request = URLRequest(url: URL(string: urlString)!,timeoutInterval: Double.infinity)
|
|
|
+ request.addValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
|
|
|
+ request.addValue("application/json", forHTTPHeaderField: "Content-Type")
|
|
|
+
|
|
|
+ request.httpMethod = "POST"
|
|
|
+ request.httpBody = postData
|
|
|
+
|
|
|
+ let task = URLSession.shared.dataTask(with: request) { data, response, error in
|
|
|
+ guard let data = data else {
|
|
|
+ print(String(describing: error))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let jsonObject = try? JSONSerialization.jsonObject(with: data, options: []) as? NSDictionary ?? [:]
|
|
|
+ if jsonObject != nil {
|
|
|
+ let data1: NSDictionary = jsonObject!["data"] as? NSDictionary ?? [:]
|
|
|
+ let subscriptionInfo = data1.object(forKey: "subscription") as? NSDictionary
|
|
|
+ let paypal_order_info = subscriptionInfo?.object(forKey: "paypal_order") as? NSDictionary
|
|
|
+ if let dataInfo = paypal_order_info, dataInfo.count > 0 {
|
|
|
+ // paypal_order
|
|
|
+ // page_pay_url 链接
|
|
|
+ // https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-3V503434MD108282U
|
|
|
+ // trade_no 订单id 用于校验订单 【22024083006591098】
|
|
|
+ let trade_no = dataInfo.object(forKey: "trade_no")
|
|
|
+ let page_pay_url = dataInfo.object(forKey: "page_pay_url")
|
|
|
+ KMPrint("trade_no:" + "\(trade_no)" + ";" + "page_pay_url:" + "\(page_pay_url)")
|
|
|
+ } else {
|
|
|
+ // 数据错误
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 数据错误
|
|
|
+ }
|
|
|
+ }
|
|
|
+ task.resume()
|
|
|
+ }
|
|
|
+
|
|
|
+ func subscriptions() {
|
|
|
+ let urlString = kVerificationServer + "/api/subscriptions"
|
|
|
+
|
|
|
+ // 升级产品
|
|
|
+ let productCode = "com.brother.pdfreaderpro.windows.product_1"
|
|
|
+ let app_code = MainBundle.km_infoDictionary()?["CFBundleIdentifier"] ?? ""
|
|
|
+ let paraDict = ["data" :
|
|
|
+ ["product_code": productCode,
|
|
|
+ "app_code": app_code,
|
|
|
+ // 购买数量
|
|
|
+ "amount": "1",
|
|
|
+ // 优惠卷id
|
|
|
+ "coupon_code": "",
|
|
|
+ // 支付类型 paypal alipay wxpay paddle
|
|
|
+ "payment": "paypal",
|
|
|
+ // 地区
|
|
|
+ "customer_country": "US",
|
|
|
+ // 邮编码
|
|
|
+ "customer_postcode" : "20001",
|
|
|
+ "unique_sn" : uuid(),
|
|
|
+ // 序列码 标准包 升级 高级包 需要
|
|
|
+ "upgrade_cdkey" : "",
|
|
|
+ "email" : "tangchao@kdanmobile.com",
|
|
|
+ // 用户名
|
|
|
+ "contact_name" : uuid()]]
|
|
|
+ var postData = try! JSONSerialization.data(withJSONObject: paraDict)
|
|
|
+ var request = URLRequest(url: URL(string: urlString)!,timeoutInterval: Double.infinity)
|
|
|
+ request.addValue("Apifox/1.0.0 (https://www.apifox.cn)", forHTTPHeaderField: "User-Agent")
|
|
|
+ request.addValue("application/json", forHTTPHeaderField: "Content-Type")
|
|
|
+
|
|
|
+ request.httpMethod = "POST"
|
|
|
+ request.httpBody = postData
|
|
|
+
|
|
|
+ let task = URLSession.shared.dataTask(with: request) { data, response, error in
|
|
|
+ guard let data = data else {
|
|
|
+ print(String(describing: error))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let jsonObject = try? JSONSerialization.jsonObject(with: data, options: []) as? NSDictionary ?? [:]
|
|
|
+ if jsonObject != nil {
|
|
|
+ let data1: NSDictionary = jsonObject!["data"] as? NSDictionary ?? [:]
|
|
|
+ let subscriptionInfo = data1.object(forKey: "subscription") as? NSDictionary
|
|
|
+ let paypal_order_info = subscriptionInfo?.object(forKey: "paypal_order") as? NSDictionary
|
|
|
+ if let dataInfo = paypal_order_info, dataInfo.count > 0 {
|
|
|
+ // paypal_order
|
|
|
+ // page_pay_url 链接
|
|
|
+ // https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-3V503434MD108282U
|
|
|
+ // trade_no 订单id 用于校验订单 【22024083006591098】
|
|
|
+ let trade_no = dataInfo.object(forKey: "trade_no")
|
|
|
+ let page_pay_url = dataInfo.object(forKey: "page_pay_url")
|
|
|
+ KMPrint("trade_no:" + "\(trade_no)" + ";" + "page_pay_url:" + "\(page_pay_url)")
|
|
|
+
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
|
|
|
+ self.getOrderStatus(trade_no: trade_no as? String ?? "")
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 数据错误
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 数据错误
|
|
|
+ }
|
|
|
+ }
|
|
|
+ task.resume()
|
|
|
+ }
|
|
|
+
|
|
|
+ // MARK: Private
|
|
|
+
|
|
|
+ private func uuid() -> String {
|
|
|
+ return GetHardwareUUID()!
|
|
|
+ }
|
|
|
+
|
|
|
+ private func platform() -> String {
|
|
|
+ var platform = "DMG"
|
|
|
+#if VERSION_DMG
|
|
|
+ platform = "DMG"
|
|
|
+#else
|
|
|
+ platform = "AiStore"
|
|
|
+#endif
|
|
|
+ return platform
|
|
|
+ }
|
|
|
+
|
|
|
+ private func app_name() -> String {
|
|
|
+ var bundleID: String!
|
|
|
+ bundleID = Bundle.main.object(forInfoDictionaryKey: "CFBundleIdentifier") as! String
|
|
|
+ return bundleID;
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+// /api/coupons/retrieval
|
|
|
+/*
|
|
|
+ ▿ Optional<AnyObject>
|
|
|
+ ▿ some : 2 elements
|
|
|
+ ▿ 0 : 2 elements
|
|
|
+ - key : app_code
|
|
|
+ - value : com.brother.pdfreaderprofree.windows
|
|
|
+ ▿ 1 : 2 elements
|
|
|
+ - key : data
|
|
|
+ ▿ value : 12 elements
|
|
|
+ ▿ 0 : 2 elements
|
|
|
+ - key : id
|
|
|
+ - value : 5851c5d6-f43e-32b2-8660-a6222194fee4
|
|
|
+ ▿ 1 : 2 elements
|
|
|
+ - key : discount
|
|
|
+ - value : <null>
|
|
|
+ ▿ 2 : 2 elements
|
|
|
+ - key : member
|
|
|
+ ▿ value : 2 elements
|
|
|
+ ▿ 0 : 2 elements
|
|
|
+ - key : email
|
|
|
+ - value : sec-2@drmail.in
|
|
|
+ ▿ 1 : 2 elements
|
|
|
+ - key : full_name
|
|
|
+ - value : test-nilvbo2
|
|
|
+ ▿ 3 : 2 elements
|
|
|
+ - key : coupon_provider
|
|
|
+ ▿ value : 15 elements
|
|
|
+ ▿ 0 : 2 elements
|
|
|
+ - key : id
|
|
|
+ - value : 291
|
|
|
+ ▿ 1 : 2 elements
|
|
|
+ - key : category
|
|
|
+ - value : presented
|
|
|
+ ▿ 2 : 2 elements
|
|
|
+ - key : start_date
|
|
|
+ - value : <null>
|
|
|
+ ▿ 3 : 2 elements
|
|
|
+ - key : limit_product
|
|
|
+ - value : 0
|
|
|
+ ▿ 4 : 2 elements
|
|
|
+ - key : total_amount
|
|
|
+ - value : 59502
|
|
|
+ ▿ 5 : 2 elements
|
|
|
+ - key : rcode
|
|
|
+ - value :
|
|
|
+ ▿ 6 : 2 elements
|
|
|
+ - key : end_date
|
|
|
+ - value : <null>
|
|
|
+ ▿ 7 : 2 elements
|
|
|
+ - key : created_at
|
|
|
+ - value : 2024-05-24 07:20:21
|
|
|
+ ▿ 8 : 2 elements
|
|
|
+ - key : discount
|
|
|
+ - value : <null>
|
|
|
+ ▿ 9 : 2 elements
|
|
|
+ - key : limit_product_code
|
|
|
+ - value :
|
|
|
+ ▿ 10 : 2 elements
|
|
|
+ - key : minimum_charge
|
|
|
+ - value : 59.99
|
|
|
+ ▿ 11 : 2 elements
|
|
|
+ - key : price
|
|
|
+ - value : 15
|
|
|
+ ▿ 12 : 2 elements
|
|
|
+ - key : valid_period
|
|
|
+ - value : 336.hours
|
|
|
+ ▿ 13 : 2 elements
|
|
|
+ - key : product_id
|
|
|
+ - value : 15
|
|
|
+ ▿ 14 : 2 elements
|
|
|
+ - key : received_amount
|
|
|
+ - value : 39
|
|
|
+ ▿ 4 : 2 elements
|
|
|
+ - key : expire_date
|
|
|
+ - value : 1718857051
|
|
|
+ ▿ 5 : 2 elements
|
|
|
+ - key : created_at
|
|
|
+ - value : 2024-06-06 04:17:31
|
|
|
+ ▿ 6 : 2 elements
|
|
|
+ - key : source_type
|
|
|
+ - value : event
|
|
|
+ ▿ 7 : 2 elements
|
|
|
+ - key : minimum_charge
|
|
|
+ - value : 59.99
|
|
|
+ ▿ 8 : 2 elements
|
|
|
+ - key : price
|
|
|
+ - value : 15
|
|
|
+ ▿ 9 : 2 elements
|
|
|
+ - key : coupon_provider_id
|
|
|
+ - value : 291
|
|
|
+ ▿ 10 : 2 elements
|
|
|
+ - key : code
|
|
|
+ - value : E85B-9C31-6EAB
|
|
|
+ ▿ 11 : 2 elements
|
|
|
+ - key : status
|
|
|
+ - value : expired
|
|
|
+ */
|