C# 参数按照ASCII码从小到大排序(字典序)
时间:2021-03-10 09:25:26|栏目:.NET代码|点击: 次
在对接第三方支付的时候,第三方会要求参数按照ASCII码从小到大排序。如下:
public static void requestPay() { Dictionary<string, string> dics = new Dictionary<string, string>(); dics.Add("amount", amount); dics.Add("callback_url", callback_url); dics.Add("goodsname", goodsname); dics.Add("merchno", merchno); dics.Add("notify_url", notify_url); dics.Add("ordno", ordno); dics.Add("organno", organno); dics.Add("version", version); dics.Add("paytype", paytype); getParamSrc(dics); }
public static String getParamSrc(Dictionary<string, string> paramsMap) { var vDic = (from objDic in paramsMap orderby objDic.Key ascending select objDic); StringBuilder str = new StringBuilder(); foreach (KeyValuePair<string, string> kv in vDic) { string pkey = kv.Key; string pvalue = kv.Value; str.Append(pkey + "=" + pvalue + "&"); } String result = str.ToString().Substring(0, str.ToString().Length - 1); return result; }
上一篇:C#模板方法模式(Template Method Pattern)实例教程
栏 目:.NET代码
下一篇:根据身份证号码计算出生日期、年龄、性别(18位) 根据入职时间计算工龄
本文地址:http://www.codeinn.net/misctech/77906.html