阿里云
阿里云多端小程序中小企业获客首选
发表主题 回复主题
  • 7450阅读
  • 3回复

[解决方案]使用阿里云邮件推送服务架设自己邮件验证与推送体系(三)

级别: 论坛版主
发帖
18
云币
350
— 本帖被 linanxiaoxiao 设置为精华(2016-08-10) —
上一篇地址:https://bbs.aliyun.com/read/289523.html HHZw-/ s,%  
]E-3/r$_cO  
4、邮件模板的设计 _?:jZ1wZ  
接下来就进入具体的开发,在开发中,肯定会用到对邮件的发送,在我们这个设计的体系里面,最上面也说了,需要设计模板机制,那么我们就先设计邮件模板功能 p3Qls*  
具体的功能架构为: #Lpw8b6  
%VFoK-a  
YnuY/zDF  
引用
这里设计了最简单的模板功能,主要思路即数据存储HTML模板内容,参数直接放入HTML代码中,在开发时进行替换
_]33Ht9  
下面是邮件模板表的设计,表结构如下: ?IYu"UO<)|  
G"` }"T0}  
]:#=[ CH  
n<bU'n  
在后端对模板进行增删改查管理,省略代码若干,最终效果如下:先构建一个用于新用户注册的HTML模板 (_|*&au J  
r&m49N,d  
bJetqF6 n  
然后在管理界面添加信息和HTML代码 iphC\*F  
4P[MkMoC  
>#$SaG!  
然后添加成功 #lrwKHZ+  
7tXy3-~biz  
bwzx_F/  
5、邮件发送的技术准备通过阿里的技术文档可以知道,阿里云邮件服务的调用方式有三种
2=- .@,6  
% Y%r2  
{iX#  
原本准备使用API接口进行封装,但是最近太忙了,所以先使用STMP接口方式进行了一次封装,主要代码如下: x)*Lu">  
实体: ,eBC]4)B6  
  1. /// <summary>
  2. /// 邮件直推请求
  3. /// </summary>
  4. public class AliyunEMailDirectPushRequest
  5. {
  6.     /// <summary>
  7.     /// 目标邮件地址列表
  8.     /// </summary>
  9.     public Dictionary<String, String> AimAddressList { get; set; }
  10.     /// <summary>
  11.     /// 来源邮件地址
  12.     /// </summary>
  13.     public KeyValuePair<String, String> FromAddress { get; set; }
  14.     /// <summary>
  15.     /// 回复邮件地址列表
  16.     /// </summary>
  17.     public Dictionary<String, String> ReplyAddressList { get; set; }
  18.     /// <summary>
  19.     /// 邮件标题
  20.     /// </summary>
  21.     public String Subject { get; set; }
  22.     /// <summary>
  23.     /// 邮件文本
  24.     /// </summary>
  25.     public String Text { get; set; }
  26.     /// <summary>
  27.     /// 邮件HTML
  28.     /// </summary>
  29.     public String HTML { get; set; }
  30.     /// <summary>
  31.     /// 类型
  32.     /// </summary>
  33.     public Int32 Type { get; set; }
  34.     /// <summary>
  35.     /// SMTP用户名
  36.     /// </summary>
  37.     public String SMTPUserName { get; set; }
  38.     /// <summary>
  39.     /// SMTP密码
  40.     /// </summary>
  41.     public String SMTPPassword { get; set; }
  42. }
  43. /// <summary>
  44. /// 邮件直推响应
  45. /// </summary>
  46. public class AliyunEMailDirectPushResponse
  47. {
  48.     /// <summary>
  49.     /// 推送结果
  50.     /// </summary>
  51.     public Int32 Result { get; set; }
  52.     /// <summary>
  53.     /// 推送结果消息
  54.     /// </summary>
  55.     public String ResultMessage { get; set; }
  56. }
