-(void)httpRequestWithURL:(NSDictionary*)dic
{
self.requestParam=dic;
NSLog(@"httpRequestWithURL: %@", dic);
//請求參數dic
NSMutableDictionary* mutableDic = [[[NSMutableDictionary alloc] initWithDictionary:dic] autorelease];
if (self.isStandardIterface)
{
//baseURL地址
self.serverPath = [IHApiConfigManager configManager].appServer;
//對字典進行正序遍歷
NSEnumerator* enumer = [[mutableDic allKeys] objectEnumerator];
NSString* key;
while (key = [enumer nextObject]) {
NSString* value = [mutableDic objectForKey:key];
if (![value isKindOfClass:[NSString class]])
{
value = [NSString stringWithFormat:@"%@", value];
[mutableDic setObject:value forKey:key];
}
}
//appkey作為參數
[mutableDic setObject:[IHApiConfigManager configManager].appKey forKey:@"appkey"];
//channel_id作為參數
[mutableDic setObject:[IHApiConfigManager configManager].channel_id forKey:@"channel_id"];
//api_version作為參數
[mutableDic setObject:[IHApiConfigManager configManager].apiVersion forKey:@"api_version"];
if (USERMODEL.sessionID==nil||[USERMODEL.sessionID length]==0)
{
}
else
{
[mutableDic setObject:USERMODEL.sessionID forKey:@"sessionid"];
}
//品牌,型號,操作系統,
NSString* ua = [[JLUainfo getInstance] getUA];
[mutableDic setObject:ua forKey:@"ua"];
//UUID
[mutableDic setObject:[IHUtility getUUID] forKey:@"deviceid"];
//imei
[mutableDic setObject:[IHUtility getIMEI] forKey:@"imei"];
//imsi
[mutableDic setObject:[IHUtility getIMSI] forKey:@"imsi"];
//時間
[mutableDic setObject:[IHUtility generateTimestamp] forKey:@"timestamp"];
[mutableDic setObject:[IHUtility generateNonce] forKey:@"nonce"];
// ihaaa.basfsfse.sysfss.initsfs
NSString* method = [mutableDic objectForKey:@"method"];
NSString* apiVersion = [IHApiConfigManager getAPIVersionWithMethod:method appKey:[IHApiConfigManager configManager].appKey];
if (apiVersion)
{
[mutableDic setObject:apiVersion forKey:@"api_version"];
}
}
//將字典
NSString* parameter = [IHUtility getParameterString:mutableDic];
//NSLog(@"paraString: %@", parameter);
NSString* url = [GJEncode URLEncode:self.serverPath];
NSString* paraEncodeString = [GJEncode URLEncode:parameter];
NSString* decRes = [NSString stringWithFormat:@"%@%@", url, paraEncodeString];
//NSLog(@"decRes:%@", decRes);
decRes = [IHUtility base64StringWithHMACSHA1Digest:decRes key:[IHApiConfigManager configManager].appSecret];
NSString* signature = [GJEncode URLEncode:decRes];
//NSLog(@"signature:%@", signature);
NSMutableDictionary* dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"json2",@"contentformat",
@"gzip" ,@"Accept-Encoding",
nil];
NSString* u = self.serverPath;
if (!self.isStandardIterface) {
u=[NSString stringWithFormat:@"%@?%@&sign=%@",self.serverPath,parameter,signature];
}
[self.httpRequest preCreateConnectRequestWithURL:u];
[self.httpRequest setHttpHeader:dict];
[self.httpRequest setHttpMethod:@"POST"];
NSString* postStr = [NSString stringWithFormat:@"%@&sign=%@", parameter, signature];
NSLog(@"total url: %@?%@", self.serverPath, postStr);
[self.httpRequest setHttpBody:[postStr dataUsingEncoding:NSUTF8StringEncoding]];
[self setHttpConnectFinishedMethod:self.httpRequest];
[self.httpRequest startCreatedConnectWithFurtherInfo:nil];
}
{
"api_version" = 2;
appkey = 1111;
"channel_id" = 2222;
deviceid = "";
imei =;
imsi =;
method = "";
nonce = "";
pixel = 640x960;
timestamp =;
ua = "";
}
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。