內網傳送簡訊驗證碼
阿新 • • 發佈:2019-02-07
簡訊介面:http://hdweb01/HelperService/SMSHelper.asmx
public void ProcessRequest(HttpContext context)
{context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
string code = ""; //驗證碼
#region 發簡訊
if (context.Request.Form["dealType"] != null & context.Request["type"] != null)
{
string dealType = XWY.Common.Method.InputCheck.RemoveBlankBetweenInput(context.Request.Form["dealType"].ToString().Trim());
string type = XWY.Common.Method.InputCheck.RemoveBlankBetweenInput(context.Request.Form["type"].ToString().Trim());
#region 驗證輸入資訊
#region 使用者名稱登入
if (context.Session["PhoneCode"] == null)
{
Random random = new Random();
code = random.Next(100000, 1000000).ToString();
context.Session["PhoneCode"] = code;
string st = SendMessage(dealType, code);
//context.Response.Write("<script>alert(" + st + ")</script>");
context.Response.Write(st);
}
else
{
context.Response.Write("該手機號碼仍然存在有效的手機驗證碼,請重新確認輸入!");
//context.Response.Write("<script>alert('該手機號碼仍然存在有效的手機驗證碼,請重新確認輸入!')</script>");
//context.Response.Write(st);
}
#endregion
#endregion
}
#endregion
}
public static string SendMessage(string dealType, string code)
{
string st = null;
string smstr = null;
string Phone = dealType;
try
{
//smstr = "深圳信用網使用者您好:您本次申請的驗證碼是" + code.ToString() + ",請在1分鐘以內使用,謝謝!";
smstr = "您本次申請的驗證碼是" + code.ToString() + ",請在2小時內使用";
string strSMSSendResult = string.Empty;
XY2.Business.SMSMessageHelper.SMSHelper sms = new XY2.Business.SMSMessageHelper.SMSHelper();
strSMSSendResult = sms.SendByChinaUnicomSMS(smstr, dealType);
if (strSMSSendResult.LastIndexOf("result=0&description=傳送簡訊成功") != -1)
{
st = "傳送成功";
}
else
{
st = "傳送失敗";
}
return st;
}
catch (Exception ex)
{
//essageBox.Show(ex.Message);
st = ex.Message;
return st;
}
}