联系客服: iP138.com客服 iP138客服 |

手机号码查询接口
  • API接口QQ交流群:177096428   iP138 api接口
  • 数据修正QQ处理群:94181690    iP138数据修正

手机号码查询接口支持HTTPS(赠送1000次)

简介:获取手机号码段的省市区以及运营商名称

已连接应用数:6857

国内:网宿cdn; 国际:亚洲中国香港、韩国首尔、日本东京、新加坡、欧洲德国法兰克福、北美洲美国硅谷节点

Object-C(ios)调用手机号码查询接口示例:

                                    //
                                    //  ViewController.m
                                    //  ApiTest
                                    //
                                    //  Created by administrator on 16/9/8.
                                    //  Copyright © 2016年 star. All rights reserved.
                                    //

                                    #import "ViewController.h"

                                    #define Host @"https://api.ip138.com/mobile/"

                                    @interface ViewController ()<NSXMLParserDelegate>

                                    @end

                                    @implementation ViewController

                                    - (void)viewDidLoad {
                                        [super viewDidLoad];
                                        // Do any additional setup after loading the view, typically from a nib.
                                        
                                        NSString * token = @"d0a79d9d5767b5f1f692634c9b08a71604";
                                        [self executeNetworkWithMobile:@"13578729563" dateType:@"txt" callBack:@"find" token:token];
                                        
                                    }

                                    /**
                                     *示例https://api.ip138.com/mobile/?mobile=13965321190&datatype=jsonp&callback=find&token=d0a79d9d5767b5f1f692634c9b08a71604
                                     *参数说明:
                                     *1. mobile string mobile
                                     *2. datatype string txt|jsonp|xml(可选,默认为jsonp)
                                     *3. callback string 回调函数 当前参数仅为jsonp格式数据提供(可选,默认为空)
                                     *4. token string 购买服务后会提供(必填)
                                     */

                                    - (void)executeNetworkWithMobile:(NSString *)mobile dateType:(NSString *)dateType callBack:(NSString *)callBack token:(NSString *)token{
                                       
                                        NSString * urlString =[NSString stringWithFormat:@"%@?mobile=%@&datatype=%@&callback=%@&token=%@",Host,mobile,dateType,callBack,token];
                                        
                                        //准备网络请求
                                        NSString *newStr = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                                        NSURL *url = [NSURL URLWithString:newStr];
                                        NSURLRequest *requst = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10];
                                        
                                        //请求异步链接
                                        [NSURLConnection sendAsynchronousRequest:requst queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
                                            
                                            if (connectionError) {
                                                NSLog(@"jsonError = %@",connectionError);
                                                return ;
                                            }
                                            
                                            //请求格式txt
                                            if ([dateType isEqualToString:@"txt"]) {
                                                NSString *result = [[NSString alloc] initWithData:data  encoding:NSUTF8StringEncoding];
                                                NSLog(@"result = %@",result);
                                            }
                                            //datatype xml
                                            else if ([dateType isEqualToString:@"xml"]){
                                                NSString *result = [[NSString alloc] initWithData:data  encoding:NSUTF8StringEncoding];
                                                NSLog(@"result = %@",result);
                                               
                                            }
                                            else{
                                                NSError *jsonError = nil;
                                                NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
                                                /*如果设置了回调函数,则可截取后再在转化为NSDictionary,也可直接转化为NSString*/
                                                if (callBack&&[callBack length]>0) {
                                                    NSRange range = [jsonString rangeOfString:@"("];
                                                    range.location++;
                                                    range.length = [jsonString length] - range.location - 1;
                                                    jsonString = [jsonString substringWithRange:range ];
                                                   
                                                }
                                                
                                                NSDictionary *jsonResponse =
                                                [NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding]
                                                                                options:0
                                                                                  error:&jsonError];
                                                if (jsonError) {
                                                    NSLog(@"jsonError = %@",jsonError);
                                                    return ;
                                                }
                                                NSLog(@"jsonResponse = %@",jsonResponse);
                                            }
                                        }];
                                    }

                                    - (void)didReceiveMemoryWarning {
                                        [super didReceiveMemoryWarning];
                                        // Dispose of any resources that can be recreated.
                                    }

                                    @end