iOS開(kāi)發(fā)之調(diào)起微信H5支付(包括外網(wǎng)IP獲取方法)

全是干貨,不過(guò)多廢話.

1.首先需要調(diào)用接口,因?yàn)镠5微信鏈接接口請(qǐng)求成功后會(huì)返回

干貨一:請(qǐng)求參數(shù)需要外網(wǎng)IP給后臺(tái),外網(wǎng)IP的獲取

搜了一些資料,講的全是內(nèi)網(wǎng)IP的獲取.

//獲取外網(wǎng)IP

? ? NSURL *ipURL = [NSURL URLWithString:@"http://ip.taobao.com/service/getIpInfo2.php?ip=myip"];

? ? NSData *data = [NSData dataWithContentsOfURL:ipURL];

? ? NSDictionary *ipDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];

? ? NSString *ipStr = nil;

? ? if (ipDic && [ipDic[@"code"] integerValue] == 0) { //獲取成功

? ? ? ? ? ipStr = ipDic[@"data"][@"ip"];

? ? }

? ? NSLog(@"ipStr == %@",ipStr);

接口返回H5微信支付的鏈接,調(diào)用WebView打開(kāi)

干貨二:打開(kāi)鏈接顯示商家參數(shù)格式有誤,請(qǐng)聯(lián)系商家解決


這里需要設(shè)置webView的Referer

_webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, gScreenWidth, gScreenHeight)];

? ? _webView.delegate = self;

? ? [self.view addSubview:_webView];

? ? NSURL *url = [NSURL URLWithString:urlStr];

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

? ? NSDictionary *headers = [request allHTTPHeaderFields];

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

? ? if (hasReferer) {

? ? ? ? // .. is this my referer?

? ? } else {

? ? ? ? // relaunch with a modified requesthttps://upload-images.jianshu.io/upload_images/12287987-d8e15aab7a556d69.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240

? ? ? ? dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

? ? ? ? ? ? dispatch_async(dispatch_get_main_queue(), ^{

? ? ? ? ? ? ? ? NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlStr] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];

? ? ? ? ? ? ? ? [request setValue:@"buyhoo.cc://" forHTTPHeaderField: @"Referer"];

? ? ? ? ? ? ? ? [_webView loadRequest:request];

? ? ? ? ? ? });

? ? ? ? });

? ? }

只是這樣還是不行的,不能調(diào)起微信H5支付

最后一步,需要設(shè)置URL Types

剛剛Referer設(shè)置的什么,去掉://就是需要填在這里的


剛剛Referer設(shè)置的buyhoo.cc://


去掉://就是buyhoo.cc

這樣就能成功的調(diào)起微信H5支付了

喜歡的點(diǎn)個(gè)贊吧~

參考文章:iOS解決微信h5支付無(wú)法直接返回app的問(wèn)題

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容