文件名称:阿里云短信接口
文件大小:200KB
文件格式:DLL
更新时间:2022-04-28 03:48:47
阿里云短信接
private string findpwdmobilecode(string telphone) { bool result = false; string qiyecid = "k游";//签名,例如:【阿里大于】 string appkey = "L1111111111111111111V"; string secret = "E111111111111111111111111"; string sms = "SMS_111111111";//短信模板ID,在阿里大于管理后台添加审核 string url = "http://gw.api.taobao.com/router/rest";//阿里大于API接口地址 string fscode = "";//随机验证码 Random random = new Random(); for (int i = 0; i < 4; i++) { fscode += random.Next(9); } Session["mobilecode"] = fscode + telphone; this.Session.Timeout = 5; #region 新版阿里大鱼 IClientProfile profile = DefaultProfile.GetProfile("default", appkey, secret); DefaultAcsClient client = new DefaultAcsClient(profile); CommonRequest request = new CommonRequest(); request.Method = MethodType.POST; request.Domain = "dysmsapi.aliyuncs.com"; request.Version = "2017-05-25"; request.Action = "SendSms"; // request.Protocol = ProtocolType.HTTP; request.AddQueryParameters("PhoneNumbers", telphone); request.AddQueryParameters("SignName", qiyecid); request.AddQueryParameters("TemplateCode", sms); string sendcode = "{\"code\":\"" + fscode + "\"}"; request.AddQueryParameters("TemplateParam", sendcode); string err_code = ""; try { CommonResponse response = client.GetCommonResponse(request); string jsonText = System.Text.Encoding.Default.GetString(response.HttpResponse.Content); try { JObject jo = (JObject)JsonConvert.DeserializeObject(jsonText); err_code = jo["Code"].ToString(); } catch (Exception e) { return ""; } switch (err_code)//返回1代表成功 { case "OK": result = true;//验证码已经发送 break; default: result = false;//请重新发送验证码 break; } } catch (ServerException e) { return ""; } catch (ClientException e) { return ""; } if (result) { return fscode + telphone; } else { return ""; } #endregion }