发送业务代码: B;ek a[xU  
  1. /// <summary>
  2. /// 邮件直接推送
  3. /// </summary>
  4. /// <param name="String"></param>
  5. /// <returns></returns>
  6. public static AliyunEMailDirectPushResponse EMailDirectPush(AliyunEMailDirectPushRequest _Request)
  7. {
  8.     AliyunEMailDirectPushResponse MyReturn = new AliyunEMailDirectPushResponse();
  9.     MailMessage MyMailMessage = new MailMessage();
  10.     //填充目标邮件地址
  11.     foreach (var e in _Request.AimAddressList)
  12.     {
  13.         MyMailMessage.To.Add(new MailAddress(e.Key, e.Value));
  14.     }
  15.     //填充来源邮件地址
  16.     MyMailMessage.From = new MailAddress(_Request.FromAddress.Key, _Request.FromAddress.Value);
  17.     //填充回复邮件地址
  18.     foreach (var e in _Request.ReplyAddressList)
  19.     {
  20.         MyMailMessage.ReplyToList.Add(new MailAddress(e.Key, e.Value));
  21.     }
  22.     // 邮件主题
  23.     MyMailMessage.Subject = _Request.Subject;
  24.     // 邮件正文内容
  25.     String Text = _Request.Text;
  26.     String HTML = _Request.HTML;
  27.     if (_Request.Type == 1)
  28.     {
  29.         //文本发送方式
  30.         MyMailMessage.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(Text, null, MediaTypeNames.Text.Plain));
  31.     }
  32.     if (_Request.Type == 2)
  33.     {
  34.         //HTML发送方式
  35.         MyMailMessage.AlternateViews.Add(AlternateView.CreateAlternateViewFromString(HTML, null, MediaTypeNames.Text.Html));
  36.     }
  37.     //邮件推送的SMTP地址和端口
  38.     SmtpClient MySmtpClient = new SmtpClient("smtpdm.aliyun.com", 25);
  39.     // 使用SMTP用户名和密码进行验证
  40.     System.Net.NetworkCredential MyNetworkCredential = new System.Net.NetworkCredential(_Request.SMTPUserName, _Request.SMTPPassword);
  41.     MySmtpClient.Credentials = MyNetworkCredential;
  42.     MySmtpClient.Timeout = 5000;//设置5秒超时
  43.     try
  44.     {
  45.         MySmtpClient.Send(MyMailMessage);
  46.         MyReturn.Result = 1;
  47.         MyReturn.ResultMessage = "发送成功";
  48.         return MyReturn;
  49.     }
  50.     catch (Exception e)
  51.     {
  52.         MyReturn.Result = -1;
  53.         MyReturn.ResultMessage = e.Message;
  54.         return MyReturn;
  55.     }
  56. }
