• C# 参数按照ASCII码从小到大排序(字典序)


    在对接第三方快递的时候,第三方会要求参数按照ASCII码从小到大排序。如下:

    复制代码
     1 public static void requestPay()
     2  {
     3        Dictionary<string, string> dics = new Dictionary<string, string>();
     4        dics.Add("amount", amount);
     5        dics.Add("callback_url", callback_url);
     6        dics.Add("goodsname", goodsname);
     7        dics.Add("merchno", merchno);
     8        dics.Add("notify_url", notify_url);
     9        dics.Add("ordno", ordno);
    10        dics.Add("organno", organno);
    11        dics.Add("version", version);
    12        dics.Add("paytype", paytype);
    13 
    14        getParamSrc(dics);
    15 }
    16 
    17 public static String getParamSrc(Dictionary<string, string> paramsMap)
    18 {
    19        var vDic = (from objDic in paramsMap orderby objDic.Key ascending select objDic);
    20        StringBuilder str = new StringBuilder();
    21        foreach (KeyValuePair<string, string> kv in vDic)
    22        {
    23            string pkey = kv.Key;
    24            string pvalue = kv.Value;
    25            str.Append(pkey + "=" + pvalue + "&");
    26         }
    27 
    28         String result = str.ToString().Substring(0, str.ToString().Length - 1);
    29         return result;
    30 }
  • 相关阅读:
    Spark5
    Spark4
    Spark3
    冲刺周期二--站立会议01
    团队第一阶段绩效考核
    各个小组对“躲避小球”游戏的评价
    软件项目第一个Sprint评论
    丹佛机场行李处理系统
    冲刺周期一--站立会议07
    冲刺周期一--站立会议06
  • 原文地址:https://www.cnblogs.com/Freedom0221/p/11455539.html
Copyright © 2020-2023  润新知