add .gitignore

This commit is contained in:
JoyWayer
2023-12-27 20:38:37 +08:00
parent b106a628a5
commit f6343426d6
515 changed files with 104217 additions and 199 deletions

View File

@@ -0,0 +1,261 @@
//
// GatewayApi.m
// PublicFuncClass
//
// Created by an chen on 12-8-30.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
/*
*
*/
#import "SGGatewayApi.h"
#import "NSString+SBJSON.h"
#import "SBJSON.h"
#import "FuncPublic.h"
#import "SGGateway.h"
#import "SGDefineInfo.h"
#import "FuncPublic.h"
@implementation SGGatewayApi
@synthesize _mUrl;
@synthesize _mvReturn;
@synthesize _returnFunction;
@synthesize _act;
@synthesize receivedBufferData;//
@synthesize _objDo;
-(id)init
{
if((self=[super init]))
{
receivedBufferData = [[NSMutableData alloc]init];
//(**)
_objDo = [[NSMutableDictionary alloc]init];
_act = [[NSString alloc] initWithString:@""];
DelayerErro = NO;
OnceAlert=YES;
}
return self;
}
-(void)dealloc
{
NSLog(@"释放:%@",_act);
SG_RELEASE(receivedBufferData);
SG_RELEASE(_mUrl);
SG_RELEASE(_act);
SG_RELEASE(_objDo);
[super dealloc];
}
/*
*
*/
-(void)delayer
{
[_DelayerTimer invalidate];
[[FuncPublic SharedFuncPublic] StopActivityAnimation];
NSLog(@"通信失败:%@",_act);
if (OnceAlert) {
// OnceAlert=NO;
// [self performSelector:@selector(ComeBack) withObject:nil afterDelay:50.0f];
// UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"网络不可用"
// message:@"无法与服务器通讯请连接到移动数据网络或者WIFI"
// delegate:self
// cancelButtonTitle:@"确定"
// otherButtonTitles:nil, nil];
// [alert show];
// [alert release];
[FuncPublic ShowAlert:@"无法与服务器通讯请连接到移动数据网络或者WIFI" title:@"网络不可用" viewController:nil];
}
//[_mvReturn performSelector:_returnFunction withObject:nil];
DelayerErro = YES;
}
-(void)ComeBack
{
OnceAlert=YES;
}
/*
* :
*
* mv:
*
* returnFunc:
*
* obj_do: mv
*
* param_post:
*
* str: url
*
*/
-(void)gateway:(id)mv func:(SEL)returnFunc obj_post:(NSMutableDictionary*)obj_post obj_post:(NSMutableDictionary*)param_post STR:(NSString*)str HTTPMethod:(NSString*)_method{
/*
*
*/
if (![str isEqualToString:@"UpdateAPNSDevice.aspx"]) {
[[FuncPublic SharedFuncPublic] StartActivityAnimation:mv];
}
_DelayerTimer = [NSTimer scheduledTimerWithTimeInterval:GATEWAY_DELAYER target:self selector:@selector(delayer) userInfo:nil repeats:NO];
_mvReturn = mv;
_returnFunction = returnFunc;
_objDo = obj_post;
if( ![[param_post objectForKey:@"t"] isEqual:@""] )//
{
if( [param_post objectForKey:@"t"] == nil )
{
_act = str;
}
else
{
_act = [param_post objectForKey:@"t"];
}
}
_mUrl = [[NSString alloc] initWithString:[NSString stringWithFormat:@"%@%@",SERVER,str]];
/*
* code start
*/
if( [param_post objectForKey:@"code"] != nil )
{
NSArray *array = [param_post allKeys];//[[param_post allKeys]sortedArrayUsingSelector: @selector(compare:)];
NSString* post = @"";
for(int i = 0; i<[array count]; i++){
if( [[param_post objectForKey:[array objectAtIndex:i]] isEqualToString:@"nn"])
continue;
post = [post stringByAppendingString:[param_post objectForKey:[array objectAtIndex:i]]];
}
post = [post stringByAppendingFormat:@"WERTY#$&(HJKfghjWERTYUIFGJFGHadf2222"];
post = [FuncPublic md5:post];
[param_post setObject:post forKey:@"code"];
}
/*
* code end
*/
//post
NSData *postData = [self generateFormDataFromPostDictionary:param_post];//obj_postkey使&
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]]; //post
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setHTTPMethod:@"POST"]; //使
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];//
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];//
[request setHTTPBody:postData]; //
NSString* post_string = [[NSString alloc] initWithData:postData encoding:NSUTF8StringEncoding];//nsdataencoding
if( [_method isEqualToString:@"POST"] )
{
[request setURL:[NSURL URLWithString:_mUrl]];
}else if( [_method isEqualToString:@"POSTtwo"] )
{
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",SERVERTwo,str]]];
}else
{
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@?%@",_mUrl,post_string ]]]; //url
}
NSLog(@"%@",[NSString stringWithFormat:@"%@?%@",_mUrl,post_string ]);
NSURLConnection *conn = [NSURLConnection connectionWithRequest:request delegate:self]; //
if (conn) {
} else {
}
SG_RELEASE(post_string);
[param_post removeAllObjects];
SG_RELEASE(param_post);
}
- (void)connection:(NSURLConnection *)conn didReceiveResponse:(NSURLResponse *)res {
[receivedBufferData setLength:0];
}
- (void)connection:(NSURLConnection *)conn didReceiveData:(NSData *)receivedData {
[receivedBufferData appendData:receivedData]; //
}
- (void)connection:(NSURLConnection *)conn didFailWithError:(NSError *)error {
}
-(NSString *)HandelData:(NSString *)str_
{
NSString *string=nil;
//ValidateUserIDAndPassword.aspx UpdateAPNSDevice.aspx InsertBookComment.aspx
if ([_act isEqualToString:@"InsertSuggestInfo.aspx"]||[_act isEqualToString:@"UpdateAPNSDevice.aspx"]||[_act isEqualToString:@"InsertBookComment.aspx"]) {
string=[NSString stringWithFormat:@"{\"data\":[{\"result\":%@}]}",str_];
return string;
}
string=str_;
return string;
}
- (void)connectionDidFinishLoading:(NSURLConnection *)conn {
NSLog(@"apiReturnOk:%@",_act);
if( DelayerErro ) return;
[_DelayerTimer invalidate];
NSString* stra = [[NSString alloc] initWithData:receivedBufferData encoding:NSUTF8StringEncoding]; //
//
NSString* str = [[NSString alloc]initWithFormat:@"%@",[stra stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
SG_RELEASE(stra);
if ([str isEqualToString: @""] == YES) {
return;
}
if(1){
NSLog(@"[%@]",str);
}
NSString *handleStr=[self HandelData:str];
NSMutableDictionary * obj_return = [handleStr JSONValue];//使js
if( obj_return == nil )
{
[[FuncPublic SharedFuncPublic] StopActivityAnimation];//funcpublic
// [FuncPublic ShowAlert:@"Api错误!"];
// [FuncPublic ShowAlert:@"没有数据!"];
[FuncPublic ShowAlert:@"没有数据!" title:nil viewController:nil];
return;
}
NSLog(@"jsonDecode完成:%@",_act);
[_objDo setObject:obj_return forKey:@"apiReturnData"];//
NSLog(@"开始回调:%@",_act);
[_mvReturn performSelector:_returnFunction withObject:_objDo];// _objDo
SG_RELEASE(str);
NSLog(@"接口%@完成",_act);
[[FuncPublic SharedFuncPublic] StopActivityAnimation];
}
- (NSData*)generateFormDataFromPostDictionary:(NSDictionary*)dict
{
NSArray* keys = [dict allKeys];
NSMutableData* result = [NSMutableData data];
for (int i = 0; i < [keys count]; i++)
{
id value = [dict valueForKey: [keys objectAtIndex:i]];
if(i > 0){
[result appendData:[@"&" dataUsingEncoding:NSUTF8StringEncoding]];//NSASCIIStringEncoding
}
[result appendData:[[NSString stringWithFormat:@"%@" ,[keys objectAtIndex:i]] dataUsingEncoding:NSUTF8StringEncoding]];
[result appendData:[@"=" dataUsingEncoding:NSUTF8StringEncoding]];
if ([value isKindOfClass:[NSData class]])
{
[result appendData:value];
}
else {
[result appendData:DATA(value)];
}
}
return result;
}
@end