您是否正受到短信签名报备的困扰?互亿无线解决方案让您最快15分钟内恢复信息传递,马上 注册体验
所有文档
运营商信息核验
文档中心 > 运营商信息核验 > 空号检测

空号检测

Objective-C对接空号检测提交接口接口DEMO示例
本文为您提供了Objective-C语言版本的空号检测提交接口接口对接DEMO示例


#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        // 定义请求的基础信息
        NSString *host = @"api.ihuyi.com";
        NSString *path = @"/empty-number/submit";
        NSString *urlString = [NSString stringWithFormat:@"http://%@%@", host, path];
        NSURL *url = [NSURL URLWithString:urlString];
        
        // 定义signature变量
        NSString *signature = @"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; // 请替换为您的鉴权签名
        
        // 定义请求的数据
        NSMutableDictionary *values = [NSMutableDictionary dictionaryWithDictionary:@{
            @"mobiles": @[@"18800000000", @"18800000001"], //手机号数组(最多10个)
        }];
        
        // 将数据转换为JSON数据
        NSError *error = nil;
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:values 
                                                           options:0 
                                                             error:&error];
        
        if (error) {
            NSLog(@"JSON序列化错误: %@", error.localizedDescription);
            return 1;
        }

        // 创建请求对象
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
                                                      cachePolicy:NSURLRequestReloadIgnoringCacheData
                                                  timeoutInterval:30.0];

        // 设置请求方法和头部
        [request setHTTPMethod:@"POST"];
        [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
        [request setValue:@"Tue, 26 Aug 2025 07:14:23 GMT" forHTTPHeaderField:@"Date"];
        [request setValue:[NSString stringWithFormat:@"Signature %@" , signature] forHTTPHeaderField:@"Authorization"];

        // 设置请求体
        [request setHTTPBody:jsonData];

        // 创建会话和任务
        NSURLSession *session = [NSURLSession sharedSession];
        NSURLSessionDataTask *task = [session dataTaskWithRequest:request
                                        completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
                                            if (error) {
                                                NSLog(@"请求错误: %@", error.localizedDescription);
                                                return;
                                            }
                                            
                                            // 处理响应
                                            NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
                                            NSLog(@"状态码: %ld", (long)httpResponse.statusCode);
                                            
                                            if (data) {
                                                NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
                                                NSLog(@"响应内容: %@", responseString);
                                            }
                                        }];

        [task resume];

        // 保持程序运行直到请求完成(仅用于测试)
        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:5.0]];
    }
    return 0;
}

5分钟快速自助开通免费体验账户

在线咨询
电话咨询

服务热线:

4008 808 898

服务热线(工作时间):

4008 808 898

业务咨询(非工作时间):

售后咨询(非工作时间):