需求
近期因為公司業務需求,需要接入建行支付,包含建行龍支付和建行分期,因為分期只需要接入H5即可,龍支付需要H5和APP之間切換,故此將接入步驟詳細記錄下來,方便他人再次接入的時候,少入坑。(真的要吐槽下建行的文件,不夠詳細)。
##配置資訊
1.首先需要在plist中進行scheme白名單配置,如下圖:
2.plist 的 NSAppTransportSecurity 欄位新增相應的 NSExceptionDomains:
<key>NSExceptionDomains</key> <dict> <key>ibsbjstar.ccb.com.cn</key> <dict> <key>NSExceptionAllowsInsecureHTTPLoads</key> <true/> <key>NSExceptionRequiresForwardSecrecy</key> <false/> <key>NSIncludesSubdomains</key> <true/> </dict> </dict>
3. 在URL Types 裡面配置回撥scheme,如下圖中的此處的值很重要,我在整合的時候,就是因為這個值,導致整個支付流程走不下去,在支付中,安裝了建行的app,建行支付頁面的時候,也跳轉到了建行APP中的支付頁面,當我點選右上角**返回按鈕或者支付完成後**,點選完成時,因為下圖中的url schemes沒有配置好,導致點選建行相關app回撥按鈕時,建行的app直接掛了。
上面兩張圖是建行給的文件資訊,後來進過反覆試驗,發現第三張圖中的schemes,是第一張或者第二張圖中 該欄位 **THIRDAPPINFO** 所對應的值,後來將改值填入,需要說明的是,這個值生成有有規則的,具體需要和後端人員商討。這個值真的很重要。
發起支付
1.在發起支付時,應該需要和後端呼叫介面,然後獲取去相關的url或者引數.
- (void)loadBBCWithUrlStr:(NSString*)urlStr { if (urlStr.length > 0) { dispatch_async(dispatch_get_main_queue(), ^{ NSURLRequest *webRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:urlStr] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30]; [self.webView loadRequest:webRequest]; }); }}
2.處理WebView回撥
#pragma mark - UIWebViewDelegate -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { self.currentLoadUrl = request.URL.absoluteString; NSString *currentLoadUrl = [self.currentLoadUrl uppercaseString]; NSURLComponents *components = [[NSURLComponents alloc] initWithString:self.currentLoadUrl]; NSArray<NSURLQueryItem *> *items = components.queryItems; __block BOOL paySuccess = NO; [items enumerateObjectsUsingBlock:^(NSURLQueryItem * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { if ([obj.name isEqualToString:@"SUCCESS"]) { if ([obj.value isEqualToString:@"Y"]) { paySuccess = YES; *stop = YES; } } }]; if (paySuccess) { //建行分期成功攔截 if (self.successBlock) { self.successBlock(nil); } [self.navigationController popViewControllerAnimated:YES]; return YES; } NSString *urlScheme = [[request URL] scheme]; if ([urlScheme isEqualToString:@"mbspay"]) { if ([[UIApplication sharedApplication] canOpenURL:[request URL]]) { if (@available(iOS 10.0, *)) { [[UIApplication sharedApplication] openURL:request.URL options:@{} completionHandler:nil]; } else { [[UIApplication sharedApplication] openURL:request.URL]; } return NO; } } return YES;}
後記
理論上建行app取消支付和支付完成後,還是需要在AppDelegate中做相應的處理,才能知道支付結果
最新評論