//
//  NetworkPublicParams.m
//  Open
//
//  Created by 雷俊博 on 2020/11/2.
//  Copyright © 2020 黄江涛 . All rights reserved.
//

#import "NetworkPublicParams.h"
#import "NSString+Timestamp.h"

@implementation NetworkPublicParams

+ (NSMutableDictionary *)getBCPublicParams
{
    
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    
    
    NSString *deviceId = [IPTool getIdentifier];//设备 id
    NSString *getMacAddress = [NSString stringWithFormat:@"%ld",(long)[getPeopleID PeopleID]];
    getMacAddress = [EnercryTool encryptUseDES:getMacAddress key:DESKEY];
    NSString *deviceName = [[UIDevice currentDevice] model];
    NSString *deviceVersion = [[UIDevice currentDevice] localizedModel];
    NSString *deviceType = [NSString stringWithFormat:@"%@%@",deviceName,deviceVersion];
    NSString *systemType = [[UIDevice currentDevice] systemName];
    NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    NSString *clientIp = [IPTool getIPAddress:YES];
    NSString *locationCoordinate = [UserDefault objectForKey:@"locationCoordinate"];
    
    NSArray  *locationArray = nil;
    if (locationCoordinate) {
       locationArray =  [locationCoordinate componentsSeparatedByString:@","];
    }

    NSString *clientLng = locationArray ?locationArray[0] :@"121.48";
    NSString *clientLat = locationArray ?locationArray[1] :@"31.22";
    
    NSDictionary* dic = @{
        @"deviceId": deviceId,
        @"deviceName": deviceType,
        @"systemType": systemType,
        @"version": app_Version,
        @"clientIp": clientIp,
        @"clientLng": clientLng,
        @"clientLat": clientLat,
        @"clientMac": getMacAddress,
        @"timestamp":[NSString getNowTimeTimestamp3],
        @"randomStr":[self getRandomStr]
    };
    
    NSMutableDictionary *paramsDic = [NSMutableDictionary dictionaryWithDictionary:dic];
    
    return paramsDic;
}

+(NSString *)getRandomStr
{
    char data[10];
     
    for (int x=0;x < 10;data[x++] = (char)('A' + (arc4random_uniform(26))));
     
    NSString *randomStr = [[NSString alloc] initWithBytes:data length:10 encoding:NSUTF8StringEncoding];


    NSString *string = [NSString stringWithFormat:@"%@",randomStr];




    return string;
     
}

@end
