向单佧手机号发送短信、定义一个可排序的字典
Dim lst As new SortedDictionary(of String,String)(StringComparer.Ordinal)
lst.Add("AccessKeyId","123456789") 'AccessKey凭证id
lst.Add("Format","JSON") '返回的结果格式
lst.Add("Action","SendSms") '调用的接口
lst.Add("RegionId","cn-hangzhou") '
lst.Add("SignatureMethod","HMAC-SHA1") '激活模式
lst.Add("SignatureNonce",System.Guid.NewGuid().ToString()) '随机数
lst.Add("SignatureVersion","1.0") '签名版本
lst.Add("Timestamp",PercentEncode(format(DateTime.UtcNow,"yyyy-MM-ddTHH:mm:ssZ"))) 'Utc时间
lst.Add("Version","2017-05-25") '界面版本
lst.Add("PhoneNumbers", PercentEncode("15500000000")) '的话号码,
'如果是多个号码参考:lst.Add("PhoneNumbers", PercentEncode("15500000000,13000000000"))
lst.Add("SignName", PercentEncode("Foxtable")) '签名
lst.Add("TemplateParam", PercentEncode("{""sfno"":""9999999""}")) '模板参数sfno为模板变量,9999999为变量值
lst.Add("TemplateCode", "SMS_000000000") '模板.
'按顺序拼接参数
Dim su As new StringBuilder
For Each key As String In lst.keys
su.AppendFormat("&{0}={1}",key,lst(key))
Next
Dim s As String =su.ToString().trimstart("&")
Dim AccessKeySecret As String = "987654321" '凭证密钥
Dim sign As String = SignString(AccessKeySecret,s) '加密参数字符串
'拼接接口url
Dim url As String = "http://dysmsapi.aliyuncs.com/?Signature=" & PercentEncode(sign) & "&" & s
'Dim urls As String = "https://dysmsapi.aliyuncs.com/?Signature=" & PercentEncode(sign) & "&" & s
Dim hc As New HttpClient(url)
Dim ret As String = hc.GetData()
MessageBox.Show(ret)