: c~SH/qS  
6、邮件验证码生成与发送的实现主要代码如下: -$W1wb9z  
  1. /// <summary>
  2. /// 创建注册邮件验证
  3. /// </summary>
  4. /// <param name="_Request"></param>
  5. /// <returns></returns>
  6. private DWebAccountCreateRegisterEMailVerifyResponse CreateRegisterEMailVerify(DWebAccountCreateRegisterEMailVerifyRequest _Request, HttpRequestMessage _HttpRequest)
  7. {
  8.     DWebAccountCreateRegisterEMailVerifyResponse MyResponse = new DWebAccountCreateRegisterEMailVerifyResponse();
  9.     DWebMySQLDataContexter CheckQueryDataContexter = CreateNewDataContexter();
  10.     //首先检查是否存在邮件
  11.     var UserCheckQuery = CheckQueryDataContexter.ams_user_table.Where(e => e.AUT_EMAILADDRESS == _Request.EMailAddress);
  12.     if (UserCheckQuery.Count() > 0)
  13.     {
  14.         MyResponse.SetResult(-1, "邮件已经存在");
  15.         return MyResponse;
  16.     }
  17.     else
  18.     {
  19.         //再检查和最近一次的发送是否已经超过1分钟了
  20.         DateTime CheckDateTime = DateTime.Now.AddMinutes(4);//增加4分钟
  21.         var VerifyCreateCheckQuery = CheckQueryDataContexter.ams_email_verify_table.Where(e => e.AEVT_EMAILADDRESS == _Request.EMailAddress && e.AEVT_EXPIRETIME >= CheckDateTime);
  22.         if (VerifyCreateCheckQuery.Count() > 0)
  23.         {
  24.             MyResponse.SetResult(-2, "一分钟内只能发送一次邮件,请稍后再试!");
  25.             return MyResponse;
  26.         }
  27.         else
  28.         {
  29.             //将之前发送的验证码全部失效
  30.             DWebMySQLDataContexter UpdateQueryDataContexter = CreateNewDataContexter();
  31.             var EMailVerifyClearUpdateQuery = UpdateQueryDataContexter.ams_email_verify_table.Where(e => e.AEVT_EMAILADDRESS == _Request.EMailAddress);
  32.             var RegisterSessionClearUpdateQuery = UpdateQueryDataContexter.ams_register_session_table.Where(e => e.ARST_EMAILADDRESS == _Request.EMailAddress);
  33.             foreach (var e in EMailVerifyClearUpdateQuery)
  34.             {
  35.                 e.AEVT_STATE = -1;//表示失效
  36.             }
  37.             foreach (var e in RegisterSessionClearUpdateQuery)
  38.             {
  39.                 e.ARST_STATE = -1;//表示失效
  40.             }
  41.             try
  42.             {
  43.                 UpdateQueryDataContexter.SaveChanges();
  44.                 //下面发起一个新的验证
  45.                 DWebMySQLDataContexter NewTableDataContexter = CreateNewDataContexter();
  46.                 //生成验证码
  47.                 Random MyRandom = new Random();
  48.                 String VerifyCode = MyRandom.Next(1000, 10000).ToString();//获得一个4位随机码
  49.                 DateTime NowDateTime = DateTime.Now;
  50.                 ams_email_verify_table TempEMailVerifyTable = new ams_email_verify_table();
  51.                 TempEMailVerifyTable.AEVT_ID = BLHelper.NewGuid();
  52.                 TempEMailVerifyTable.AEVT_CHANNEL = 1;//表示注册验证
  53.                 TempEMailVerifyTable.AEVT_CHANNELDESCRIPTION = "注册验证";
  54.                 TempEMailVerifyTable.AEVT_CREATETIME = NowDateTime;
  55.                 TempEMailVerifyTable.AEVT_EXPIRETIME = NowDateTime.AddSeconds(300);//有效期300秒,5分钟
  56.                 TempEMailVerifyTable.AEVT_EMAILADDRESS = _Request.EMailAddress;
  57.                 TempEMailVerifyTable.AEVT_PARAMETER1 = "";//参数暂时为空
  58.                 TempEMailVerifyTable.AEVT_PARAMETER2 = "";//参数暂时为空
  59.                 TempEMailVerifyTable.AEVT_REQUESTIPNUMBERADDRESS = _HttpRequest.GetClientIPAddress().StringIPToNumberIP();//获得IP地址
  60.                 TempEMailVerifyTable.AEVT_STATE = 1;//刚刚创建
  61.                 TempEMailVerifyTable.AEVT_VERIFYCODE = VerifyCode;
  62.                 TempEMailVerifyTable.AEVT_VERIFYTYPE = 1;//默认类型为1
  63.                                                          //插入数据库
  64.                 NewTableDataContexter.ams_email_verify_table.Add(TempEMailVerifyTable);
  65.                 try
  66.                 {
  67.                     //保存
  68.                     NewTableDataContexter.SaveChanges();
  69.                     //下面就开启一个多线程发送邮件,然后返回获取成功,这里这样写不妥,但是为了用户体验,立即返回发送成功,就暂且相信阿里云的到达率吧
  70.                     //下面在线程中发送邮件
  71.                     Task TempTask;
  72.                     TempTask = Task.Factory.StartNew(() =>
  73.                     {
  74.                         try
  75.                         {
  76.                             //下面继续用阿里云邮件推送发送邮件
  77.                             //先读取邮件验证模板
  78.                             String TaskVerifyCode = VerifyCode;
  79.                             DWebMySQLDataContexter EMailTemplateDataContexter = CreateNewDataContexter();
  80.                             String EMailTemplateUniqueIdentity = "NewRegisterVerify";
  81.                             var EMailTemplateQuery = EMailTemplateDataContexter.ams_email_template_table.Where(e => e.AETT_UNIQUEIDENTITY == EMailTemplateUniqueIdentity).ToList();
  82.                             if (EMailTemplateQuery.Count() > 0)
  83.                             {
  84.                                 AliyunEMailDirectPushRequest MyRequest = new AliyunEMailDirectPushRequest();
  85.                                 //目标地址
  86.                                 MyRequest.AimAddressList = new Dictionary<String, String>();
  87.                                 MyRequest.AimAddressList.Add(_Request.EMailAddress, "AlphaMS门户注册邮箱【" + _Request.EMailAddress + "】");
  88.                                 //来源地址
  89.                                 MyRequest.FromAddress = new KeyValuePair<String, String>("service@mail.alphams.cn", "AlphaMS门户邮件服务");
  90.                                 //回复地址
  91.                                 MyRequest.ReplyAddressList = new Dictionary<String, String>();
  92.                                 MyRequest.ReplyAddressList.Add("kefu@alphams.cn", "AlphaMS门户客服");
  93.                                 String EMailHTML = EMailTemplateQuery.FirstOrDefault().AETT_CONTENT;
  94.                                 EMailHTML = EMailHTML.Replace("##EMailAddress##", _Request.EMailAddress);
  95.                                 EMailHTML = EMailHTML.Replace("##VerifyCode##", TaskVerifyCode);
  96.                                 MyRequest.HTML = EMailHTML;
  97.                                 MyRequest.Subject = "AlphaMS门户用户注册邮件验证";
  98.                                 MyRequest.Type = 2;//HTML方式发送邮件
  99.                                 MyRequest.SMTPUserName = "service@mail.alphams.cn";
  100.                                 MyRequest.SMTPPassword = "XXXXXX";
  101.                                 //下面发送
  102.                                 AliyunEMailDirectPushResponse TempAliyunEMailDirectPushResponse = AliyunControl.EMailDirectPush(MyRequest);
  103.                             }
  104.                             else
  105.                             {
  106.                                 //模板不存在,也不报错
  107.                             }
  108.                         }
  109.                         catch (Exception)
  110.                         {
  111.                             //在线程中不报错
  112.                         }
  113.                     });
  114.                     MyResponse.SetResult(1, "发送成功");
  115.                     return MyResponse;
  116.                 }
  117.                 catch (Exception NewTableSaveException)
  118.                 {
  119.                     return (DWebAccountCreateRegisterEMailVerifyResponse)SetExceptionError(MyResponse, NewTableSaveException, -5, "数据库错误");
  120.                 }
  121.             }
  122.             catch (Exception UpdateStateSaveException)
  123.             {
  124.                 return (DWebAccountCreateRegisterEMailVerifyResponse)SetExceptionError(MyResponse, UpdateStateSaveException, -5, "数据库错误");
  125.             }
  126.         }
  127.     }
  128. }
