|
|
@@ -6,7 +6,7 @@
|
|
|
// Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
|
|
|
//
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
#import "ApexMobileNetwork.h"
|
|
|
@@ -27,7 +27,7 @@
|
|
|
return RESULT_NET_NOTAVAILABLE;
|
|
|
|
|
|
ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
|
|
|
-
|
|
|
+
|
|
|
|
|
|
NSMutableDictionary * params = [[NSMutableDictionary alloc] init];
|
|
|
[params setValue:user forKey:@"user"];
|
|
|
@@ -37,11 +37,11 @@
|
|
|
[params setValue:@"handset_search" forKey:@"action"];
|
|
|
[params setValue:appDelegate.sessionid forKey:@"sessionid"];
|
|
|
NSData* json=[ApexMobileNetwork get_json:URL_RETRIEVE_PASS parameters:params];
|
|
|
-
|
|
|
+
|
|
|
|
|
|
if (json==nil)
|
|
|
{
|
|
|
- DebugLog(@"json is wrong");
|
|
|
+ DebugLog(@"json is wrong");
|
|
|
return RESULT_NET_ERROR;
|
|
|
}
|
|
|
|
|
|
@@ -52,7 +52,7 @@
|
|
|
int result = [[jsobj valueForKey:@"result"] intValue];
|
|
|
if(result!=AP_USER_AUTH)
|
|
|
{
|
|
|
- DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
|
|
|
+ DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
|
|
|
return RESULT_FALSE;
|
|
|
|
|
|
}
|
|
|
@@ -60,8 +60,8 @@
|
|
|
|
|
|
}
|
|
|
return RESULT_NET_ERROR;
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
+(int) RetrievePassword : (NSString*) user email:(NSString*) email
|
|
|
{
|
|
|
@@ -76,7 +76,7 @@
|
|
|
NSData* json=[ApexMobileNetwork get_json:URL_RETRIEVE_PASS parameters:params];
|
|
|
if (json==nil)
|
|
|
{
|
|
|
- DebugLog(@"json is wrong");
|
|
|
+ DebugLog(@"json is wrong");
|
|
|
return RESULT_NET_ERROR;
|
|
|
}
|
|
|
|
|
|
@@ -87,20 +87,20 @@
|
|
|
int result = [[jsobj valueForKey:@"result"] intValue];
|
|
|
if(result!=AP_USER_AUTH)
|
|
|
{
|
|
|
- DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
|
|
|
+ DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
|
|
|
return RESULT_FALSE;
|
|
|
|
|
|
}
|
|
|
return RESULT_TRUE;
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
return RESULT_NET_ERROR;
|
|
|
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
+(int)parse_authinfo : (NSData *) json user:(NSString*) user password:(NSString*) password
|
|
|
{
|
|
|
- DebugLog(@"parse_authinfo");
|
|
|
+ DebugLog(@"parse_authinfo");
|
|
|
NSError *error=nil;
|
|
|
|
|
|
sqlite3 *db =[ApexMobileDB get_db];
|
|
|
@@ -114,14 +114,14 @@
|
|
|
int result = [[jsobj valueForKey:@"result"] intValue];
|
|
|
if(result!=AP_USER_AUTH)
|
|
|
{
|
|
|
- DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
|
|
|
+ DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
|
|
|
return RESULT_FALSE;
|
|
|
|
|
|
}
|
|
|
NSDictionary* objheader = [jsobj objectForKey:@"header"];
|
|
|
ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
|
|
|
NSString* required_ver=[objheader objectForKey:@"client_ver"] ;
|
|
|
- DebugLog(@"required_ver=%@ ",required_ver);
|
|
|
+ DebugLog(@"required_ver=%@ ",required_ver);
|
|
|
NSDictionary* infoDict =[[NSBundle mainBundle] infoDictionary];
|
|
|
NSString* versionNum =[infoDict objectForKey:@"CFBundleVersion"];
|
|
|
versionNum = [NSString stringWithFormat:@"A%@",versionNum];
|
|
|
@@ -132,7 +132,7 @@
|
|
|
appDelegate.sessionid = [objheader valueForKey:@"sessionid"];
|
|
|
appDelegate.user = user;
|
|
|
appDelegate.password = password;
|
|
|
- DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
|
|
|
+ DebugLog(@"sessionid=%@ ",appDelegate.sessionid);
|
|
|
if ([[objheader valueForKey:@"update"] boolValue]==false)
|
|
|
{
|
|
|
// no update on the server;
|
|
|
@@ -297,7 +297,7 @@
|
|
|
}
|
|
|
+(DetailContent*) get_detailcontent: (NSMutableDictionary *) params
|
|
|
{
|
|
|
- DebugLog(@"get_detailcontent");
|
|
|
+ DebugLog(@"get_detailcontent");
|
|
|
DetailContent * detailContent = [[DetailContent alloc] init];
|
|
|
NSMutableArray* segments = [[NSMutableArray alloc] init];
|
|
|
detailContent.segments = segments;
|
|
|
@@ -307,12 +307,12 @@
|
|
|
return detailContent;
|
|
|
}
|
|
|
ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
|
|
|
-// [params setValue:@"handset_search" forKey:@"action"];
|
|
|
+ // [params setValue:@"handset_search" forKey:@"action"];
|
|
|
[params setValue:appDelegate.sessionid forKey:@"sessionid"];
|
|
|
NSData* json=[ApexMobileNetwork get_json:URL_REQUEST_RECORDS parameters:params];
|
|
|
if (json==nil)
|
|
|
{
|
|
|
- DebugLog(@"json is wrong");
|
|
|
+ DebugLog(@"json is wrong");
|
|
|
detailContent.result_code = RESULT_NET_ERROR;
|
|
|
return detailContent;
|
|
|
}
|
|
|
@@ -324,7 +324,7 @@
|
|
|
int result = [[jsobj valueForKey:@"result"] intValue];
|
|
|
if(result!=AP_USER_AUTH)
|
|
|
{
|
|
|
- DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
|
|
|
+ DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
|
|
|
detailContent.result_code = result;
|
|
|
return detailContent;
|
|
|
|
|
|
@@ -337,7 +337,7 @@
|
|
|
|
|
|
return detailContent;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
for(int i=0;i<count;i++)
|
|
|
{
|
|
|
|
|
|
@@ -361,8 +361,8 @@
|
|
|
|
|
|
// NSDictionary* objrecords = [jsobj objectForKey:@"records"];
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
return detailContent;
|
|
|
|
|
|
}
|
|
|
@@ -372,7 +372,7 @@
|
|
|
+(PageData*) get_pagedata: (NSMutableDictionary *) params
|
|
|
{
|
|
|
|
|
|
- DebugLog(@"get_pagedata");
|
|
|
+ DebugLog(@"get_pagedata");
|
|
|
if(![ApexMobileNetwork IsNetworkAvailable])
|
|
|
return nil;
|
|
|
ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
|
|
|
@@ -381,7 +381,7 @@
|
|
|
NSData* json=[ApexMobileNetwork get_json:URL_REQUEST_RECORDS parameters:params];
|
|
|
if (json==nil)
|
|
|
{
|
|
|
- DebugLog(@"json is wrong");
|
|
|
+ DebugLog(@"json is wrong");
|
|
|
return nil;
|
|
|
}
|
|
|
|
|
|
@@ -392,7 +392,7 @@
|
|
|
int result = [[jsobj valueForKey:@"result"] intValue];
|
|
|
if(result!=AP_USER_AUTH)
|
|
|
{
|
|
|
- DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
|
|
|
+ DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
|
|
|
return nil;
|
|
|
|
|
|
}
|
|
|
@@ -408,7 +408,7 @@
|
|
|
}
|
|
|
+(int) get_recordcount: (NSMutableDictionary *) params// delegate:(id < NSURLConnectionDelegate >)delegate
|
|
|
{
|
|
|
- DebugLog(@"get_recordcount");
|
|
|
+ DebugLog(@"get_recordcount");
|
|
|
if(![ApexMobileNetwork IsNetworkAvailable])
|
|
|
return -1;
|
|
|
ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
|
|
|
@@ -418,7 +418,7 @@
|
|
|
NSData* json=[ApexMobileNetwork get_json:URL_REQUEST_COUNT parameters:params];
|
|
|
if (json==nil)
|
|
|
{
|
|
|
- DebugLog(@"json is wrong");
|
|
|
+ DebugLog(@"json is wrong");
|
|
|
return RESULT_NET_ERROR;
|
|
|
}
|
|
|
|
|
|
@@ -429,7 +429,7 @@
|
|
|
int result = [[jsobj valueForKey:@"result"] intValue];
|
|
|
if(result!=AP_USER_AUTH)
|
|
|
{
|
|
|
- DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
|
|
|
+ DebugLog(@"USER NOT AUTHORIZED CODE=%d ",result);
|
|
|
return RESULT_FALSE;
|
|
|
|
|
|
}
|
|
|
@@ -456,6 +456,141 @@
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
++(void)post_without_return : (NSString*) url parameters:(NSMutableDictionary *) params //delegate:(id < NSURLConnectionDelegate >)delegate
|
|
|
+{
|
|
|
+ ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
|
|
|
+ //分界线的标识符
|
|
|
+ NSString *TWITTERFON_FORM_BOUNDARY = @"AaB03x";
|
|
|
+ //根据url初始化request
|
|
|
+ NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]
|
|
|
+ cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
|
|
|
+ timeoutInterval:30];
|
|
|
+ //分界线 --AaB03x
|
|
|
+ NSString *MPboundary=[[NSString alloc]initWithFormat:@"--%@",TWITTERFON_FORM_BOUNDARY];
|
|
|
+ //结束符 AaB03x--
|
|
|
+ NSString *endMPboundary=[[NSString alloc]initWithFormat:@"%@--",MPboundary];
|
|
|
+ //要上传的图片
|
|
|
+ // UIImage *image=[params objectForKey:@"pic"];
|
|
|
+ //得到图片的data
|
|
|
+ // NSData* data = UIImagePNGRepresentation(image);
|
|
|
+ //http body的字符串
|
|
|
+ NSMutableString *body=[[NSMutableString alloc]init];
|
|
|
+
|
|
|
+ // NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
|
|
|
+ // [params setValue:@"handset_login" forKey:@"action"];
|
|
|
+ // [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
|
|
|
+
|
|
|
+ [params setValue:appDelegate.sessionid forKey:@"sessionid"];
|
|
|
+ // [params setValue:password forKey:@"password"];
|
|
|
+ // [params setValue:[NSString stringWithFormat:@"%d",ver] forKey:@"auth_ver"];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // [headers setValue:headQuerlString forKey:@"param"];
|
|
|
+
|
|
|
+ //参数的集合的所有key的集合
|
|
|
+ NSArray *keys= [params allKeys];
|
|
|
+ DebugLog(@"================parms==================");
|
|
|
+ //遍历keys
|
|
|
+ for(int i=0;i<[keys count];i++)
|
|
|
+ {
|
|
|
+ //得到当前key
|
|
|
+ NSString *key=[keys objectAtIndex:i];
|
|
|
+ //如果key不是pic,说明value是字符类型,比如name:Boris
|
|
|
+ if(![key isEqualToString:@"pic"])
|
|
|
+ {
|
|
|
+ //添加分界线,换行
|
|
|
+ [body appendFormat:@"%@\r\n",MPboundary];
|
|
|
+ //添加字段名称,换2行
|
|
|
+ [body appendFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n",key];
|
|
|
+ //添加字段的值
|
|
|
+ [body appendFormat:@"%@\r\n",[params objectForKey:key]];
|
|
|
+ DebugLog(@"parameter: key=%@ value=%@",key,[params objectForKey:key]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ DebugLog(@"================parms==================");
|
|
|
+ ////添加分界线,换行
|
|
|
+ [body appendFormat:@"%@\r\n",MPboundary];
|
|
|
+ //声明pic字段,文件名为boris.png
|
|
|
+ [body appendFormat:@"Content-Disposition: form-data; name=\"pic\"; filename=\"boris.png\"\r\n"];
|
|
|
+ //声明上传文件的格式
|
|
|
+ [body appendFormat:@"Content-Type: image/png\r\n\r\n"];
|
|
|
+
|
|
|
+ //声明结束符:--AaB03x--
|
|
|
+ NSString *end=[[NSString alloc]initWithFormat:@"\r\n%@",endMPboundary];
|
|
|
+ //声明myRequestData,用来放入http body
|
|
|
+ NSMutableData *myRequestData=[NSMutableData data];
|
|
|
+ //将body字符串转化为UTF8格式的二进制
|
|
|
+ [myRequestData appendData:[body dataUsingEncoding:NSUTF8StringEncoding]];
|
|
|
+ //将image的data加入
|
|
|
+ // [myRequestData appendData:data];
|
|
|
+ //加入结束符--AaB03x--
|
|
|
+ [myRequestData appendData:[end dataUsingEncoding:NSUTF8StringEncoding]];
|
|
|
+
|
|
|
+ //设置HTTPHeader中Content-Type的值
|
|
|
+ NSString *content=[[NSString alloc]initWithFormat:@"multipart/form-data; boundary=%@",TWITTERFON_FORM_BOUNDARY];
|
|
|
+ //设置HTTPHeader
|
|
|
+ [request setValue:content forHTTPHeaderField:@"Content-Type"];
|
|
|
+ //设置Content-Length
|
|
|
+ [request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[myRequestData length]] forHTTPHeaderField:@"Content-Length"];
|
|
|
+ //设置http body
|
|
|
+ [request setHTTPBody:myRequestData];
|
|
|
+ //http method
|
|
|
+ [request setHTTPMethod:@"POST"];
|
|
|
+
|
|
|
+
|
|
|
+ NSHTTPURLResponse* urlResponse = nil;
|
|
|
+
|
|
|
+ NSError *error = [[NSError alloc] init];
|
|
|
+
|
|
|
+ [NSURLConnection sendAsynchronousRequest:request queue:nil completionHandler:^(NSURLResponse *response,NSData *data,NSError *error){}];
|
|
|
+// NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:nil];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
++(NSData*)get_marketnews : (NSString*) id limit: (int) limit
|
|
|
+{
|
|
|
+ NSString* ret = nil;
|
|
|
+
|
|
|
+ NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
|
|
|
+ [params setValue:@"Market News" forKey:@"module_name"];
|
|
|
+ [params setValue:@"search" forKey:@"action_type"];
|
|
|
+ [params setValue:id forKey:@"id"];
|
|
|
+ [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
|
|
|
+
|
|
|
+ NSData* json=[ApexMobileNetwork get_json:URL_ANNOUNCEMENTS parameters:params];
|
|
|
+ if (json==nil)
|
|
|
+ {
|
|
|
+ DebugLog(@"json is wrong");
|
|
|
+ return nil;
|
|
|
+ }
|
|
|
+ return json;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
++(NSData*)get_announcements : (NSString*) id limit: (int) limit
|
|
|
+{
|
|
|
+ NSString* ret = nil;
|
|
|
+
|
|
|
+ NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
|
|
|
+ [params setValue:@"Announcements" forKey:@"module_name"];
|
|
|
+[params setValue:@"search" forKey:@"action_type"];
|
|
|
+ [params setValue:id forKey:@"id"];
|
|
|
+ [params setValue:[NSString stringWithFormat:@"%d",limit ] forKey:@"limit"];
|
|
|
+
|
|
|
+ NSData* json=[ApexMobileNetwork get_json:URL_ANNOUNCEMENTS parameters:params];
|
|
|
+ if (json==nil)
|
|
|
+ {
|
|
|
+ DebugLog(@"json is wrong");
|
|
|
+ return nil;
|
|
|
+ }
|
|
|
+ return json;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+(NSData*)get_json : (NSString*) url parameters:(NSMutableDictionary *) params //delegate:(id < NSURLConnectionDelegate >)delegate
|
|
|
{
|
|
|
ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
|
|
|
@@ -490,7 +625,7 @@
|
|
|
|
|
|
//参数的集合的所有key的集合
|
|
|
NSArray *keys= [params allKeys];
|
|
|
- DebugLog(@"================parms==================");
|
|
|
+ DebugLog(@"================parms==================");
|
|
|
//遍历keys
|
|
|
for(int i=0;i<[keys count];i++)
|
|
|
{
|
|
|
@@ -505,10 +640,10 @@
|
|
|
[body appendFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n",key];
|
|
|
//添加字段的值
|
|
|
[body appendFormat:@"%@\r\n",[params objectForKey:key]];
|
|
|
- DebugLog(@"parameter: key=%@ value=%@",key,[params objectForKey:key]);
|
|
|
+ DebugLog(@"parameter: key=%@ value=%@",key,[params objectForKey:key]);
|
|
|
}
|
|
|
}
|
|
|
- DebugLog(@"================parms==================");
|
|
|
+ DebugLog(@"================parms==================");
|
|
|
////添加分界线,换行
|
|
|
[body appendFormat:@"%@\r\n",MPboundary];
|
|
|
//声明pic字段,文件名为boris.png
|
|
|
@@ -545,36 +680,50 @@
|
|
|
|
|
|
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
|
|
|
|
|
|
- DebugLog(@"response: %@",[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode]);
|
|
|
+ DebugLog(@"response: %@",[NSHTTPURLResponse localizedStringForStatusCode:urlResponse.statusCode]);
|
|
|
|
|
|
if (responseData==nil) {
|
|
|
|
|
|
- DebugLog(@"move failed:%@", [error localizedDescription]);
|
|
|
+ DebugLog(@"move failed:%@", [error localizedDescription]);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
NSMutableString *result = [[NSMutableString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
|
|
|
|
|
|
- DebugLog(@"result: %@",result);
|
|
|
+ DebugLog(@"result: %@",result);
|
|
|
|
|
|
|
|
|
}
|
|
|
return responseData;
|
|
|
|
|
|
}
|
|
|
++(void)Logout
|
|
|
+{
|
|
|
+ if(![ApexMobileNetwork IsNetworkAvailable])
|
|
|
+ return ;//RESULT_NET_NOTAVAILABLE;
|
|
|
+ NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
|
|
|
+ ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
|
|
|
+ if(appDelegate.duid !=nil)
|
|
|
+ [params setValue:appDelegate.duid forKey:@"udid"];
|
|
|
+ [params setValue:@"handset_logout" forKey:@"action"];
|
|
|
|
|
|
+ [ApexMobileNetwork post_without_return :URL_UPDATE_AUTH parameters:params];
|
|
|
+}
|
|
|
+(int)Authorize : (NSString*) user password:(NSString*) password{
|
|
|
|
|
|
if(![ApexMobileNetwork IsNetworkAvailable])
|
|
|
return RESULT_NET_NOTAVAILABLE;
|
|
|
-// if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
|
|
|
-// return RESULT_NET_ERROR;
|
|
|
+ // if(![ApexMobileNetwork IsHostAvailable:URL_UPDATE_AUTH])
|
|
|
+ // return RESULT_NET_ERROR;
|
|
|
NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
|
|
|
long ver =[defaults integerForKey:[NSString stringWithFormat:@"%@_Auth_InfoVer",user]];
|
|
|
|
|
|
|
|
|
|
|
|
NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
|
|
|
+ ApexMobileAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
|
|
|
+ if(appDelegate.duid !=nil)
|
|
|
+ [params setValue:appDelegate.duid forKey:@"udid"];
|
|
|
[params setValue:@"handset_login" forKey:@"action"];
|
|
|
// [headers setValue:[NSString stringWithFormat:@"%d",dataLength] forKey:@"Content-Length"];
|
|
|
|
|
|
@@ -586,7 +735,7 @@
|
|
|
return RESULT_NET_ERROR;
|
|
|
|
|
|
int ret = [ApexMobileNetwork parse_authinfo:json user:user password:password];
|
|
|
- DebugLog(@"parse_authinfo return %d ",ret);
|
|
|
+ DebugLog(@"parse_authinfo return %d ",ret);
|
|
|
|
|
|
|
|
|
return ret;
|