Commit 16699f9c2bf766d67de8d1ae98a4a81eb7a16978
1 parent
42057c6e
内购付费
Showing
3 changed files
with
27 additions
and
2 deletions
metaCode/Classes/Main/HomePages/ViewModel/CNLiveHomePageViewModel.swift
| @@ -635,6 +635,31 @@ class CNLiveHomePageViewModel:NSObject,URLSessionTaskDelegate{ | @@ -635,6 +635,31 @@ class CNLiveHomePageViewModel:NSObject,URLSessionTaskDelegate{ | ||
| 635 | } | 635 | } |
| 636 | } | 636 | } |
| 637 | } | 637 | } |
| 638 | + //内购 | ||
| 639 | + static func generateTradeNumber() -> String { | ||
| 640 | + // 生成3个0-9的随机数 | ||
| 641 | + let randomDigits = (0..<3).map { _ in String(Int.random(in: 0...9)) }.joined() | ||
| 642 | + | ||
| 643 | + // 日期格式化(yyMMdd) | ||
| 644 | + let dateFormatter = DateFormatter() | ||
| 645 | + dateFormatter.dateFormat = "yyMMdd" | ||
| 646 | + let dateString = dateFormatter.string(from: Date()) | ||
| 647 | + | ||
| 648 | + // 处理时间戳(精确到毫秒) | ||
| 649 | + let timestamp = String(format: "%.0f", Date().timeIntervalSince1970 * 1000) | ||
| 650 | + | ||
| 651 | + // 截取时间戳后8位,并处理异常情况 | ||
| 652 | + let timeString: String = { | ||
| 653 | + guard timestamp.count >= 8 else { | ||
| 654 | + return String(timestamp.suffix(timestamp.count)) | ||
| 655 | + } | ||
| 656 | + return String(timestamp.suffix(8)) | ||
| 657 | + }() | ||
| 658 | + | ||
| 659 | + // 组合交易号 | ||
| 660 | + return "003apple\(dateString)\(timeString)\(randomDigits)" | ||
| 661 | + } | ||
| 662 | + | ||
| 638 | static func getRandomOrderId() -> String { | 663 | static func getRandomOrderId() -> String { |
| 639 | // appId+渠道+年月日+毫秒数后10位+2位数的随机数 | 664 | // appId+渠道+年月日+毫秒数后10位+2位数的随机数 |
| 640 | var randomOrderId = "" | 665 | var randomOrderId = "" |
metaCode/Classes/Main/HuBiLieHomePage/Controller/CNLiveTVPlayerViewController.swift
| @@ -342,7 +342,7 @@ class CNLiveTVPlayerViewController:UIViewController, UITableViewDataSource, UITa | @@ -342,7 +342,7 @@ class CNLiveTVPlayerViewController:UIViewController, UITableViewDataSource, UITa | ||
| 342 | //支付按钮,拉起内购 | 342 | //支付按钮,拉起内购 |
| 343 | //成功用pay参数 刷新页面 | 343 | //成功用pay参数 刷新页面 |
| 344 | 344 | ||
| 345 | - let orderId = CNLiveHomePageViewModel.getRandomOrderId() | 345 | + let orderId = CNLiveHomePageViewModel.generateTradeNumber() |
| 346 | let notifyUrl = "http://apps.pay.cnlive.com/upappnotify/notify/orderForVideo" | 346 | let notifyUrl = "http://apps.pay.cnlive.com/upappnotify/notify/orderForVideo" |
| 347 | //分转元,没有小数点 | 347 | //分转元,没有小数点 |
| 348 | let fenString = self.payVodAlbumListModel?.product?.iosRmb ?? "100" | 348 | let fenString = self.payVodAlbumListModel?.product?.iosRmb ?? "100" |
metaCode/Classes/Other/AppDelegate.swift
| @@ -65,7 +65,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { | @@ -65,7 +65,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { | ||
| 65 | 65 | ||
| 66 | CNLivePaySDK.sharedCNLivePayManager().registerApp(CNLiveMCEnvironmentManager.shared.appId_wjj, appKey: CNLiveMCEnvironmentManager.shared.appKey_wjj, isTestEnvironment: false) | 66 | CNLivePaySDK.sharedCNLivePayManager().registerApp(CNLiveMCEnvironmentManager.shared.appId_wjj, appKey: CNLiveMCEnvironmentManager.shared.appKey_wjj, isTestEnvironment: false) |
| 67 | CNLivePaySDK.sharedCNLivePayManager().registerWXApi(withWXAppId: wxAppId, universalLink: universalLinkURL) | 67 | CNLivePaySDK.sharedCNLivePayManager().registerWXApi(withWXAppId: wxAppId, universalLink: universalLinkURL) |
| 68 | - | 68 | + print("1111:\(CNLiveMCEnvironmentManager.shared.appId_wjj),\(CNLiveMCEnvironmentManager.shared.appKey_wjj),\(wxAppId),\(universalLinkURL)") |
| 69 | window = UIWindow.init(frame: UIScreen.main.bounds) | 69 | window = UIWindow.init(frame: UIScreen.main.bounds) |
| 70 | window?.backgroundColor = KVCBackgroupColor | 70 | window?.backgroundColor = KVCBackgroupColor |
| 71 | let is_login = UserDefaults.standard.bool(forKey: "is_login") | 71 | let is_login = UserDefaults.standard.bool(forKey: "is_login") |