Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

h5调起微信支付一系列问题(商家参数错误及无法返回app) #1

Open
cheenbee opened this Issue Sep 6, 2018 · 0 comments

Comments

1 participant
@cheenbee
Copy link
Owner

cheenbee commented Sep 6, 2018

h5 无法调起微信支付错误:商家参数格式有误

1.商家参数格式有误,请联系商家解决 参考微信官方文档罗列的常见错误

  1. APP里调起H5支付,需要在 webview 中手动设置referer, referer的作用是验证是否为安全支付来源, 代码如下: (本文以UIWebView为例)
- (BOOL) webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType) navigationType 
{
    NSDictionary *headers = [request allHTTPHeaderFields];
    BOOL hasReferer = [headers objectForKey:@"Referer"]!=nil;
    if (hasReferer) {
        // .. is this my referer?
        return YES;
    } else {
        // relaunch with a modified request
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            dispatch_async(dispatch_get_main_queue(), ^{
                NSURL *url = [request URL];
                NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
                [request setHTTPMethod:@"GET"];
                [request setValue:@"https://whatever.com" forHTTPHeaderField: @"Referer"];
                [self.webView loadRequest:request];
            });
        });
        return NO;
    }
}

(https://stackoverflow.com/questions/7913305/specifying-http-referer-in-embedded-uiwebview?noredirect=1)

iOS h5 支付从微信返回直接跳转到 Safari 浏览器无法跳转到 app

修改 Referer 和配置 scheme 进行跳转

  1. 设置 Referer 值为:

    [request setValue:@"whatever.com://" forHTTPHeaderField: @"Referer"];  
    
  2. 在Xcode项目Target->Info->URL Types 添加一个scheme

  3. Referer 去除 http:// 或 https:// 依然可以进行支付

在 Safari 浏览器中进行 scheme 跳转回app

  1. h5支付完成会配置一个回调地址,在此网页中再次进行scheme跳转

    window.location.href = "scheme://whatever.com"
    
  2. 在 Safari 中可以通过scheme打开指定 app, 经过浏览器迂回跳转到 app,也可以配置scheme进行指定页面跳转

参考:

  1. ios微信H5支付提示参数格式错误
  2. iOS 解决微信h5支付无法直接返回APP的问题
  3. iOS实现微信外部H5支付完成后返回原APP(多APP也可实现)
  4. iOS支付宝H5支付无法返回APP解决方案
  5. iOS scheme跳转机制

@cheenbee cheenbee added the iOS label Sep 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.