Prechádzať zdrojové kódy

feat:paypal支付webview修改

“wangdongchao” 1 rok pred
rodič
commit
be9aba5d4a

+ 6 - 0
WMBase/WMBase/UCMBaseC.m

@@ -27,6 +27,12 @@
     [super viewWillAppear:animated];
     self.tabBarController.tabBar.hidden = self.navigationController.viewControllers.count > 1;
 }
+
+- (void)viewDidAppear:(BOOL)animated {
+    [super viewDidAppear:animated];
+    self.tabBarController.tabBar.hidden = self.navigationController.viewControllers.count > 1;
+    
+}
 #pragma mark -- 公开方法
 -(void)ucm_bindvmmodel{
 }

+ 74 - 0
WMBase/WMBase/UCM_Web/XXX_BaseWebC.m

@@ -9,6 +9,7 @@
 #import "DsJsInteractAPI.h"
 #import "TT_ProgressV.h"
 #import "UIDevice+StateHeight.h"
+#import "NSString+URL.h"
 
 @interface XXX_BaseWebC () 
 @property (nonatomic, strong) TT_ProgressV *wkweb_pv;
@@ -27,6 +28,8 @@
     if(self.isPayType == YES){
         [self present_confignavBarBar];
     }
+    
+    [self tt_addSubviews];
 }
 
 - (void)viewWillAppear:(BOOL)animated {
@@ -92,11 +95,57 @@
 /// 页面加载失败时调用
 - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(NSError *)error {
     [self web_pvframeis_Hide:NO];
+    
+    if (self.isPayType) {
+        [self loadEndWithUrl:webView.URL];
+    }
 }
 ///页面加载完成时调用
 -(void)webView:(WKWebView*)webView didFinishNavigation:(WKNavigation*)navigation{
     [self web_pvframeis_Hide:NO];
 
+    if (self.isPayType) {
+        [self loadEndWithUrl:webView.URL];
+    }
+}
+
+- (void)loadEndWithUrl:(NSURL *)webUrl {
+    
+    NSString *urlStr = [webUrl absoluteString];
+    
+    NSLog(@"urlStrurlStr======%@", urlStr);
+    NSLog(@"webUrl.query======%@", webUrl.query);
+    
+    if ([urlStr containsString:@"rest/V1/rewrite/paypal/cancel"]) {
+        // 取消paypal支付
+        
+        NSDictionary *cancelDic = @{@"title":@"Cancel Pay"};
+        
+        if (self.WebViewBlock) {
+            self.WebViewBlock(0, cancelDic);
+        }
+        
+        [self tool_PopViewController];
+        
+    } else if ([urlStr containsString:@"rest/V1/rewrite/paypal/return"]){
+        
+        NSDictionary *successDic = [webUrl.query getURLParameters];
+        
+        if (self.WebViewBlock) {
+            self.WebViewBlock(1, successDic);
+        }
+        
+        [self tool_PopViewController];
+        
+    }
+    
+//
+    
+    
+    
+    
+    
+    
 }
 
 #pragma mark - **************** wkweb_pv ****************
@@ -130,6 +179,31 @@
 }
 
 
+-(void)webJs_onClose{
+    @weakify(self)
+    [self.dwebview callHandler:@"onClose" completionHandler:^(id  _Nullable value) {
+        NSLog(@"onClose ---- value:%@",value);///exits
+     @strongify(self)
+//        if(isValid(value)){
+//            [self tool_closeSaveValue:value];
+//        }
+        [self tool_PopViewController];
+    } ];
+}
+
+- (void)tool_PopViewController{
+    if (self.navigationController) {
+        if (self.navigationController.viewControllers.count == 1) {
+            if (self.presentingViewController) {
+                [self dismissViewControllerAnimated:YES completion:nil];
+            }
+        } else {
+            [self.navigationController popViewControllerAnimated:YES];
+        }
+    } else if(self.presentingViewController) {
+        [self dismissViewControllerAnimated:YES completion:nil];
+    }
+}
 
 
 

+ 6 - 0
WMBase/WMBase/UC_Commonmodule/UC_CommonmoduleCat/NSString+URL.h

@@ -45,4 +45,10 @@
 //判断是否为整形:
 
 - (BOOL)isPureInt:(NSString*)string;
+
+/**
+ * 通过url.query获取参数字符 再分成字典
+ */
+- (NSMutableDictionary *)getURLParameters;
+
 @end

+ 63 - 0
WMBase/WMBase/UC_Commonmodule/UC_CommonmoduleCat/NSString+URL.m

@@ -199,5 +199,68 @@
             result[12], result[13], result[14], result[15]];
 }
 
+//通过url.query获取参数字符 再分成字典
+-(NSMutableDictionary *)getURLParameters
+{
+    if (!self.length) {
+        return nil;
+    }
+    NSMutableDictionary  *params = [NSMutableDictionary   dictionary];
+    if ([self containsString:@"&"]) {
+        NSArray *urlComponents = [self componentsSeparatedByString:@"&"];
+        
+        for(NSString *keyValuePair in urlComponents) {
+            
+            //生成key/value
+            NSArray *pairComponents = [keyValuePair componentsSeparatedByString:@"="];
+            NSString *key = [pairComponents.firstObject stringByRemovingPercentEncoding];
+            NSString*value = [pairComponents.lastObject stringByRemovingPercentEncoding];
+            if(keyValuePair.length > key.length+1){
+                
+                value = [keyValuePair substringFromIndex:key.length+1];
+
+            }
+            
+            //key不能为nil
+            
+            if(key==nil|| value ==nil) continue;
+            
+            id existValue = [params valueForKey:key];
+            if(existValue !=nil) {
+                //已存在的值,生成数组。
+                if([existValue isKindOfClass:[NSArray class]]) {
+                    //已存在的值生成数组
+                    NSMutableArray*items = [NSMutableArray arrayWithArray:existValue];
+                    [items addObject:value];
+                    [params setValue:items forKey:key];
+                }else{
+                    //非数组
+                    [params setValue:@[existValue,value]forKey:key];
+                }
+                
+            }else{
+                //设置值
+                [params setValue:value forKey:key];
+            }
+            
+        }
+    }else {
+        //单个参数生成key/value
+        NSArray *pairComponents = [self componentsSeparatedByString:@"="];
+        if(pairComponents.count==1) {
+            return nil;
+        }
+        //分隔值
+        NSString *key = [pairComponents.firstObject stringByRemovingPercentEncoding];
+        NSString *value = [pairComponents.lastObject stringByRemovingPercentEncoding];
+        //key不能为nil
+        if(key ==nil|| value ==nil)return nil;
+        //设置值
+        [params setValue:value forKey:key];
+        
+    }
+    return params;
+}
+
 
 @end