7、验证码验证逻辑的实现 GZ~Tl0U  
主要代码如下:
  1. /// <summary>
  2. /// 检查注册邮件验证码
  3. /// </summary>
  4. /// <param name=""></param>
  5. /// <returns></returns>
  6. private DWebAccountCheckRegisterEMailVerifyCodeResponse CheckRegisterEMailVerifyCode(DWebAccountCheckRegisterEMailVerifyCodeRequest _Request, HttpRequestMessage _HttpRequest)
  7. {
  8.     DWebAccountCheckRegisterEMailVerifyCodeResponse MyResponse = new DWebAccountCheckRegisterEMailVerifyCodeResponse();
  9.     //先检查是否有验证记录
  10.     DWebMySQLDataContexter CheckQueryDataContexter = CreateNewDataContexter();
  11.     DateTime NowDateTime = DateTime.Now;
  12.     var CheckQuery = CheckQueryDataContexter.ams_email_verify_table.Where(e => e.AEVT_EMAILADDRESS == _Request.EMailAddress && e.AEVT_STATE == 1 && e.AEVT_EXPIRETIME >= NowDateTime);
  13.     if (CheckQuery.Count() > 0)
  14.     {
  15.         String VerifyCode = CheckQuery.FirstOrDefault().AEVT_VERIFYCODE;
  16.         if (VerifyCode == _Request.VerifyCode)
  17.         {
  18.             //验证成功,设置这个验证失效
  19.             CheckQuery.FirstOrDefault().AEVT_STATE = -1;//设置失效
  20.             //所有的注册会话先失效
  21.             DWebMySQLDataContexter UpdateClearDataContexter = CreateNewDataContexter();
  22.             var ClearQuery = UpdateClearDataContexter.ams_register_session_table.Where(e => e.ARST_EMAILADDRESS == _Request.EMailAddress);
  23.             foreach (var e in ClearQuery)
  24.             {
  25.                 e.ARST_STATE = -1;//全部失效
  26.             }
  27.             //下面就要新建一个注册会话
  28.             DWebMySQLDataContexter NewTableDataContexter = CreateNewDataContexter();
  29.             ams_register_session_table TempRegisterSessionTable = new ams_register_session_table();
  30.             TempRegisterSessionTable.ARST_ID = BLHelper.NewGuid();
  31.             CheckQuery.FirstOrDefault().AEVT_PARAMETER1 = TempRegisterSessionTable.ARST_ID;//和邮件验证建立起关联
  32.             TempRegisterSessionTable.ARST_CREATETIME = NowDateTime;
  33.             TempRegisterSessionTable.ARST_CLIENTIPNUMBERADDRESS = _HttpRequest.GetClientIPAddress().StringIPToNumberIP();
  34.             TempRegisterSessionTable.ARST_EMAILADDRESS = _Request.EMailAddress;
  35.             TempRegisterSessionTable.ARST_EXPIRETIME = NowDateTime.AddMinutes(10);//这个会话的有效期是10分钟
  36.             TempRegisterSessionTable.ARST_STATE = 1;//刚刚创建
  37.             NewTableDataContexter.ams_register_session_table.Add(TempRegisterSessionTable);
  38.             try
  39.             {
  40.                 CheckQueryDataContexter.SaveChanges();
  41.                 NewTableDataContexter.SaveChanges();
  42.                 UpdateClearDataContexter.SaveChanges();
  43.                 MyResponse.RegisterSessionID = TempRegisterSessionTable.ARST_ID;
  44.                 MyResponse.SetResult(1, "验证成功");
  45.                 return MyResponse;
  46.             }
  47.             catch (Exception DataSaveException)
  48.             {
  49.                 return (DWebAccountCheckRegisterEMailVerifyCodeResponse)SetExceptionError(MyResponse, DataSaveException, -5, "数据库错误");
  50.             }
  51.         }
  52.         else
  53.         {
  54.             MyResponse.SetResult(-2, "验证码错误");
  55.             return MyResponse;
  56.         }
  57.     }
  58.     else
  59.     {
  60.         MyResponse.SetResult(-1, "已经过期,请重新获取验证码!");
  61.         return MyResponse;
  62.     }
  63. }
