php苹果h5微信支付白屏,iOS 微信h5支付 返回APP显示支付结果

作者:QuinceyYang (YangQing)

一、解决UIWebView页面不能调起微信支付

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

//https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb?prepay_id=wx10103020268128bfe4d291131154467378&package=2397190279&redirect_url=http://www.soargift.com/parkApp/HuarunApp/orderDetail.html?parm=order_cwyd20180911001_a22

NSString *markString = request.URL.absoluteString;

NSLog(@"markString = %@",markString);

NSDictionary *headers = [request allHTTPHeaderFields];

BOOL hasReferer = [headers objectForKey:@"Referer"]!=nil;

if (hasReferer) {

// .. is this my referer?

if ([markString containsString:@"https://wx.tenpay.com/cgi-bin/mmpayweb-bin/checkmweb"] && [markString containsString:@"http://www.soargift.com/parkApp/HuarunApp/orderDetail.html"]) {

NSRange tmpRange = [markString rangeOfString:@"&redirect_url=http://www.soargift.com/parkApp/HuarunApp/orderDetail.html"];

NSString *subStr1 = [markString substringToIndex:tmpRange.location];

NSString *subStr2 = [markString substringFromIndex:tmpRange.location+14];

[[NSUserDefaults standardUserDefaults] setObject:subStr2 forKey:@"H5PayFinishedRedirectUrl"];

[[NSUserDefaults standardUserDefaults] synchronize];

__weak __typeof(self)weakSelf = self;

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

dispatch_async(dispatch_get_main_queue(), ^{

NSURL *url = [NSURL URLWithString:subStr1];

NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];

[request setHTTPMethod:@"GET"];

[request setValue:@"www.soargift.com://" forHTTPHeaderField:@"Referer"];

[weakSelf.webView loadRequest:request];

});

});

return NO;

}

return YES;

} else {

// relaunch with a modified request

__weak __typeof(self)weakSelf = self;

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:@"www.soargift.com://" forHTTPHeaderField:@"Referer"];

[weakSelf.webView loadRequest:request];

});

});

return NO;

}

return YES;

}

二、解决微信支付后跳回Safari问题

首先你在Xcode中,选择你的工程设置项,选中“TARGETS”一栏,在“info”标签栏的“LSApplicationQueriesSchemes“添加weixin

d42fb9cf7c7c?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

再在URL Types中添加

d42fb9cf7c7c?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

三、解决跳回APP白屏问题,并显示支付结果

在对应的视图控制器中添加

//使用通知中心监听

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(h5PayFinishedGoback:) name:@"H5PayFinishedGoback" object:nil];

- (void)h5PayFinishedGoback:(NSNotification *)noti {

NSString *redirectUrl = [[NSUserDefaults standardUserDefaults] objectForKey:@"H5PayFinishedRedirectUrl"];

__weak __typeof(self)weakSelf = self;

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

dispatch_async(dispatch_get_main_queue(), ^{

NSURL *url = [NSURL URLWithString:redirectUrl];

NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];

[request setHTTPMethod:@"GET"];

[request setValue:@"www.soargift.com://" forHTTPHeaderField:@"Referer"];

[weakSelf.webView loadRequest:request];

});

});

}

在APP跳转回调接口中添加

- (BOOL)application:(UIApplication *)application

openURL:(NSURL *)url

sourceApplication:(NSString *)sourceApplication

annotation:(id)annotation

{

if ([url.scheme isEqualToString:@"www.soargift.com"]) {

[[NSNotificationCenter defaultCenter] postNotificationName:@"H5PayFinishedGoback" object:nil];

return YES;

}

}

End

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值