Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

The introduction

This paper is to sort out the related problems and corresponding solutions of fans to blog: [Signature request parameters] request parameters sorting, splicing and encryption (implemented recursively) according to ASCII code from small to large.

The demo address: https://download.csdn.net/download/u011018979/15483107

I, signature array ASCII sorting optimization

1.1 Optimize the sorting of array elements

Record a bug feedback from users, and modify the content as shown in the figure below:

For arrays, my rule is that [] represents arrays, and array elements are recursively concatenated with separated [,,,]. If you think the sorting of the ASCII array is wrong, you can print the sorted string and see how the sorting differs from the concatenation rules on your server side. Change the rules to be consistent with the background array sorting rules.

/** - Handles the case where the Value of the key is an array */
+ (NSString *)sortedDictionaryArr:(NSArray *)arr {
    
    
    NSMutableString *contentString =[NSMutableString string];

    #pragmaMark-******** Optional

 arr =    [self sortedArrBykey:sortedArray];//

    for ( id obj in arr ) {
        
        
        
            NSString * tmp = @ "";

            if(contentString.length<1 || [contentString isEqualToString:@ ""]) {//
            
            
            
        }
        else{
            [contentString appendString:@ ","];
            
            
        }
        
        
        
        
              
                         if( [obj isKindOfClass:NSDictionary.class]){
                             
                    
                    
                    tmp = [self sortedDictionary:obj];
                             
                             
                    
                             
                    
                    
                    
                }
        
                // Array is []
                
                else         if( [obj isKindOfClass:NSArray.class]){
                    
                    
                    tmp = [self sortedDictionaryArr:obj];
                    

                                tmp = [NSString stringWithFormat:@ % @ % @ % @ "".@ "{",tmp,@ "}"];

                    
                }
                else{
            
            tmp=   obj;
            

            
        }



        
        
        
        [contentString appendFormat:@ "% @",tmp];
        
        
        
    }
    
    
                        contentString = [NSString stringWithFormat:@ % @ % @ % @ "".@ "[",contentString,"@"]];
    

    

    return contentString;
    
    
    
}

Copy the code

Example: Edit the price request message of the goods in the store:

{
  "adjustStocks" : [
    {
      "nnewStockNum" : "0",
      "productId" : "1280072986512433152",
      "newStockNum" : "0",
      "oldStockNum" : "0",
      "storeId" : "25063",
      "productSkuId" : "1280072986516627456",
      "batchNo" : ""
    }
  ],
  "modifyPrices" : [
    {
      "tagId" : "25063",
      "productNewPrice" : "5",
      "productSkuId" : "1280072986516627456",
      "type" : "1",
      "productId" : "1280072986512433152",
      "productOldPrice" : "33"
    }
  ]
}
Copy the code

ASCII sort of the signature meta string

adjustStocks=[batchNo=&newStockNum=0&nnewStockNum=0&oldStockNum=0&productId=1280072986512433152&productSkuId=1280072986516627456&storeId=25063]&modifyPrices=[productId=1280072986512433152&productNewPrice=55&productOldPrice=5&productSkuId=1280072986516627456&tagId=25063&type=1]&appsecret=4f7b71
Copy the code

1.2 Sorting of new set elements:

My initial idea for sorting arrays is to group the elements by their class type, sort the subarrays if they are strings, and then regroup them into new arrays. And then we do ergodic recursive splicing

/** 1, new set element sort: For array sort, my initial idea is to group the elements by their class type. If the subarrays are strings, sort them and then regroup them into a new array. */ + (NSMutableArray *)sortedArrBykey:(NSArray *)array {// sort the array by class type //1 *arDistinct = [array valueForKeyPath:@"@distinctUnionOfObjects.class"]; / / / / can't get into the dictionary class type NSMutableArray * classArr = [NSMutableArray arrayWithArray: arDistinct]; NSMutableArray *strclassArr = [NSMutableArray array]; NSMutableArray *nostrclassArr = [NSMutableArray array]; for (NSObject* obj in array) { if([obj isKindOfClass:NSString.class]){ [strclassArr addObject:obj]; }else{ [nostrclassArr addObject:obj]; NSMutableArray* sortedArray = [NSMutableArray array]; strclassArr = [strclassArr sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2){ return [obj1 compare:obj2 options:NSNumericSearch]; }]; [sortedArray addObjectsFromArray:strclassArr]; [sortedArray addObjectsFromArray:nostrclassArr]; return sortedArray; }Copy the code

1.3 If the wechat payment parameter value is empty, it will not participate in the sorting scheme

Arguments that are empty can be removed from the dictionary before sorting.

Rule reason: signature only for important fields, the value can be null parameter can not participate

II. Other compile-related questions

2.1 Why did Xcode12 allow errors after I downloaded the demo: Library not found for lAXIndicatorView; How to solve it?

Reason: This is not found in the CocoaPods library AXIndicatorView. It’s the AXWebViewController library that depends on it

  • Solution: Update pod ‘AXWebViewController’.

Pod update AXWebViewController –verbose –repo-update

2, Pod update will update all libraries to get the latest version of the class library

Cocoapods usage article: https://blog.csdn.net/z929118967/article/details/103830017

exit0% ➜ retail git:(develop) qualify cat ~/bin/knpod#! /bin/sh

This command only installs newly added libraries, ignoring updated libraries

pod install --verbose --no-repo-update
# this command updates only the specified libraries, ignoring other libraries
#pod update library name --verbose --no-repo-update

exitThose who qualify can go onto universityCopy the code

see also

For more information and services, please check out # Applets: iOS Reverse, only for you to present valuable information, focusing on mobile technology research field.

More resources to download, please visit the blog: kunnan.blog.csdn.net/article/det…