博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[转] VB6.0 Dictionary 排序,生成Sign
阅读量:6875 次
发布时间:2019-06-26

本文共 1996 字,大约阅读时间需要 6 分钟。

  最近遇到好多要生成 sign 的接口,要求使用URL键值对的格式(即key1=value1&key2=value2…)拼接成字符串,最后拼接上key进行MD5加密。

  规则:

  1. .    ◆ 参数名ASCII码从小到大排序(字典序);
  2. .    ◆ 如果参数的值为空不参与签名;
  3. .    ◆ 参数名区分大小写;
  4. .    ◆ 参数名Sign 、Key 不参与拼接字符串;

  发现VB6.0 的资料很少,特此整理一份网上的代码。

  转自:  

'说明:Dictionary排序'参数:'   objDict:Dictionary对象'   intSort: 1 根据key排序; 2 根据value排序Function SortDictionary(objDict, intSort)  ' declare our variables  Dim strDict()  Dim objKey  Dim strKey, strItem  Dim X, Y, Z  ' get the dictionary count  Z = objDict.Count  ' we need more than one item to warrant sorting  If Z > 1 Then    ' create an array to store dictionary information    ReDim strDict(Z, 2)    X = 0    ' populate the string array    For Each objKey In objDict        strDict(X, 1) = CStr(objKey)        strDict(X, 2) = CStr(objDict(objKey))        X = X + 1    Next    ' perform a a shell sort of the string array    For X = 0 To (Z - 2)      For Y = X To (Z - 1)        If StrComp(strDict(X, intSort), strDict(Y, intSort), vbTextCompare) > 0 Then            strKey = strDict(X, 1)            strItem = strDict(X, 2)            strDict(X, 1) = strDict(Y, 1)            strDict(X, 2) = strDict(Y, 2)            strDict(Y, 1) = strKey            strDict(Y, 2) = strItem        End If      Next    Next    ' erase the contents of the dictionary object    objDict.RemoveAll    ' repopulate the dictionary with the sorted information    For X = 0 To (Z - 1)        If LCase(strDict(X, 1)) <> "sign" And LCase(strDict(X, 1)) <> "key" And strDict(X, 2) <> "" Then            objDict.Add strDict(X, 1), strDict(X, 2)        End If    Next  End IfEnd Function

   使用方法:

Dim dict As Dictionary    Dim item    Dim Return as String         Set dict = New Dictionary        dict.Add "aaa", "094959"    dict.Add "ccc", "0000000000"    dict.Add "fff", "20180912"      SortDictionary dict, 1 '排序    For Each item In dict        Return = Return & item & "=" & dict(item) & "&"    Next    Return = Return & "key=keyvalue"    Debug.Print Return 

 

转载于:https://www.cnblogs.com/PengRay0221/p/9645528.html

你可能感兴趣的文章
PXE+KickStart无人值守安装RHEL
查看>>
十年,站酷已成设计论坛霸主,博客园却成无兵之将
查看>>
ansible安装
查看>>
使用bind搭建DNS服务器
查看>>
Windows server 2008R2 DHCP服务器
查看>>
计算机网络笔记--数据链路层(一)
查看>>
我的友情链接
查看>>
Java方法重载注意事项
查看>>
爱创课堂每日一题第五十九天- javascript继承的6种方法
查看>>
16.1 Tomcat介绍 16.2 安装jdk 16.3 安装Tomcat
查看>>
JS 正则表达式用法
查看>>
文档查看cat_more_less_head_tail
查看>>
python课堂笔记之django-day01(4)
查看>>
九月十九日作业
查看>>
Shell工作笔记01
查看>>
项目、软件开发过程中版本术语
查看>>
CSS实现背景透明,文字不透明(各浏览器兼容)
查看>>
【转】[大学引导]超级链接、字体颜色、音乐播放公式
查看>>
T-SQL中INSERT、UPDATE
查看>>
Linux下Nginx服务器配置Modsecurity实现Web应用防护系统
查看>>