8、前端注册页面的实现 3~T ~Bs  
  1. //页面控制器
  2. var PageControl = {
  3.     //注册初始化
  4.     RegisterInit: function () {
  5.         PageControl.NewRegisterSessionID = "";//重新清空会话编号
  6.         PageControl.EMailVerifyInit();
  7.     },
  8.     //邮件验证初始化
  9.     EMailVerifyInit: function () {
  10.         clearInterval(PageControl.GetVerifyCodeTimeLeft);
  11.         $("#AR_Register_EMailVerify_Container").show();
  12.         $("#AR_Register_EMailVerify_EMailAddress_TextBox").val("");
  13.         $("#AR_Register_EMailVerify_EMailAddress_TextBox").removeAttr("readonly");
  14.         $("#AR_Register_EMailVerify_GetVerifyCode_Button").removeAttr("disabled");
  15.         $("#AR_Register_EMailVerify_GetVerifyCode_Button").val("获取验证码");
  16.         $("#AR_Register_EMailVerify_Verify_Container").hide();
  17.         $("#AR_Register_EMailVerify_Verify_Code_TextBox").val("");
  18.         $("#AR_Register_UserInfo_Container").hide();
  19.     },
  20.     //获取验证码时间结束
  21.     GetVerifyCodeTimeLeft: null,
  22.     //创建邮件验证
  23.     CreateEMailVerify: function () {
  24.         //先隐藏起来
  25.         $("#AR_Register_EMailVerify_Verify_Container").hide();
  26.         //检查邮件地址输入
  27.         if ($("#AR_Register_EMailVerify_EMailAddress_TextBox").val() == "") {
  28.             AlphaMS.JSToolkit.Dialog.MessageBox("请输入邮件地址", function () {
  29.                 $("#AR_Register_EMailVerify_EMailAddress_TextBox").focus();
  30.             });
  31.             return;
  32.         }
  33.         //检查邮件地址输入
  34.         if (!AlphaMS.JSToolkit.Valid.CheckMail($("#AR_Register_EMailVerify_EMailAddress_TextBox").val())) {
  35.             AlphaMS.JSToolkit.Dialog.MessageBox("请输入正确的邮件地址", function () {
  36.                 $("#AR_Register_EMailVerify_EMailAddress_TextBox").focus();
  37.             });
  38.             return;
  39.         }
  40.         //AlphaMS业务逻辑请求
  41.         AlphaMS.JSToolkit.NET.BLRequest({
  42.             Debug: false,
  43.             //业务逻辑方法路由名称
  44.             FunctionRouteName: "AlphaMS.Portal.DWeb.Account.CreateRegisterEMailVerify",
  45.             //业务逻辑请求数据
  46.             BLRequestObject: {
  47.                 //请求参数
  48.                 //邮件地址
  49.                 EMailAddress: $("#AR_Register_EMailVerify_EMailAddress_TextBox").val()
  50.             },
  51.             //SBS请求返回
  52.             BLResponse: {
  53.                 //请求成功
  54.                 Success: function (MyResponseObject) {
  55.                     switch (MyResponseObject.ResultCode) {
  56.                         case 1:
  57.                             //注册成功
  58.                             AlphaMS.JSToolkit.Dialog.MessageBox("验证码获取成功,有效期5分钟,请到邮箱中查收验证码并填入下面框中", function () {
  59.                                 $("#AR_Register_EMailVerify_Verify_Code_TextBox").focus();
  60.                             });
  61.                             $("#AR_Register_EMailVerify_EMailAddress_TextBox").attr("readonly", "readonly");
  62.                             $("#AR_Register_EMailVerify_GetVerifyCode_Button").attr("disabled", "disabled");
  63.                             $("#AR_Register_EMailVerify_GetVerifyCode_Button").html("重新获取(剩余60秒)");
  64.                             var T = 60;//倒计时60秒
  65.                             PageControl.GetVerifyCodeTimeLeft = setInterval(function () {
  66.                                 T = T - 1;
  67.                                 if (T == 0) {
  68.                                     //结束倒计时
  69.                                     clearInterval(PageControl.GetVerifyCodeTimeLeft);
  70.                                     $("#AR_Register_EMailVerify_EMailAddress_TextBox").removeAttr("readonly");
  71.                                     $("#AR_Register_EMailVerify_GetVerifyCode_Button").removeAttr("disabled");
  72.                                     $("#AR_Register_EMailVerify_GetVerifyCode_Button").html("获取验证码");
  73.                                 } else {
  74.                                     $("#AR_Register_EMailVerify_GetVerifyCode_Button").html("重新获取(剩余" + T + "秒)");
  75.                                 }
  76.                             }, 1000);
  77.                             $("#AR_Register_EMailVerify_Verify_Container").show();
  78.                             break;
  79.                         case -1:
  80.                             AlphaMS.JSToolkit.Dialog.MessageBox("邮件已经被其他用户使用,请换一个", function () {
  81.                                 $("#AR_Register_EMailVerify_EMailAddress_TextBox").focus();
  82.                             });
  83.                             break;
  84.                         default:
  85.                             AlphaMS.JSToolkit.Dialog.MessageBox(MyResponseObject.ResultMessage);
  86.                             break;
  87.                     }
  88.                 }
  89.             }
  90.         }, ["Body"]);
  91.     },
  92.     //新注册会话编号
  93.     NewRegisterSessionID: "",
  94.     //检查邮件验证码
  95.     CheckEMailVerifyCode: function () {
  96.         //检查验证码输入
  97.         if ($("#AR_Register_EMailVerify_Verify_Code_TextBox").val() == "") {
  98.             AlphaMS.JSToolkit.Dialog.MessageBox("请输入收到的验证码", function () {
  99.                 $("#AR_Register_EMailVerify_Verify_Code_TextBox").focus();
  100.             });
  101.             return;
  102.         }
  103.         //AlphaMS业务逻辑请求
  104.         AlphaMS.JSToolkit.NET.BLRequest({
  105.             Debug: false,
  106.             //业务逻辑方法路由名称
  107.             FunctionRouteName: "AlphaMS.Portal.DWeb.Account.CheckRegisterEMailVerifyCode",
  108.             //业务逻辑请求数据
  109.             BLRequestObject: {
  110.                 //请求参数
  111.                 //邮件地址
  112.                 EMailAddress: $("#AR_Register_EMailVerify_EMailAddress_TextBox").val(),
  113.                 //验证码
  114.                 VerifyCode: $("#AR_Register_EMailVerify_Verify_Code_TextBox").val()
  115.             },
  116.             //SBS请求返回
  117.             BLResponse: {
  118.                 //请求成功
  119.                 Success: function (MyResponseObject) {
  120.                     switch (MyResponseObject.ResultCode) {
  121.                         case 1:
  122.                             PageControl.NewRegisterSessionID = MyResponseObject.RegisterSessionID;
  123.                             $("#AR_Register_EMailVerify_Container").hide();
  124.                             $("#AR_Register_UserInfo_Container").show();
  125.                             $("#AR_Register_EMail_TextBox").val($("#AR_Register_EMailVerify_EMailAddress_TextBox").val());
  126.                             break;
  127.                         case -1:
  128.                             AlphaMS.JSToolkit.Dialog.MessageBox("验证码过期,请重新获取!", function () {
  129.                                 //初始化邮件验证
  130.                                 PageControl.EMailVerifyInit();
  131.                             });
  132.                             break;
  133.                         case -2:
  134.                             AlphaMS.JSToolkit.Dialog.MessageBox("验证码错误,请重新输入", function () {
  135.                                 $("#AR_Register_EMailVerify_Verify_Code_TextBox").focus();
  136.                             });
  137.                             break;
  138.                         default:
  139.                             AlphaMS.JSToolkit.Dialog.MessageBox(MyResponseObject.ResultMessage);
  140.                             break;
  141.                     }
  142.                 }
  143.             }
  144.         }, ["Body"]);
  145.     },
  146.     //提交注册
  147.     SubmitRegister: function () {
  148.         //检查用户名输入
  149.         if ($("#AR_Register_UserName_TextBox").val() == "") {
  150.             AlphaMS.JSToolkit.Dialog.MessageBox("请输入用户名", function () {
  151.                 $("#AR_Register_UserName_TextBox").focus();
  152.             });
  153.             return;
  154.         }
  155.         //检查密码输入
  156.         if ($("#AR_Register_Password_TextBox").val() == "") {
  157.             AlphaMS.JSToolkit.Dialog.MessageBox("请输入密码", function () {
  158.                 $("#AR_Register_Password_TextBox").focus();
  159.             });
  160.             return;
  161.         }
  162.         var PreRegisterString = "您的注册信息如下:</br>";
  163.         PreRegisterString = PreRegisterString + "邮件地址:" + $("#AR_Register_EMailVerify_EMailAddress_TextBox").val() + "</br>";
  164.         PreRegisterString = PreRegisterString + "用户名:" + $("#AR_Register_UserName_TextBox").val() + "</br>";
  165.         PreRegisterString = PreRegisterString + "密码:" + $("#AR_Register_Password_TextBox").val() + "</br>";
  166.         PreRegisterString = PreRegisterString + "确认注册吗?";
  167.         AlphaMS.JSToolkit.Dialog.MessageBox(PreRegisterString, function () {
  168.             //AlphaMS业务逻辑请求
  169.             AlphaMS.JSToolkit.NET.BLRequest({
  170.                 Debug: false,
  171.                 //业务逻辑方法路由名称
  172.                 FunctionRouteName: "AlphaMS.Portal.DWeb.Account.NewRegister",
  173.                 //业务逻辑请求数据
  174.                 BLRequestObject: {
  175.                     //请求参数
  176.                     //用户名
  177.                     UserName: $("#AR_Register_UserName_TextBox").val(),
  178.                     //密码
  179.                     Password: $("#AR_Register_Password_TextBox").val(),
  180.                     //注册会话编号
  181.                     RegisterSessionID: PageControl.NewRegisterSessionID
  182.                 },
  183.                 //SBS请求返回
  184.                 BLResponse: {
  185.                     //请求成功
  186.                     Success: function (MyResponseObject) {
  187.                         switch (MyResponseObject.ResultCode) {
  188.                             case 1:
  189.                                 //注册成功
  190.                                 AlphaMS.JSToolkit.Dialog.MessageBox("注册成功,请前往登录", function () {
  191.                                     AlphaMS.JSToolkit.Action.GoToPage("/Login");
  192.                                 });
  193.                                 break;
  194.                             case -1:
  195.                                 AlphaMS.JSToolkit.Dialog.MessageBox("注册已经过期,请重新验证邮件地址!", function () {
  196.                                     PageControl.RegisterInit();
  197.                                 });
  198.                                 break;
  199.                             case -2:
  200.                                 AlphaMS.JSToolkit.Dialog.MessageBox("邮件地址已经存在!", function () {
  201.                                     PageControl.RegisterInit();
  202.                                 });
  203.                                 break;
  204.                             case -3:
  205.                                 AlphaMS.JSToolkit.Dialog.MessageBox("用户名已经存在,请重新输入!", function () {
  206.                                     $("#AR_Register_UserName_TextBox").focus();
  207.                                 });
  208.                                 break;
  209.                             default:
  210.                                 AlphaMS.JSToolkit.Dialog.MessageBox(MyResponseObject.ResultMessage);
  211.                                 break;
  212.                         }
  213.                     }
  214.                 }
  215.             }, ["Body"]);
  216.         }, function () { });
  217.     }
  218. }
