• 调用接口时对参数的排序、生成签名、生成随机数,获取唯一标示符


    #pragma mark -- 参数的排序  

    + (NSMutableString*)postSignParamet:(NSString*)method privateParam:(NSMutableDictionary*)param {

        

        NSMutableString* lastParam = [[NSMutableString alloc]init];

        

        //排序 

        NSArray* sortKeys = [[param allKeys] sortedArrayUsingSelector:@selector(compare:)];

        

        for (NSString *key in sortKeys) {

            [lastParam appendString:[NSString stringWithFormat:@"%@=%@&",key,[param objectForKey:key]]];

        }

         //appKey 作为排序的结尾字符,

        [lastParam appendString:[NSString stringWithFormat:@"%@=%@",appkey,PARTNER_ID]];

        return lastParam;

    }

    //生成签名

    + (NSString*)postSign:(NSString *)sign {

        

        NSData *data = [sign dataUsingEncoding:NSUTF8StringEncoding];

        unsigned char result[CC_MD5_DIGEST_LENGTH];

        CC_MD5(data.bytes, (CC_LONG)data.length, result);

        

        NSMutableString *ret = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH*2];

        for(int i = 0; i<CC_MD5_DIGEST_LENGTH; i++) {

            [ret appendFormat:@"%02X",result[i]];

        }

        return ret;

    }

     

    #pragma mark -- 获取随机数

    + (NSString *)getNonceStr

    {

        NSString *string = [[NSString alloc]init];

        for (int i = 0; i < 32; i++) {

            int number = arc4random() % 32;  //随机数的长度 32

            if (number < 10) {

                int figure = (arc4random() % 10) + 48//数字

                NSString *tempString = [NSString stringWithFormat:@"%d", figure];

                string = [string stringByAppendingString:tempString];

            }

            else if (number > 10 && number < 20)

            {

                int figure = (arc4random() % 26) + 65//大写

                char character = figure;

                NSString *tempString = [NSString stringWithFormat:@"%c", character];

                string = [string stringByAppendingString:tempString];

            }

            else {

                int figure = (arc4random() % 26) + 97//小写

                char character = figure;

                NSString *tempString = [NSString stringWithFormat:@"%c", character];

                string = [string stringByAppendingString:tempString];

            }

        }

        NSLog(@"%@", string);

        return string;

    }

     

    #pragma  mark -- 获取唯一标识符

    + (NSString*)getDeviceInfo {

        NSString *identifier = [[[UIDevice currentDevice] identifierForVendor] UUIDString];

        return identifier;

    }

     

  • 相关阅读:
    魔兽争霸3 冰封王座 w3g文件如何打开
    魔兽争霸3怎么玩
    笔记本电脑 联想 Thinkpad E420 无法打开摄像头怎么办
    笔记本能连上WIFI网络,但是无法上网怎么办
    佳能打印机 打不出黑色怎么办
    佳能打印机 出现5100错误怎么办
    UG如何把语言改成中文,UG如何把界面语言改成中文
    [Spring] Spring Data JPA
    基于控制权限和登录验证跳转的django登录界面的实现
    windows环境下nutch2.x 在eclipse中实现抓取数据存进mysql详细步骤
  • 原文地址:https://www.cnblogs.com/qwer-BHS/p/5315963.html
Copyright © 2020-2023  润新知