Skip to content

Commit

Permalink
change the sign timestamp key and delegate module
Browse files Browse the repository at this point in the history
  • Loading branch information
李杰 committed Sep 26, 2017
1 parent c1b4885 commit db942bc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion JJNetwork.podspec
Expand Up @@ -16,7 +16,7 @@ Pod::Spec.new do |s|
#

s.name = "JJNetwork"
s.version = "0.0.5"
s.version = "0.0.6"
s.summary = "JJNetwork."

# This description is used to generate tags and improve search results.
Expand Down
23 changes: 15 additions & 8 deletions JJNetwork/Source/APIService/APIService.m
Expand Up @@ -39,13 +39,11 @@ @implementation APIService
#pragma mark - Register APIModule

+ (void)registerDomainIP:(id<APIDominIPModule>)module{
NSDictionary* dic = [module domainIPData];
[APIServiceManager share].domainIPs = dic;
[APIServiceManager share].domainIPs = module;
}

+ (void)registerHttpHeadField:(id<APIHttpHeadModule>)module{
NSDictionary* dic = [module customerHttpHead];
[APIServiceManager share].httpHeadField = dic;
[APIServiceManager share].httpHeadField = module;
}


Expand Down Expand Up @@ -159,7 +157,12 @@ - (BOOL)checkRequestValidity:(APIRequest<RequestProtocol>*)request{
@return New URL
*/
- (NSString*)replaceDomainIPFromURL:(NSString*)url{
NSDictionary* ips = [APIServiceManager share].domainIPs;

if (![[APIServiceManager share].domainIPs respondsToSelector:@selector(domainIPData)]) {
return url;
}

NSDictionary* ips = [[APIServiceManager share].domainIPs domainIPData];
if (ips.count == 0) {
return url;
}
Expand All @@ -177,7 +180,10 @@ - (NSString*)replaceDomainIPFromURL:(NSString*)url{
@param request NSMutableURLRequest
*/
- (void)addHttpHeadFieldFromRequest:(NSMutableURLRequest**)request{
NSDictionary* heads = [APIServiceManager share].httpHeadField;
if (![[APIServiceManager share].httpHeadField respondsToSelector:@selector(customerHttpHead)]) {
return;
}
NSDictionary* heads = [[APIServiceManager share].httpHeadField customerHttpHead];
for (NSString* key in heads) {
[*request setValue:heads[key] forHTTPHeaderField:key];
}
Expand Down Expand Up @@ -215,11 +221,12 @@ - (NSDictionary*)signParameterWithKey:(NSDictionary *)para key:(NSString*)key{

//MD5 the all value and contact the timeStamp,
//The sign will change every seconds

[mString appendFormat:@"%d",(int)[[NSDate date] timeIntervalSince1970]];
NSInteger timestamp = (int)[[NSDate date] timeIntervalSince1970];
[mString appendFormat:@"%d",timestamp];
NSString* sign = [[NSString stringWithFormat:@"%@%@",mString,key] md5];

dic[@"sign"] = sign;
dic[@"timestamp"] = @(timestamp);
return dic;
}

Expand Down
5 changes: 3 additions & 2 deletions JJNetwork/Source/APIService/APIServiceManager.h
Expand Up @@ -7,13 +7,14 @@
//

#import <Foundation/Foundation.h>
#import "APIModule.h"

@interface APIServiceManager : NSObject

+ (instancetype)share;

@property(nonatomic,readwrite,strong)NSDictionary* domainIPs;
@property(nonatomic,readwrite,weak)id<APIDominIPModule> domainIPs;

@property(nonatomic,readwrite,strong)NSDictionary* httpHeadField;
@property(nonatomic,readwrite,weak)id<APIHttpHeadModule> httpHeadField;

@end
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -3,7 +3,7 @@
[![Build Status](https://travis-ci.org/jezzmemo/JJNetwork.svg?branch=master)](https://travis-ci.org/jezzmemo/JJNetwork.svg?branch=master)
[![Pod License](http://img.shields.io/cocoapods/l/JJNetwork.svg?style=flat)](https://www.apache.org/licenses/LICENSE-2.0.html)

AFNetworking-based network library, with delegate to process network response, integrate more business functions and optimize network performance,[Chinese document](https://github.com/jezzmemo/JJNetwork/blob/master/EXPLAIN.md)
AFNetworking-based network library, with delegate to process network response, integrate more business and optimize network performance,[Chinese document](https://github.com/jezzmemo/JJNetwork/blob/master/EXPLAIN.md)

## Features

Expand Down

0 comments on commit db942bc

Please sign in to comment.