Commit 095d62761812d0ec4ad344c4ab82e536422a29c2

Authored by “张旭”
1 parent c8cb138c

电商h5调通微信支付和支付宝支付

metaCode/Classes/Config/CNLiveConfigManager.swift
@@ -95,4 +95,9 @@ extension Notification.Name { @@ -95,4 +95,9 @@ extension Notification.Name {
95 //认证页垂直方向是哪个页面的通知 1上面页 2中间页 3下面页 95 //认证页垂直方向是哪个页面的通知 1上面页 2中间页 3下面页
96 public static let kAuthVNumPageChangedNotification = Notification.Name("kAuthVNumPageChangedNotification") 96 public static let kAuthVNumPageChangedNotification = Notification.Name("kAuthVNumPageChangedNotification")
97 } 97 }
  98 + struct ShopOrderManage{
  99 + //电商h5订单支付成功通知
  100 + public static let kDSSuccessPayOrderNotification = Notification.Name("kDSSuccessPayOrderNotification")
  101 + }
  102 +
98 } 103 }
metaCode/Classes/Main/HomePage/Controller/ShopPayController/CNLiveShopPayController.swift
@@ -197,7 +197,9 @@ class CNLiveShopPayController:CNLiveBaseViewController,UITableViewDelegate,UITab @@ -197,7 +197,9 @@ class CNLiveShopPayController:CNLiveBaseViewController,UITableViewDelegate,UITab
197 hiddenLoading() 197 hiddenLoading()
198 if status == .success{ 198 if status == .success{
199 self.finishPayCallBack?(self.orderInfoModel!, self.payType!, .success) 199 self.finishPayCallBack?(self.orderInfoModel!, self.payType!, .success)
200 -// NotificationCenter.default.post(name: <#T##NSNotification.Name#>, object: <#T##Any?#>)//kDSSuccessPayOrderNotification 200 +// NotificationCenter.default.post(name: Notification.Name.ShopOrderManage.kDSSuccessPayOrderNotification, object: nil)
  201 + self.navigationController?.popViewController(animated: true)
  202 +
201 }else{ 203 }else{
202 if lastCount > 0{ 204 if lastCount > 0{
203 DispatchQueue.main.asyncAfter(deadline: .now() + 1) { 205 DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
metaCode/Classes/Main/HomePage/Controller/WebController/CNWebView.swift
@@ -123,25 +123,20 @@ class CNWebView:UIView,WKNavigationDelegate, WKScriptMessageHandler{ @@ -123,25 +123,20 @@ class CNWebView:UIView,WKNavigationDelegate, WKScriptMessageHandler{
123 print("json 字典是空的") 123 print("json 字典是空的")
124 return 124 return
125 } 125 }
126 - // 获取所有键  
127 - let allKeys = json.keys  
128 // 使用可选链获取 orderNumber,如果不存在则返回空字符串 126 // 使用可选链获取 orderNumber,如果不存在则返回空字符串
129 let orderNumber = json["orderNumber"] as? String ?? "" 127 let orderNumber = json["orderNumber"] as? String ?? ""
130 - // 获取 payModel,如果不存在或者不是字符串类型,则使用默认值 "2"  
131 -// let payModel = (json["payModel"] as? String) ?? "2"  
132 - // 现在你可以使用 orderNumber 和 payModel 进行后续操作  
133 let vc = CNLiveShopPayController(orderNumber: orderNumber) 128 let vc = CNLiveShopPayController(orderNumber: orderNumber)
134 vc.finishPayCallBack = { [weak self] orderInfoModel ,payType ,payResult in 129 vc.finishPayCallBack = { [weak self] orderInfoModel ,payType ,payResult in
135 - let params = NSDictionary()  
136 - params.setValue(orderInfoModel.toJSONString() ?? "", forKey: "orderInfo") 130 + let params = NSMutableDictionary()
  131 + let jsonStr = orderInfoModel.toJSONString() ?? ""
  132 + params.setValue(jsonStr, forKey: "orderInfo")
137 params.setValue(payType.hashValue, forKey: "payType") 133 params.setValue(payType.hashValue, forKey: "payType")
138 params.setValue(payResult.hashValue, forKey: "payResult") 134 params.setValue(payResult.hashValue, forKey: "payResult")
139 135
140 - let sparams = params.jsonString() 136 + let sparams = self!.stringByJson(params as? [String : Any])
141 let appPaymentCallbackJS = String(format: "appPaymentCallback('%@')", sparams ?? "") 137 let appPaymentCallbackJS = String(format: "appPaymentCallback('%@')", sparams ?? "")
142 -  
143 self?.cnWebView.evaluateJavaScript(appPaymentCallbackJS, completionHandler: { result, error in 138 self?.cnWebView.evaluateJavaScript(appPaymentCallbackJS, completionHandler: { result, error in
144 - print("22222222appPaymentCallbackJS:\(result)") 139 +// print("error \(error)")
145 }) 140 })
146 } 141 }
147 // 跳转支付页面 142 // 跳转支付页面
@@ -162,17 +157,11 @@ class CNWebView:UIView,WKNavigationDelegate, WKScriptMessageHandler{ @@ -162,17 +157,11 @@ class CNWebView:UIView,WKNavigationDelegate, WKScriptMessageHandler{
162 print("json 字典是空的") 157 print("json 字典是空的")
163 return 158 return
164 } 159 }
165 - // 获取所有键  
166 - let allKeys = json.keys  
167 // 使用可选链和条件绑定获取 type,如果不存在或不是数字,则使用默认值 0 160 // 使用可选链和条件绑定获取 type,如果不存在或不是数字,则使用默认值 0
168 let type: UInt = (json["type"] as? NSNumber)?.uintValue ?? 0 161 let type: UInt = (json["type"] as? NSNumber)?.uintValue ?? 0
169 // 使用可选链获取 id 和 ext,如果不存在则返回空字符串 162 // 使用可选链获取 id 和 ext,如果不存在则返回空字符串
170 let targetId = json["id"] as? String ?? "" 163 let targetId = json["id"] as? String ?? ""
171 let ext = json["ext"] as? String ?? "" 164 let ext = json["ext"] as? String ?? ""
172 - // 现在你可以使用 type, idStr 和 ext 进行后续操作  
173 - print("type: \(type)")  
174 - print("id: \(targetId)")  
175 - print("ext: \(ext)")  
176 //请求分享参数 165 //请求分享参数
177 showLoading(message: "") 166 showLoading(message: "")
178 CNLiveShoph5ViewModel.postGetShareDataWithType(type: NSInteger(type), targetId: targetId, ext: ext) { result, status in 167 CNLiveShoph5ViewModel.postGetShareDataWithType(type: NSInteger(type), targetId: targetId, ext: ext) { result, status in
@@ -195,7 +184,35 @@ class CNWebView:UIView,WKNavigationDelegate, WKScriptMessageHandler{ @@ -195,7 +184,35 @@ class CNWebView:UIView,WKNavigationDelegate, WKScriptMessageHandler{
195 } 184 }
196 } 185 }
197 } 186 }
198 - 187 + // MARK: - 字典转字符串
  188 + func stringByJson(_ json: [String: Any]?) -> String? {
  189 + guard let json = json else {
  190 + return nil
  191 + }
  192 +
  193 + do {
  194 + let data = try JSONSerialization.data(withJSONObject: json, options: .prettyPrinted)
  195 + if let string = String(data: data, encoding: .utf8) {
  196 + // 去掉字符串中的空格
  197 + let stringWithoutSpaces = string.replacingOccurrences(of: " ", with: "", options: .literal, range: nil)
  198 +
  199 + // 去掉字符串中的换行符
  200 + let stringWithoutNewlines = stringWithoutSpaces.replacingOccurrences(of: "\n", with: "", options: .literal, range: nil)
  201 +
  202 + // 去掉字符串中的转义字符 "\"
  203 + // 注意:在标准的JSON字符串中,转义字符 "\" 是必要的,因此通常不会移除它们。
  204 + // 如果你确实需要移除它们,请确保这样做不会导致JSON字符串格式错误。
  205 + let stringWithoutEscapes = stringWithoutNewlines.replacingOccurrences(of: "\\", with: "", options: .literal, range: nil)
  206 +
  207 + return stringWithoutEscapes
  208 + }
  209 + } catch {
  210 + // 处理JSONSerialization的错误
  211 + return nil
  212 + }
  213 +
  214 + return nil
  215 + }
199 // MARK: - wjjh5的交互回调调用 216 // MARK: - wjjh5的交互回调调用
200 func configBridge(){ 217 func configBridge(){
201 WKWebViewJavascriptBridge.enableLogging() 218 WKWebViewJavascriptBridge.enableLogging()
@@ -224,7 +241,7 @@ class CNWebView:UIView,WKNavigationDelegate, WKScriptMessageHandler{ @@ -224,7 +241,7 @@ class CNWebView:UIView,WKNavigationDelegate, WKScriptMessageHandler{
224 let dic = data as! Dictionary<String, Any> 241 let dic = data as! Dictionary<String, Any>
225 let index = (dic["index"] as! NSString).integerValue 242 let index = (dic["index"] as! NSString).integerValue
226 let imageArray = dic["imgArr"] as! NSArray 243 let imageArray = dic["imgArr"] as! NSArray
227 - var imgArray = NSMutableArray() 244 + let imgArray = NSMutableArray()
228 for dict in imageArray { 245 for dict in imageArray {
229 var imgUrl = "" 246 var imgUrl = ""
230 if let dictemp = dict as? String{ 247 if let dictemp = dict as? String{
@@ -261,14 +278,14 @@ class CNWebView:UIView,WKNavigationDelegate, WKScriptMessageHandler{ @@ -261,14 +278,14 @@ class CNWebView:UIView,WKNavigationDelegate, WKScriptMessageHandler{
261 278
262 //h5拉起原生跳转苹果内购 279 //h5拉起原生跳转苹果内购
263 self.bridge?.registerHandler("wjjHtmlPullApplePay", handler: { data, responseCallback in 280 self.bridge?.registerHandler("wjjHtmlPullApplePay", handler: { data, responseCallback in
264 - print("js call oc\(data)")  
265 - let dataDic = data as! Dictionary<String, Any>  
266 - let body = dataDic["body"] as? String  
267 - let notify_url = dataDic["notify_url"] as? String  
268 - let orderId = dataDic["orderId"] as? String  
269 - let prdId = dataDic["prdId"] as? String  
270 - let total_fee = dataDic["total_fee"] as? Int  
271 - print("拉起苹果内购") 281 +// print("js call oc\(data)")
  282 +// let dataDic = data as! Dictionary<String, Any>
  283 +// let body = dataDic["body"] as? String
  284 +// let notify_url = dataDic["notify_url"] as? String
  285 +// let orderId = dataDic["orderId"] as? String
  286 +// let prdId = dataDic["prdId"] as? String
  287 +// let total_fee = dataDic["total_fee"] as? Int
  288 +// print("拉起苹果内购")
272 289
273 }) 290 })
274 291
metaCode/Classes/Main/HomePage/Controller/WebController/CNWebViewController.swift
@@ -47,7 +47,6 @@ class CNWebViewController:CNLiveBaseViewController ,WKNavigationDelegate{ @@ -47,7 +47,6 @@ class CNWebViewController:CNLiveBaseViewController ,WKNavigationDelegate{
47 moreNavBtn.addTarget(self, action: #selector(moreNavBtnAction), for: .touchUpInside) 47 moreNavBtn.addTarget(self, action: #selector(moreNavBtnAction), for: .touchUpInside)
48 return moreNavBtn 48 return moreNavBtn
49 }() 49 }()
50 -  
51 50
52 var _url:URL? 51 var _url:URL?
53 var url:URL? { 52 var url:URL? {
metaCode/Classes/Main/HomePage/View/VerticalViews/UpSlide/CNUpSlideView.swift
@@ -78,7 +78,6 @@ class CNUpSlideView:UIView{ @@ -78,7 +78,6 @@ class CNUpSlideView:UIView{
78 view.removeFromSuperview() 78 view.removeFromSuperview()
79 } 79 }
80 if(type == UpDownTypeH5){ 80 if(type == UpDownTypeH5){
81 -// _downPath = "https://manageshop.cnlive.com/html/mall/1/#/pages/main/detail/detail?id=9526907&share_mold=shop&share_uid=c7KtcyWyXy7yMGCUPWuaUQ%3D%3D&shop_type=f8Ug%2BT1YxNKjy5QcYX4XlQ%3D%3D&shop_to=HNWMXVEMCtRetyucYELQtqg80ZoCVAAx%2B2jJIJuozJLTuJhb2vXeootObdZsz43yjHZNxKqF0WsT9mICYb0zHjo4STMRuQrSWYMkFzT4EQlgQS1%2BX%2FeCQ0jmkT2n4aZ9bShTP%2BB3nLDm%2BfHeBnfRpIEuEl3l9sXHnXc4p%2BcxciI%3D&shop_shop_type=f8Ug%2BT1YxNKjy5QcYX4XlQ%3D%3D&mall_share_type=2&price=0.01&originalPrice=0.00&shopShareType=1&wjjshopType=cnliveShopCar"  
82 if _downPath?.count ?? 0 > 0{ 81 if _downPath?.count ?? 0 > 0{
83 self.addSubview(self.webView) 82 self.addSubview(self.webView)
84 if self.webView.cnWebView.url?.absoluteString.contains(_downPath) == false && self.webView.cnWebView.url != nil{ 83 if self.webView.cnWebView.url?.absoluteString.contains(_downPath) == false && self.webView.cnWebView.url != nil{