#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
// 定義請求的基礎(chǔ)信息
NSString *host = @"api.ihuyi.com";
NSString *path = @"/mms/v1/batchSend";
NSString *urlString = [NSString stringWithFormat:@"http://%@%@", host, path];
NSURL *url = [NSURL URLWithString:urlString];
// 定義請求的數(shù)據(jù)
NSDictionary *values = @{
@"api_id": @"mms-xxxxxxxx", //APIID(用戶中心【富媒體短信】-【5G視頻短信】-【產(chǎn)品總覽】查看)
@"signature": @"xxxxxxxxx", //請求驗(yàn)證加密簽名(非彩信簽名);
簽名生成方式:
僅公共參數(shù)以ASCII碼從小到大排序值,key=value,多值以“&”隔開,拼接之后md5 32位小寫; 如:md5(api_id=xxxx&api_key=xxxx&request_id=xxxxxxxx×tamp=xxxxxxx)
APIKEY(用戶中心【富媒體短信】-【5G視頻短信】-【產(chǎn)品總覽】查看)
2、動態(tài)密碼(生成動態(tài)密碼方式請看該文檔末尾的說明)
@"timestamp": @1623643787, //東八時(shí)區(qū);10位時(shí)間戳,時(shí)間允許相差±60S
@"request_id": @"xxxxxxxxxxxx", //請求方請求ID,建議使用唯一ID,比如使用uuid;我方系統(tǒng)會2小時(shí)內(nèi)去重驗(yàn)證處理,防止網(wǎng)絡(luò)重復(fù)攻擊;
@"product_id": @1001, //產(chǎn)品ID
@"phone": @[@"18800000000", @"18800000001"], //手機(jī)號數(shù)組(最多1萬個(gè)號碼)
@"sign_name": @"xxxxxxxx", //彩信簽名(template_id未填寫則必填)
@"title": @"xxxxxxxxxxxx", //彩信標(biāo)題(template_id未填寫則必填)
@"content": @[@{@"con_type":@"txt",@"ext_type":@"",@"data":@"將原始內(nèi)容base64編碼"},@{@"con_type":@"img",@"ext_type":@"jpg",@"data":@"將原始內(nèi)容base64編碼"}], //彩信內(nèi)容和模板ID必須傳入1個(gè);當(dāng)彩信內(nèi)容和模板ID都傳入時(shí),傳入內(nèi)容生效,模板ID屬性失效 彩信元素DataItem結(jié)構(gòu):(具體參照文檔9.01)
@"template_id": @1, //模板ID(內(nèi)容為空則必填)
@"send_time": @"2020-08-26 16:08:14", //定時(shí)發(fā)送時(shí)間
};
// 將數(shù)據(jù)轉(zhuǎn)換為JSON數(shù)據(jù)
NSError *error = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:values
options:0
error:&error];
if (error) {
NSLog(@"JSON序列化錯(cuò)誤: %@", error.localizedDescription);
return 1;
}
// 創(chuàng)建請求對象
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestReloadIgnoringCacheData
timeoutInterval:30.0];
// 設(shè)置請求方法和頭部
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
// 設(shè)置請求體
[request setHTTPBody:jsonData];
// 創(chuàng)建會話和任務(wù)
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request
completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (error) {
NSLog(@"請求錯(cuò)誤: %@", error.localizedDescription);
return;
}
// 處理響應(yīng)
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
NSLog(@"狀態(tài)碼: %ld", (long)httpResponse.statusCode);
if (data) {
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"響應(yīng)內(nèi)容: %@", responseString);
}
}];
[task resume];
// 保持程序運(yùn)行直到請求完成(僅用于測試)
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:5.0]];
}
return 0;
}
國內(nèi)專業(yè)互聯(lián)網(wǎng)團(tuán)隊(duì)
21年行業(yè)經(jīng)驗(yàn)
7x24小時(shí)售后支持
豐富的行業(yè)經(jīng)驗(yàn)
互 億 無 線 官 方 微 信 號
Copyright ? 2004-2025 上海思銳信息技術(shù)有限公司 All rights reserved. 滬ICP備07035915號-15 電信增值業(yè)務(wù)許可證:B2-20160082
服務(wù)熱線:
4008 808 898
服務(wù)熱線(工作時(shí)間):
4008 808 898
業(yè)務(wù)咨詢(非工作時(shí)間):
售后咨詢(非工作時(shí)間):