下面来看一下最终邮件验证的效果 &Gjpc>d  
输入邮件地址 8In\Jo$|q>  
n7fhc*}:`  
G<e+sDQ2  
获取验证码 3_)I&RM  
A,.X  
3W7^,ir  
收到邮件 rNq* z,  
d5l42^Z  
GK}52,NM  
验证成功,继续填写用户信息 -5b|nQuY  
D6Ad "|Z  
3P6O]x<-?  
'IX1WS&\"  
m`-);y  
注册成功 $\BYN=#  
<2U@O` gC  
ie6 c/5  
wtek5C^  
四、总结与思考 309 pl  
就此,我们就使用阿里云邮件推送,完成了完整的邮件验证与推送体系的架设(主动推送、数据统计等没有写出来,但是在代码里面有,有需要代码的可以邮件向我索要),一句话总结就是如下: &IQ=M.!r  
引用
我想,互联网再怎么发展,QQ号可以没有,微信也可能衰落,但邮件没有的可能性很低,作为一种工作方式和服务方式,在可预见的未来内,邮件体系一定会伴随着信息系统的发展而发展,而从技术的角度出发,对邮件技术和服务的深入研究与思考,一定能够带来更加优秀的软件系统和应用。因此,建议每一个互联网创业者和应用,都能够重视对邮件数据的收集和处理,也在邮件服务上多花点精力和金钱,带给用户更好的体验。

作者:张柔,发布于  阿里云云栖论坛博客园  与  初码博客 " #iJ/vy  
z ?\it(  
F"] P|   
*DPX4 P  
j9NF|  
!kE5]<H\  
[ 此帖被初码在2016-07-22 18:30重新编辑 ]
本帖最近评分记录: 1 条评分 云币 +8
鬼才神兵 云币 +8 您的帖子很精彩!希望很快能再分享您的下一帖! 2016-07-23
级别: 论坛版主
发帖
1784
云币
3327

只看该作者 沙发  发表于: 2016-07-23
您的帖子很精彩!希望很快能再分享您的下一帖!
级别: 论坛版主
发帖
3414
云币
8980

只看该作者 板凳  发表于: 2016-07-23
模板机制  去年项目开发 就是用的模板 以前居然直接写到代码里面也是醉了
级别: 论坛版主
发帖
18
云币
350
只看该作者 地板  发表于: 2016-07-24
回 2楼(小柒2012) 的帖子
发表主题 回复主题
« 返回列表上一主题下一主题

限100 字节
如果您在写长篇帖子又不马上发表,建议存为草稿
 
验证问题: 49 - 32 = ?
上一个 下一个
      ×
      全新阿里云开发者社区, 去探索开发者的新世界吧!
      一站式的体验,更多的精彩!
      通过下面领域大门,一起探索新的技术世界吧~ (点击图标进入)