//
//  weatherNetModel.m
//  socialSecurity
//
//  Created by 看看智能 on 2017/5/4.
//  Copyright © 2017年 黄江涛 . All rights reserved.
//

#import "weatherNetModel.h"
#define NSUSERDEFAULT(safe,jinweidu)  [[NSUserDefaults standardUserDefaults] setObject:safe forKey:jinweidu];
#define NSUSERSYS [[NSUserDefaults standardUserDefaults] synchronize];

#define USEJINANDWEI(SAFE)  [[NSUserDefaults standardUserDefaults]objectForKey:SAFE]
@implementation weatherNetModel
+(id)JDInterHandle:(void(^)(NewMessage*, NSError *))complete{
    
    NSString * pathNew_1 =@"http://106.14.200.109:8081/jd/url";
    NSString * pathNew1 =  [pathNew_1 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSDictionary *dictNew =@{
                             @"loginId":@([getPeopleID PeopleID]),
                             @"telephone":[getPeopleID PeopleIphoneNmber],
                             @"terminal":@2
                             
                             };
    NSLog(@"dictNew:%@",dictNew);
    return [self  POST:pathNew1 parameters:dictNew completionHandler:^(id responseObj, NSError *error) {
        complete( [NewMessage mj_objectWithKeyValues:responseObj],error);
        if (error) {
            NSLog(@"打印错误:%@",error);
        }
    }];
    
    
}







+(id)weather:(NSString *)telephoneNo andCity:(NSString *)city Handle:(void (^)(weather_2 *, NSError *))complete
{

    
    NSString *password = @"b5221badabadc8963c17e16ecd245e90";
    NSString *host = @"http://coapi.moji.com/whapi/json/lbsweather";
    NSString *method = @"GET";
    NSString *jin = USEJINANDWEI(@"jinDu");
     NSString *wei = USEJINANDWEI(@"WeiDu");
    AppDelegate *delegate=(AppDelegate*)[[UIApplication sharedApplication]delegate];
    

    if ((![delegate.jin isEqualToString:@""] ) ) {
        if (![jin isEqualToString:delegate.jin] && ![jin isEqualToString:@""] ) {
            NSUSERDEFAULT(delegate.jin,@"jinDu")
            NSUSERDEFAULT(delegate.wei, @"WeiDu")
            NSUSERSYS
        }
    }else{
        return nil;
    }
    
    
    
    NSString *masd = [MyMD5 md5:[NSString stringWithFormat:@"%@0%@%@",password,jin,wei]];
    
    
    NSString *bod = [NSString stringWithFormat:@"timestamp=0&token=e75c5ccbd6755505ca8a44a5cecd2e80&key=%@&lat=%@&lon=%@",masd,jin,wei];
    NSString *url = [NSString stringWithFormat:@"%@?%@",host,bod];
    NSLog(@"%@",url);
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString: url]  cachePolicy:NSURLRequestReloadIgnoringLocalCacheData  timeoutInterval:  5];
    request.HTTPMethod  =  method;

    NSURLSession *requestSession = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
    NSURLSessionDataTask *task = [requestSession dataTaskWithRequest:request
                                                   completionHandler:^(NSData * _Nullable body , NSURLResponse * _Nullable response, NSError * _Nullable error) {
                                                       
                                                       //雷俊博修改,nsdatas为nil时不能解析
                                                       NSDictionary *weatherDic = nil;
                                                       if (body) {
                                                           weatherDic = [NSJSONSerialization JSONObjectWithData:body options:NSJSONReadingMutableLeaves error:&error];
                                                       }
                                                       
                                                               complete([weather_2 mj_objectWithKeyValues:weatherDic],nil);
 
                                                   }];
    
    [task resume];
 return nil;

}
+(id)findJobInfoLoginID:(NSInteger)logind handle:(void(^)(verifyAdressModel*, NSError *))complete{
    
    
    NSString * pathNew_1 =@"http://demand.weface.com.cn/wuba/find";
    NSString * pathNew1 =  [pathNew_1 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSDictionary *dictNew =@{
                             @"loginId":@([getPeopleID PeopleID])
                             };
    NSLog(@"dictNew:%@",dictNew);
    return [self  POST:pathNew1 parameters:dictNew completionHandler:^(id responseObj, NSError *error) {
        complete( [verifyAdressModel mj_objectWithKeyValues:responseObj],error);
        if (error) {
            NSLog(@"打印错误:%@",error);
        }
    }];
    
    
    
}


+(id)findJobInfoSaveloginId:(NSInteger)login
                 tellIphone:(NSString *)tellPhone
                      Birth:(NSString*)birth
                       name:(NSString*)name
                        sex:(NSInteger)sex
                   province:(NSString*)province
                     county:(NSString*)county
                       city:(NSString*)city
                    address:(NSString*)address
                     idcard:(NSString*)idcard
                     handle:(void(^)(verifyAdressModel*, NSError *))complete{
    
    if (![getPeopleID PeopleIphoneNmber]) {
        tellPhone = @"";
    }else{
        tellPhone = [EnercryTool encryptUseDES:[getPeopleID PeopleIphoneNmber] key:DESKEY];
    }
    if (!address) {
        address = @"";
    }
    if (!idcard) {
        idcard = @"";
    }else{
        [EnercryTool A:idcard];
        
    }
    if ([birth isEqualToString:@""]) {
        birth  = @"";
    }else{
        birth =[JobUtil onlyBirthDai:birth];
    }
       NSString * pathNew_1 =@"http://106.14.200.109:8081/wuba/save";


    NSString * pathNew1 =  [pathNew_1 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    NSDictionary *dictNew =@{
                             @"loginId":@([getPeopleID PeopleID]),
                             @"phone":tellPhone,
                             @"birth":birth,
                             @"name":name,
                             @"sex":@(sex),
                             @"province":province,
                             @"county":county,
                             @"city":city,
                             @"address":address,
                             @"idcard":idcard,
                             @"terminal":@2,
                             @"version":@50
                             };
    NSLog(@"dictNew:%@",dictNew);
    return [self  POST:pathNew1 parameters:dictNew completionHandler:^(id responseObj, NSError *error) {
        complete( [verifyAdressModel mj_objectWithKeyValues:responseObj],error);

    }];

    
    
    
    
    
    
    
}







@end
