APAuthV2Info.m 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // APAuthV2Info.m
  3. // AliSDKDemo
  4. //
  5. // Created by 亦澄 on 16-8-12.
  6. // Copyright (c) 2016年 Alipay. All rights reserved.
  7. //
  8. #import "APAuthV2Info.h"
  9. @implementation APAuthV2Info
  10. - (NSString *)description
  11. {
  12. if (self.appID.length != 16||self.pid.length != 16) {
  13. return nil;
  14. }
  15. // NOTE: 增加不变部分数据
  16. NSMutableDictionary *tmpDict = [NSMutableDictionary new];
  17. [tmpDict addEntriesFromDictionary:@{@"app_id":_appID,
  18. @"pid":_pid,
  19. @"apiname":@"com.alipay.account.auth",
  20. @"method":@"alipay.open.auth.sdk.code.get",
  21. @"app_name":@"mc",
  22. @"biz_type":@"openservice",
  23. @"product_id":@"APP_FAST_LOGIN",
  24. @"scope":@"kuaijie",
  25. @"target_id":(_targetID?:@"20141225xxxx"),
  26. @"auth_type":(_authType?:@"AUTHACCOUNT")}];
  27. // NOTE: 排序,得出最终请求字串
  28. NSArray* sortedKeyArray = [[tmpDict allKeys] sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
  29. return [obj1 compare:obj2];
  30. }];
  31. NSMutableArray *tmpArray = [NSMutableArray new];
  32. for (NSString* key in sortedKeyArray) {
  33. NSString* orderItem = [self itemWithKey:key andValue:[tmpDict objectForKey:key]];
  34. if (orderItem.length > 0) {
  35. [tmpArray addObject:orderItem];
  36. }
  37. }
  38. return [tmpArray componentsJoinedByString:@"&"];
  39. }
  40. - (NSString*)itemWithKey:(NSString*)key andValue:(NSString*)value
  41. {
  42. if (key.length > 0 && value.length > 0) {
  43. return [NSString stringWithFormat:@"%@=%@", key, value];
  44. }
  45. return nil;
  46. }
  47. @end