Created
May 31, 2016 08:43
-
-
Save InstaRobot/14ecbf64fc56aca3b1fff122c7d0c5bd to your computer and use it in GitHub Desktop.
sig sign for POST methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // SignRequest.h | |
| // CryptClassPro | |
| // | |
| // Created by VITALIY PODOLSKIY on 01/08/15. | |
| // Copyright © 2015 VITALIY PODOLSKIY. All rights reserved. | |
| // | |
| #import <Foundation/Foundation.h> | |
| @interface SignRequest : NSObject | |
| + (SignRequest *)sharedRequest; | |
| - (NSString *)signRequest:(NSDictionary *)params; | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // SignRequest.m | |
| // CryptClassPro | |
| // | |
| // Created by VITALIY PODOLSKIY on 01/08/15. | |
| // Copyright © 2015 VITALIY PODOLSKIY. All rights reserved. | |
| // | |
| #import "SignRequest.h" | |
| #import "NSString+SHA256HMAC.h" | |
| @implementation SignRequest | |
| + (SignRequest *)sharedRequest { | |
| static SignRequest *_sharedRequest = nil; | |
| static dispatch_once_t onceToken; | |
| dispatch_once(&onceToken, ^{ | |
| _sharedRequest = [[SignRequest alloc] init]; | |
| }); | |
| return _sharedRequest; | |
| } // sharedRequest | |
| - (NSString *)signRequest:(NSDictionary *)params { | |
| NSDictionary *signDictionary = params; | |
| NSMutableString *sigString = [[NSMutableString alloc] init]; | |
| // add endpoint | |
| NSString *endpoint = [signDictionary valueForKey:@"endpoint"]; | |
| if (endpoint) { | |
| [sigString appendString:endpoint]; | |
| } | |
| //add access_token | |
| NSString *access_token = [signDictionary valueForKey:@"access_token"]; | |
| if (access_token) { | |
| [sigString appendString:[NSString stringWithFormat:@"|access_token=%@", access_token]]; | |
| } | |
| // add action | |
| NSString *action = [signDictionary valueForKey:@"action"]; | |
| if (action) { | |
| [sigString appendString:[NSString stringWithFormat:@"|action=%@", action]]; | |
| } | |
| // add count | |
| NSString *count = [signDictionary valueForKey:@"count"]; | |
| if (count) { | |
| [sigString appendString:[NSString stringWithFormat:@"|count=%@", count]]; | |
| } | |
| // add distance | |
| NSString *distance = [signDictionary valueForKey:@"distance"]; | |
| if (distance) { | |
| [sigString appendString:[NSString stringWithFormat:@"|distance=%@", distance]]; | |
| } | |
| // add facebook_places_id | |
| NSString *facebook_places_id = [signDictionary valueForKey:@"facebook_places_id"]; | |
| if (facebook_places_id) { | |
| [sigString appendString:[NSString stringWithFormat:@"|facebook_places_id=%@", facebook_places_id]]; | |
| } | |
| // add foursquare_id | |
| NSString *foursquare_id = [signDictionary valueForKey:@"foursquare_id"]; | |
| if (foursquare_id) { | |
| [sigString appendString:[NSString stringWithFormat:@"|foursquare_id=%@", foursquare_id]]; | |
| } | |
| // add foursquare_v2_id | |
| NSString *foursquare_v2_id = [signDictionary valueForKey:@"foursquare_v2_id"]; | |
| if (foursquare_v2_id) { | |
| [sigString appendString:[NSString stringWithFormat:@"|foursquare_v2_id=%@", foursquare_v2_id]]; | |
| } | |
| // add lat | |
| NSString *lat = [signDictionary valueForKey:@"lat"]; | |
| if (lat) { | |
| [sigString appendString:[NSString stringWithFormat:@"|lat=%@", lat]]; | |
| } | |
| // add lng | |
| NSString *lng = [signDictionary valueForKey:@"lng"]; | |
| if (lng) { | |
| [sigString appendString:[NSString stringWithFormat:@"|lng=%@", lng]]; | |
| } | |
| // add max_id | |
| NSString *max_id = [signDictionary valueForKey:@"max_id"]; | |
| if (max_id) { | |
| [sigString appendString:[NSString stringWithFormat:@"|max_id=%@", max_id]]; | |
| } | |
| // add max_like_id | |
| NSString *max_like_id = [signDictionary valueForKey:@"max_like_id"]; | |
| if (max_like_id) { | |
| [sigString appendString:[NSString stringWithFormat:@"|max_like_id=%@", max_like_id]]; | |
| } | |
| // add max_tag_id | |
| NSString *max_tag_id = [signDictionary valueForKey:@"max_tag_id"]; | |
| if (max_tag_id) { | |
| [sigString appendString:[NSString stringWithFormat:@"|max_tag_id=%@", max_tag_id]]; | |
| } | |
| // add max_timestamp | |
| NSString *max_timestamp = [signDictionary valueForKey:@"max_timestamp"]; | |
| if (max_timestamp) { | |
| [sigString appendString:[NSString stringWithFormat:@"|max_timestamp=%@", max_timestamp]]; | |
| } | |
| // add min_id | |
| NSString *min_id = [signDictionary valueForKey:@"min_id"]; | |
| if (min_id) { | |
| [sigString appendString:[NSString stringWithFormat:@"|min_id=%@", min_id]]; | |
| } | |
| // add min_tag_id | |
| NSString *min_tag_id = [signDictionary valueForKey:@"min_tag_id"]; | |
| if (min_tag_id) { | |
| [sigString appendString:[NSString stringWithFormat:@"|min_tag_id=%@", min_tag_id]]; | |
| } | |
| // add min_timestamp | |
| NSString *min_timestamp = [signDictionary valueForKey:@"min_timestamp"]; | |
| if (min_timestamp) { | |
| [sigString appendString:[NSString stringWithFormat:@"|min_timestamp=%@", min_timestamp]]; | |
| } | |
| // add q | |
| NSString *q = [signDictionary valueForKey:@"q"]; | |
| if (q) { | |
| [sigString appendString:[NSString stringWithFormat:@"|q=%@", q]]; | |
| } | |
| NSString *sec = @"3dde97c7a03d47eba2bbd521b1cd36a2"; | |
| NSString *fuckStr = [sigString SHA256HMACWithKey:sec]; | |
| return fuckStr; | |
| } // signRequest | |
| @end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| NSDictionary* URLParameters = @{@"endpoint":@"/tags/fashion/media/recent", | |
| @"access_token":@"364765806.9b6a283.348582a9cb2348c6a43a18211777f098", | |
| @"count": @"100", | |
| }; | |
| NSLog(@"%@", [[SignRequest sharedRequest] signRequest:URLParameters]); | |
| // Данный класс возвращает SIG-подпись в виде строки!!! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment