码迷,mamicode.com
首页 > 微信 > 详细

微信支付sign生成方法

时间:2016-01-18 17:34:28      阅读:2602      评论:0      收藏:0      [点我收藏+]

标签:

        NSMutableDictionary *signParams = [NSMutableDictionary dictionary];

        [signParams setObject: req.openID        forKey:@"appid"];

        [signParams setObject: req.nonceStr    forKey:@"noncestr"];

        [signParams setObject: req.package      forKey:@"package"];

        [signParams setObject: req.partnerId        forKey:@"partnerid"];

        [signParams setObject: @(req.timeStamp)    forKey:@"timestamp"];

        [signParams setObject: req.prepayId      forKey:@"prepayid"];

        

        NSMutableString *contentString  =[NSMutableString string];

        NSArray *keys = [signParams allKeys];

        //按字母顺序排序

        NSArray *sortedArray = [keys sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {

            return [obj1 compare:obj2 options:NSNumericSearch];

        }];

        //拼接字符串

        for (NSString *categoryId in sortedArray) {

            if (   ![[dict objectForKey:categoryId] isEqualToString:@""]

                && ![categoryId isEqualToString:@"sign"]

                && ![categoryId isEqualToString:@"key"]

                )

            {

                [contentString appendFormat:@"%@=%@&", categoryId, [signParams objectForKey:categoryId]];

            }

            

        }

        //添加key字段

        [contentString appendFormat:@"key=%@", @"商户api密钥"];

 

        req.sign                = [contentString MD5];

 

微信支付sign生成方法

标签:

原文地址:http://www.cnblogs.com/heiheihei/p/5139849.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!