Commit 095d62761812d0ec4ad344c4ab82e536422a29c2
1 parent
c8cb138c
电商h5调通微信支付和支付宝支付
Showing
5 changed files
with
51 additions
and
29 deletions
metaCode/Classes/Config/CNLiveConfigManager.swift
| ... | ... | @@ -95,4 +95,9 @@ extension Notification.Name { |
| 95 | 95 | //认证页垂直方向是哪个页面的通知 1上面页 2中间页 3下面页 |
| 96 | 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 | 197 | hiddenLoading() |
| 198 | 198 | if status == .success{ |
| 199 | 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 | 203 | }else{ |
| 202 | 204 | if lastCount > 0{ |
| 203 | 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 | 123 | print("json 字典是空的") |
| 124 | 124 | return |
| 125 | 125 | } |
| 126 | - // 获取所有键 | |
| 127 | - let allKeys = json.keys | |
| 128 | 126 | // 使用可选链获取 orderNumber,如果不存在则返回空字符串 |
| 129 | 127 | let orderNumber = json["orderNumber"] as? String ?? "" |
| 130 | - // 获取 payModel,如果不存在或者不是字符串类型,则使用默认值 "2" | |
| 131 | -// let payModel = (json["payModel"] as? String) ?? "2" | |
| 132 | - // 现在你可以使用 orderNumber 和 payModel 进行后续操作 | |
| 133 | 128 | let vc = CNLiveShopPayController(orderNumber: orderNumber) |
| 134 | 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 | 133 | params.setValue(payType.hashValue, forKey: "payType") |
| 138 | 134 | params.setValue(payResult.hashValue, forKey: "payResult") |
| 139 | 135 | |
| 140 | - let sparams = params.jsonString() | |
| 136 | + let sparams = self!.stringByJson(params as? [String : Any]) | |
| 141 | 137 | let appPaymentCallbackJS = String(format: "appPaymentCallback('%@')", sparams ?? "") |
| 142 | - | |
| 143 | 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 | 157 | print("json 字典是空的") |
| 163 | 158 | return |
| 164 | 159 | } |
| 165 | - // 获取所有键 | |
| 166 | - let allKeys = json.keys | |
| 167 | 160 | // 使用可选链和条件绑定获取 type,如果不存在或不是数字,则使用默认值 0 |
| 168 | 161 | let type: UInt = (json["type"] as? NSNumber)?.uintValue ?? 0 |
| 169 | 162 | // 使用可选链获取 id 和 ext,如果不存在则返回空字符串 |
| 170 | 163 | let targetId = json["id"] as? String ?? "" |
| 171 | 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 | 166 | showLoading(message: "") |
| 178 | 167 | CNLiveShoph5ViewModel.postGetShareDataWithType(type: NSInteger(type), targetId: targetId, ext: ext) { result, status in |
| ... | ... | @@ -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 | 216 | // MARK: - wjjh5的交互回调调用 |
| 200 | 217 | func configBridge(){ |
| 201 | 218 | WKWebViewJavascriptBridge.enableLogging() |
| ... | ... | @@ -224,7 +241,7 @@ class CNWebView:UIView,WKNavigationDelegate, WKScriptMessageHandler{ |
| 224 | 241 | let dic = data as! Dictionary<String, Any> |
| 225 | 242 | let index = (dic["index"] as! NSString).integerValue |
| 226 | 243 | let imageArray = dic["imgArr"] as! NSArray |
| 227 | - var imgArray = NSMutableArray() | |
| 244 | + let imgArray = NSMutableArray() | |
| 228 | 245 | for dict in imageArray { |
| 229 | 246 | var imgUrl = "" |
| 230 | 247 | if let dictemp = dict as? String{ |
| ... | ... | @@ -261,14 +278,14 @@ class CNWebView:UIView,WKNavigationDelegate, WKScriptMessageHandler{ |
| 261 | 278 | |
| 262 | 279 | //h5拉起原生跳转苹果内购 |
| 263 | 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
metaCode/Classes/Main/HomePage/View/VerticalViews/UpSlide/CNUpSlideView.swift
| ... | ... | @@ -78,7 +78,6 @@ class CNUpSlideView:UIView{ |
| 78 | 78 | view.removeFromSuperview() |
| 79 | 79 | } |
| 80 | 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 | 81 | if _downPath?.count ?? 0 > 0{ |
| 83 | 82 | self.addSubview(self.webView) |
| 84 | 83 | if self.webView.cnWebView.url?.absoluteString.contains(_downPath) == false && self.webView.cnWebView.url != nil{ | ... | ... |