ylbtech-Code-C#:手机号码验证

手机号码验证,文档以JFB项目架构为原型,介绍实现原理,如何调用和应用实例。

架构包括5个主要模块:Basebase,Base,Service,Api和Web。表的设计,实体,数据库操作类,API,Web的网站配置、注册和找回密码实例。

1. Database返回顶部
1、\Tables\VerifyCode/VerifyCode.sql
CREATE TABLE [dbo].[VerifyCode]
(
[Id] INT NOT NULL PRIMARY KEY IDENTITY,
[Code] VARCHAR(50) NULL,
[SndTo] VARCHAR(50) NULL,
[SndContent] VARCHAR(1000) NULL,
[CreateTime] DATETIME NULL,
[IsDeleted] BIT NULL
)
2、
2. Base返回顶部
1、/VerifyCode/VerifyCode.cs
namespace DS.JZB.Base.VerifyCode
{
[Dapper.Contrib.Extensions.Table("[VerifyCode]")]
public class VerifyCode : BaseEntity
{
[Dapper.Contrib.Extensions.Key]
public int Id { get; set; }
/// <summary>
/// 验证码
/// </summary>
public string Code { get; set; }
/// <summary>
/// 发送到
/// </summary>
public string SndTo { get; set; }
/// <summary>
/// 发送内容
/// </summary>
public string SndContent { get; set; }
}
}
2、BaseEntity.cs
using System;

namespace DS.JZB.Base {
public interface IEntity {
bool IsDeleted { get; set; }
DateTime CreateTime { get; set; }
} public abstract class BaseEntity : IEntity {
#region Implementation of IEntity public bool IsDeleted { get; set; } = false;
public DateTime CreateTime { get; set; } = DateTime.Now; #endregion
}
}
3、
3. Service返回顶部
1、/VerifyCode
1.1、IVerifyService.cs
using System.Data;

namespace DS.JZB.Service.VerifyCodes
{
public interface IVerifyCodeService
{
/// <summary>
/// 判断验证码是否有效
/// </summary>
/// <param name="code"></param>
/// <param name="mobile"></param>
void IsValidCode(string code, string mobile); /// <summary>
/// 发送验证码
/// </summary>
/// <param name="sndTo"></param>
string SndVerifyCode(string sndTo); void ValidateIsValidCode(string validCode, string mobile, IDbConnection conn, IDbTransaction trans); void IsValidCode(string code); }
}
1.2、VerifyService.cs
using System;
using System.Data;
using Dapper;
using Dapper.Contrib.Extensions;
using DS.JZB.Base;
using DS.JZB.Base.VerifyCode;
using DS.JZB.Common;
using System.Linq;
using DS.JZB.Service.Sms; namespace DS.JZB.Service.VerifyCodes {
public class VerifyCodeService : IVerifyCodeService {
/// <summary>
/// 验证验证码是否有效
/// </summary>
/// <param name="code"></param>
/// <param name="mobile"></param>
public void IsValidCode(string code, string mobile) {
DbConnectionManipulator.RunMainDatabase(conn => {
var entity =
conn.QueryFirstOrDefault<VerifyCode>(
"select * from VerifyCode where IsDeleted=0 and Code=@Code and SndTo=@SndTo",
new { Code = code, SndTo = mobile });
if (entity == null)
throw new DsException("验证码不存在"); //发送时间距离当前时间超过30分钟的为失败的
if (entity.CreateTime.AddMinutes() < DateTime.Now)
throw new DsException("验证码已失效");
});
} /// <summary>
/// 发送验证码
/// </summary>
/// <param name="sndTo"></param>
public string SndVerifyCode(string sndTo) {
if (string.IsNullOrWhiteSpace(sndTo))
throw new DsException("请输入手机号码"); sndTo = sndTo.Trim(); DbConnectionManipulator.RunMainDatabase(conn => {
//1分钟内,如果已经发送过验证码,则不允许再次发送
var model =
conn.QueryFirstOrDefault("select * from VerifyCode where IsDeleted = 0 and SndTo=@SndTo and CreateTime>@CreateTime",
new { SndTo = sndTo, CreateTime = DateTime.Now.AddMinutes(-) });
if (model != null)
throw new DsException("验证码已发送,请勿重复发送");
}); var code = RndInt();
var sndContent = "验证码{0}";
sndContent = string.Format(sndContent, code);
var entity = new VerifyCode {
Code = code,
SndContent = sndContent,
SndTo = sndTo
};
Insert(entity); SmsService.Instance.SendValidateCodeSms(entity.SndTo, new {
code = code.ToString(),
product = "家服宝"
}); return code;
} private void Insert(VerifyCode entity) {
DbConnectionManipulator.RunMainDatabase(conn => {
conn.Insert(entity);
});
} /// <summary>
/// 验证是否是验证码
/// </summary>
/// <param name="validCode"></param>
/// <param name="mobile"></param>
/// <param name="conn"></param>
/// <param name="trans"></param>
public void ValidateIsValidCode(string validCode, string mobile, IDbConnection conn, IDbTransaction trans) {
var fnOwnConn = conn == null;
if (fnOwnConn) {
conn = DbConnectionManipulator.GetMainDatabaseConnection();
} var entity =
conn.QueryFirstOrDefault<VerifyCode>(
"select * from VerifyCode where IsDeleted=0 and Code=@Code and SndTo=@SndTo",
new { Code = validCode, SndTo = mobile }, trans); if (fnOwnConn) {
conn.Close();
conn.Dispose();
}
if (entity == null)
throw new DsException("验证码不存在"); //发送时间距离当前时间超过30分钟的为失败的
if (entity != null && entity.CreateTime.AddMinutes() < DateTime.Now)
throw new DsException("验证码已失效");
} /// <summary>
/// n位随机码
/// </summary>
/// <returns></returns>
private string RndInt(int n) {
const string str = "";
var rStr = "";
var rnd = new Random();
for (var i = ; i < n; i++) {
var rndNum = rnd.Next();
rStr += str.Substring(rndNum, );
}
return rStr;
} public void IsValidCode(string code) {
var result = DbConnectionManipulator.RunMainDatabase(conn => {
return conn.QuerySingle<int>(@"DECLARE @CreateTime DATETIME
SELECT @CreateTime FROM dbo.VerifyCode WHERE IsDeleted=0 AND Code=@Code
IF @@ROWCOUNT=0
BEGIN
SELECT -1
RETURN
END IF DATEADD(MINUTE,30,@CreateTime)<GETDATE()
BEGIN
SELECT -2
RETURN
END SELECT 0", new { Code = code });
});
if (result == -)
throw new DsException("验证码不存在", ExceptionLevel.Error); //发送时间距离当前时间超过30分钟的为失败的
if (result == -)
throw new DsException("验证码已失效", ExceptionLevel.Error);
} public void MarkValidCodeInvalid(string code, string uniqueKey) {
if (string.IsNullOrWhiteSpace(code)) {
throw new DsException("请填写验证码");
} DbConnectionManipulator.RunMainDatabaseInTransaction((conn, trans) => {
var obj =
conn.Query(
"SELECT TOP 1 * FROM RegCode WHERE Sign=@Sign AND CurStatus=0 AND CreateTime>=@CreateTime AND Code=@Code ORDER BY Id DESC",
new { Sign = uniqueKey, CreateTime = DateTime.Now.AddMinutes(-), Code = code }, trans).FirstOrDefault();
if (obj == null) {
return;
}
conn.Execute(@"UPDATE RegCode SET CurStatus=1 WHERE Id=@Id
UPDATE VerifyCode SET IsDeleted=1 WHERE Code=@Code", new { Id = obj.Id, Code = code }, trans);
});
} }
}
2、SMS
2.1、
2.2、
4. Api返回顶部
1、Controllers
1.1、Account
1.1.1、MemberController.cs
/// <summary>
/// 获取注册验证码
/// </summary>
/// <param name="sndTo"></param>
/// <param name="validateCode"></param>
/// <param name="type"></param>
/// <returns></returns>
[Route("GetVerifyCode"), AllowAnonymous]
[HttpPost]
public JsonResult GetVerifyCode(string sndTo, string validateCode, int type = , string vid = "", int userType = ) {
//if (!DefaultValidateCodeManager.Instance.IsValidValidateCode(validateCode, vid)) {
// return Json(ResultModel.NewError("校验码输入错误或已过期."));
//}
MemberModel user;
if (userType == ) {
user = MemberService.GetSingleByMobile(sndTo);
}
else if (userType == ) {
user = MemberService.GetSingleCleaningByMobile(sndTo);
}
else {
throw new DsException("非法调用!");
} if (type == ) {
if (user != null) {
throw new DsException("该手机号码已注册,请更换!");
}
}
else {
if (user == null) {
throw new DsException("未找到该手机号码的注册信息,请确认!");
}
} VerifyCodeService.SndVerifyCode(sndTo);
return Json(ResultModel.Ok());
} [Route("ValidCode"), AllowAnonymous]
public JsonResult ValidCode(MemberRegisterModel model) { VerifyCodeService.IsValidCode(model.VerifyCode, model.Mobile); return Json(ResultModel.Ok());
}
2、Sms
2.1、ISmsService.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace DS.JZB.Service.Sms {
public interface ISmsService {
/// <summary>
/// 此方法发送的短信,不计入所在企业的扣费列表
/// </summary>
/// <param name="mobile">手机号</param>
/// <param name="content">短信内容,不带标签</param>
void SendValidateCodeSms(string mobile, object parameter);
/// <summary>
/// 此方法发送的短信,会计入所在企业的扣费列表
/// </summary>
void SendSms(string mobile, object parameter, string templateCode = null, string sign = SmsService.SMS_SIGN, int teamId = , int memberId = );
/// <summary>
/// 此方法发送的短信,会计入所在企业的扣费列表
/// </summary>
void SendSms(string[] mobiles, object parameter, string templateCode = null, string sign = SmsService.SMS_SIGN, int teamId = , int memberId = );
}
}
2.2、SmsService.cs
using Dapper;
using Dapper.Contrib.Extensions;
using DS.JZB.Base;
using DS.JZB.Common;
using DS.JZB.Common.Extensions;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Sms.Model.V20170525;
using NLog; namespace DS.JZB.Service.Sms {
public class SmsService : ISmsService {
public const string SMS_SIGN = "服务名称";
public const int FREE_SMS_COUNT = ; public static readonly ISmsService Instance = new SmsService(); private SmsService() { } public void SendSms(string mobile, object parameter, string templateCode, string sign = SMS_SIGN, int teamId = , int memberId = ) {
DoSendSms(mobile, parameter, sign, templateCode, teamId);
} public void SendSms(string[] mobiles, object parameter, string templateCode, string sign = SMS_SIGN, int teamId = , int memberId = ) {
if(mobiles.Length == ) {
DoSendSms(mobiles[], parameter, sign, templateCode, teamId);
}
else {
foreach (var mobile in mobiles)
{
DoSendSms(mobile, parameter, sign, templateCode, teamId);
}
}
} public void SendValidateCodeSms(string mobile, object parameter) {
DoSendSms(mobile, parameter, "服务名称", "SMS_XXXX", );
} private void DoSendSms(string mobile, object parameter, string sign, string templateCode, int teamId) {
if (parameter == null) {
throw new DsException("请指定发送短信的内容");
} if (string.IsNullOrWhiteSpace(mobile)) {
throw new DsException("请指定短信的接收者");
} try
{
string regionId = "cn-hangzhou";
string signName = SMS_SIGN;
string phoneNumbers = mobile;
string templateParam = JsonConvert.SerializeObject(parameter); IClientProfile clientProfile = DefaultProfile.GetProfile(regionId, AliyunSmsConfig.Instance.AccessKeyId, AliyunSmsConfig.Instance.AccessKeySecret);
DefaultProfile.AddEndpoint(regionId, regionId, "Dysmsapi", "dysmsapi.aliyuncs.com"); IAcsClient acsClient = new DefaultAcsClient(clientProfile); SendSmsRequest request = new SendSmsRequest(); request.SignName = signName;
request.TemplateCode = templateCode;
request.PhoneNumbers = phoneNumbers;
request.TemplateParam = templateParam; SendSmsResponse response = acsClient.GetAcsResponse(request); if (response != null) {
LogManager.GetCurrentClassLogger().Debug($"[SMS] {JsonConvert.SerializeObject(response)}");
}
}
catch (ServerException e) {
LogManager.GetCurrentClassLogger().Error(e, "[SMS] ServerException");
}
catch (ClientException e) {
LogManager.GetCurrentClassLogger().Error(e, "[SMS] ClientException"); }
} private void CreateTeamSmsStatisticIfNotExists(int teamId, bool success, IDbConnection conn, IDbTransaction trans) {
conn.Execute($@"IF NOT EXISTS(SELECT TOP 1 1 FROM TeamSmsStatistics WHERE TeamId=@TeamId AND StatisticalDate=@Now)
INSERT INTO [dbo].[TeamSmsStatistics]([TeamId],[StatisticalDate],[TotalSend],[SuccessSend],[FailedSend])
VALUES(@TeamId,@Now,1,{(success ? "," : ",")})
ELSE
UPDATE TeamSmsStatistics SET TotalSend=TotalSend+, {(success ? "SuccessSend=SuccessSend+1" : "FailedSend=FailedSend+1")} WHERE TeamId=@TeamId AND StatisticalDate=@Now", new {
TeamId = teamId,
Now = DateTime.Now.Date
}, trans);
}
}
}
3、
5. Web返回顶部
0、web.config
<configuration>
<appSettings>
<add key="Aliyun:AccessKeyId" value="XXX" />
<add key="Aliyun:AccessKeySecret" value="XXX" />
<add key="Aliyun:EndpointManifestPath" value="D:\X\Web\App_Data\endpoints.xml" />
<add key="Aliyun:AppCode" value="XXXX" />
<add key="TLCert" value="D:\X\Web\App_Data\TLCert.cer" />
</appSettings>
</configuration>
1、/m/js/shd.js
/***
* 账号相关,登录,注册,找回密码
* @type {{initLogin: initLogin, initRegister: initRegister, initForget: initForget}}
*/
var accountUi = {
initLogin: function() { var userType = $.getUrlParam("t");
if(!userType) {
userType = 1;
} if(userType !== 1) {
$(".title").html("家政员登录")
} else {
$(".title").html("客户登录")
}
var ctype = $.getUrlParam("pwd"); $(document).on("tap", "#btnLoginSys", function() {
if(utils.isNull($("#LoginMobile").val())) {
mui.toast("请输入手机号码!");
return false;
}
if(!utils.isMobile($("#LoginMobile").val())) {
mui.toast("您输入的不是有效的手机号");
$("#LoginMobile").focus();
return false;
}
if(utils.isNull($("#LoginPwd").val())) {
mui.toast("请输入密码!");
return false;
}
var param = {
Mobile: $.trim($("#LoginMobile").val()),
LoginPwd: CryptoJS.MD5($.trim($("#LoginPwd").val())).toString(),
userType: userType
}; var btnObj = this;
mui(btnObj).button("loading");
utils.postRequest("member/login", param, function(d) {
$.cookie("token", d.Data.Token);
$.cookie("memberid", d.Data.User.Id);
$.cookie("memberface", d.Data.User.FacePic);
$.cookie("membername", d.Data.User.Name); if(userType == 1) {
$.cookie("ctoken", "");
$.cookie("mtoken", d.Data.Token);
} else {
$.cookie("ctoken", d.Data.Token);
$.cookie("mtoken", "");
} if(window.wechatHelper.isWeiXin()) {
window.wechatHelper.wxEnvInit(); setTimeout(function() {
if(userType == 1) {
mui.openWindow("/m/customer/index.html", "/m/customer/index.html");
} else if(userType == 2) {
mui.openWindow("/m/service/index.html", "/m/service/index.html"); } else {
mui.back();
} }, 15);
} else {
// mui.back();
if(userType == 1) {
mui.openWindow("/m/customer/index.html", "/m/customer/index.html");
} else if(userType == 2) {
mui.openWindow("/m/service/index.html", "/m/service/index.html");
} else {
mui.back();
}
}
}, true).always(function(d) {
mui(btnObj).button("reset");
});
}); $(document).on("tap", "#btnReg", function() {
mui.openWindow("/register.html?t=" + userType, "/register.html?t=" + userType);
});
$(document).on("tap", "#aforget", function() {
mui.openWindow("/forget.html?t=" + userType, "/forget.html?t=" + userType);
});
},
initRegister: function() { var userType = $.getUrlParam("t");
if(!userType) {
userType = 1;
}
if(userType != 1) {
$(".title").html("家政员立即注册");
} else {
$(".title").html("客户立即注册");
}
$(document).on("tap", "#btnGetCheckCode", function() {
var p = {
sndTo: $.trim($("#LoginMobile").val()),
userType: userType
};
if(utils.isNull(p.sndTo) || !p.sndTo.length) {
mui.toast("请输入手机号码");
return false;
}
if(!utils.isMobile(p.sndTo)) {
mui.toast("您输入的不是有效的手机号");
return false;
}
var btnObj = this;
mui(btnObj).button("loading");
utils.postRequest("member/getverifycode", p, function(rev) {
if(rev.IsError) {
mui.toast(rev.Msg);
$(btnObj).html("获取");
} else {
countDownEnable($(btnObj));
//$("#btnNextReg").removeClass("mui-hidden");
}
}, true, true).always(function(d) {
if(d.IsError) {
mui(btnObj).button("reset");
}
});
}); $(document).on("tap", "#btnRegComp", function() {
if(utils.isNull($.trim($("#LoginMobile").val()))) {
mui.toast("请输入手机号码");
return false;
}
if(!utils.isMobile($.trim($("#LoginMobile").val()))) {
mui.toast("您输入的不是有效的手机号");
return false;
}
if(utils.isNull($.trim($("#VerifyCode").val()))) {
mui.toast("请输入验证码");
return false;
}
if(utils.isNull($.trim($("#LoginPwd").val()))) {
mui.toast("请输入密码");
return false;
} var p = {
Mobile: $.trim($("#LoginMobile").val()),
LoginPwd: CryptoJS.MD5($.trim($("#LoginPwd").val())).toString(),
VerifyCode: $.trim($("#VerifyCode").val()),
userType: userType
}; var btnObj = this;
mui(btnObj).button("loading");
utils.postRequest("member/register", p, function(d) {
mui.toast("注册成功!");
setTimeout(function() {
//mui.openWindow("/login.html?t=" + userType, "/login.html?t=" + userType);
mui.back();
}, 500);
}, true).always(function(d) {
if(d.IsError) {
mui(btnObj).button("reset");
}
});
});
},
initForget: function() { var userType = $.getUrlParam("t");
if(!userType) {
userType = 1;
} $(document).on("tap", "#btnGetCheckCode", function() {
var p = {
sndTo: $.trim($("#LoginMobile").val()),
type: 1,
userType: userType
};
if(utils.isNull(p.sndTo) || !p.sndTo.length) {
mui.toast("请输入手机号码");
return false;
}
if(!utils.isMobile(p.sndTo)) {
mui.toast("您输入的不是有效的手机号");
return false;
}
var btnObj = this;
mui(btnObj).button("loading");
utils.postRequest("member/getverifycode", p, function(rev) {
if(rev.IsError) {
mui.toast(rev.Msg);
$(btnObj).html("获取");
} else {
countDownEnable($(btnObj));
//$("#btnNextReg").removeClass("mui-hidden");
}
}, true, true).always(function(d) {
if(d.IsError) {
mui(btnObj).button("reset");
}
});
}); $(document).on("tap", "#btnRegComp", function() {
if(utils.isNull($.trim($("#LoginMobile").val()))) {
mui.toast("请输入手机号码");
return false;
}
if(!utils.isMobile($.trim($("#LoginMobile").val()))) {
mui.toast("您输入的不是有效的手机号");
return false;
}
if(utils.isNull($.trim($("#VerifyCode").val()))) {
mui.toast("请输入验证码");
return false;
}
if(utils.isNull($.trim($("#LoginPwd").val()))) {
mui.toast("请输入密码");
return false;
} var p = {
Mobile: $.trim($("#LoginMobile").val()),
LoginPwd: CryptoJS.MD5($.trim($("#LoginPwd").val())).toString(),
VerifyCode: $.trim($("#VerifyCode").val()),
userType: userType
}; var btnObj = this;
mui(btnObj).button("loading");
utils.postRequest("member/resetpwd", p, function(d) {
mui.toast("密码重置成功!");
setTimeout(function() {
//mui.openWindow("/login.html?t=" + userType, "/login.html?t=" + userType);
mui.back();
}, 500);
}, true).always(function(d) {
if(d.IsError) {
mui(btnObj).button("reset");
}
});
});
},
initLocalRegister: function() {
var params = {};
//获取填写的第几页的注册数据
function getRegisterData(id,page) {
utils.getRequest("localteamOther/getsingle/{0}".format(id), {IsPlatform: $.getUrlParam("p") ? true : false},
function (d) {
if (!d.Data || !d.Data.localTeamInfo) {
return false;
}
var localTeamInfo = d.Data.localTeamInfo;
switch (page) {
case 1:
$("#LinkTel").val(localTeamInfo.LinkTel);
if (!localTeamInfo.OpeningProvince) {
$("#OpeningProvince").html('<span class="province"></span><span class="city"></span><span class="area"></span>');
} else if (!localTeamInfo.OpeningTown) {
$("#OpeningProvince").html('<span class="province">' + localTeamInfo.OpeningProvince + '</span><span class="city">' + localTeamInfo.OpeningCity + '</span><span class="area"></span>');
} else {
$("#OpeningProvince").html('<span class="province">' + localTeamInfo.OpeningProvince + '</span><span class="city">' + localTeamInfo.OpeningCity + '</span><span class="area">' + localTeamInfo.OpeningTown + '</span>');
}
$("#WorkAddress").val(localTeamInfo.WorkAddress);
$("#Management").val(localTeamInfo.ManagementId);
$("#InvitationNO").val(localTeamInfo.InvitationNO);
break;
case 2:
$("[BusinessLicenseId].mui-btn-danger").attr("BusinessLicenseId", localTeamInfo.BusinessLicenseId);
$("#BusinessLicenseName").val(localTeamInfo.BusinessLicenseName);
//$("#UniformCreditNO").val(localTeamInfo.UniformCreditNO);
$("#BusinessLicenseNO").val(localTeamInfo.BusinessLicenseNO);
$("#LegalPerson").val(localTeamInfo.LegalPerson);
if (!localTeamInfo.RegisterProvince) {
$("#RegisterAdr").html('<span class="province"></span><span class="city"></span><span class="area"></span>');
} else if (!localTeamInfo.RegisterTown) {
$("#RegisterAdr").html('<span class="province">' + localTeamInfo.RegisterProvince + '</span><span class="city">' + localTeamInfo.RegisterCity + '</span><span class="area"></span>');
} else {
$("#RegisterAdr").html('<span class="province">' + localTeamInfo.RegisterProvince + '</span><span class="city">' + localTeamInfo.RegisterCity + '</span><span class="area">' + localTeamInfo.RegisterTown + '</span>');
}
$("#DetailAddress").val(localTeamInfo.DetailAddress);
$("[BusinessTermId].mui-btn-danger").attr("BusinessTermId",localTeamInfo.BusinessTermId);
$("#BusinessTermStart").val(utils.utcToLocal(localTeamInfo.BusinessTermStart,"yyyy-MM-dd"));
$("#BusinessTermEnd").val(utils.utcToLocal(localTeamInfo.BusinessTermEnd,"yyyy-MM-dd"));
$("#LinkMan").val(localTeamInfo.LinkMan);
$("#CardNO").val(localTeamInfo.CardNO);
$("#Email").val(localTeamInfo.Email);
$("#LowQuality").val(localTeamInfo.LowQuality);
break;
case 3:
//$("#AccreditUrl").attr("src", localTeamInfo.AccreditUrl);
if(utils.isNull(localTeamInfo.BusinessLicenseUrl)){
$("#BusinessLicenseUrl").attr("src", "/img/mfsczp.jpg");
}else {
$("#BusinessLicenseUrl").attr("src", localTeamInfo.BusinessLicenseUrl);
}
break;
case 4:
if (utils.isNull(localTeamInfo.CardNOUrl_A)) {
$("#CardNOUrl_A").attr("src", "/img/mfsczp.jpg");
} else {
$("#CardNOUrl_A").attr("src", localTeamInfo.CardNOUrl_A);
}
if (utils.isNull(localTeamInfo.CardNOUrl_B)) {
$("#CardNOUrl_B").attr("src", "/img/mfsczp.jpg");
} else {
$("#CardNOUrl_B").attr("src", localTeamInfo.CardNOUrl_B);
}
break;
case 5:
if (utils.isNull(localTeamInfo.PersonCardUrl)) {
$("#PersonCardUrl").attr("src", "/img/mfsczp.jpg");
} else {
$("#PersonCardUrl").attr("src", localTeamInfo.PersonCardUrl);
}
//$("#PermitUrl").attr("src", localTeamInfo.PermitUrl);
break;
}
}, true);
}
//经营类目接口获取
utils.getRequest("managementitem/list", {}, function(data) {
$("#Management").empty().append("<option value=\"\">请选择经营类目</option>");
$(data.Data.Collection).each(function(i, item) {
$("#Management").append("<option value=\"" + item.Id + "\">" + item.Name + "</option>");
});
//获取首页注册的数据需要在获取经营类目完成后调用
if ($.getUrlParam("p")) {
if (!utils.isNull($.cookie("pid"))) {
getRegisterData($.cookie("pid"), 1);
}
} else {
if (!utils.isNull($.cookie("id"))) {
getRegisterData($.cookie("id"), 1);
}
}
}, true); utils.getRequest("bankitem/list", {}, function(data) {
$("#BankItemId").empty().append("<option value=\"\">请选择开户行</option>");
$(data.Data.Collection).each(function(i, item) {
$("#BankItemId").append("<option value=\"" + item.Id + "\">" + item.Name + "</option>");
});
}, true); mui.previewImage();
// utils.uploader({
// browse_button: "upAccreditUrl",
// completeCallback: function(pic) {
// $("#AccreditUrl").attr("src", pic);
// }
// }); utils.uploader({
browse_button: "upBusinessLicenseUrl",
completeCallback: function(pic) {
$("#BusinessLicenseUrl").attr("src", pic);
}
}); utils.uploader({
browse_button: "upCardNOUrl_A",
completeCallback: function(pic) {
$("#CardNOUrl_A").attr("src", pic);
}
}); utils.uploader({
browse_button: "upCardNOUrl_B",
completeCallback: function(pic) {
$("#CardNOUrl_B").attr("src", pic);
}
}); utils.uploader({
browse_button: "upPersonCardUrl",
completeCallback: function(pic) {
$("#PersonCardUrl").attr("src", pic);
}
}); // utils.uploader({
// browse_button: "upPermitUrl",
// completeCallback: function(pic) {
// $("#PermitUrl").attr("src", pic);
// }
// }); $(document).on("tap", "#nextStep", function() {
//验证输入信息
if(utils.isNull($("#LinkTel").val())) {
mui.toast("请输入联系方式!");
return false;
}
if(!utils.isMobile($("#LinkTel").val())) {
mui.toast("请输入正确的联系方式!");
return false;
}
if(utils.isNull($("#OpeningProvince").find(".province").html())) {
mui.toast("请选择开通城市!");
return false;
}
if(utils.isNull($("#WorkAddress").val())) {
mui.toast("请输入办公地址!");
return false;
}
if(utils.isNull($("#Management").val())) {
mui.toast("请选择经营类目!");
return false;
}
var btnObj = this;
mui(btnObj).button("loading");
params = {
UserName: $.trim($("#LinkTel").val()),
LinkTel: $.trim($("#LinkTel").val()),
OpeningProvince: $.trim($("#OpeningProvince").find(".province").html()),
OpeningCity: $.trim($("#OpeningProvince").find(".city").html()),
OpeningTown: $.trim($("#OpeningProvince").find(".area").html()),
WorkAddress: $("#WorkAddress").val(),
ManagementId: $("#Management").val(),
InvitationNO: $("#InvitationNO").val()
};
if ($.getUrlParam("p")) {
params.IsPlatform = true; //是商家还是地方平台
if (!utils.isNull($.cookie("pid"))) {
params.Id = $.cookie("pid");
}
} else {
params.IsPlatform = false; //是商家还是地方平台
if (!utils.isNull($.cookie("id"))) {
params.Id = $.cookie("id");
}
}
utils.postRequest("localteamOther/insertinfo", params, function(d) {
if($.getUrlParam("p")) {
params.IsPlatform = true;
$.cookie("pid",d.Data);
} else {
params.IsPlatform = false;
$.cookie("id",d.Data);
}
viewApi.go("#zzxx");
//获取第二页的数据
if($.getUrlParam("p")) {
if($.cookie("pid")){
getRegisterData($.cookie("pid"),2);
}
} else {
if($.cookie("id")){
getRegisterData($.cookie("id"),2);
}
}
}, true).always(function() {
mui(btnObj).button("reset");
});
});
$(document).on("tap", "#nextStep2", function() {
//验证输入信息
if(utils.isNull($("#BusinessLicenseName").val())) {
mui.toast("请输入营业执照名称!");
return false;
}
if(utils.isNull($("#BusinessLicenseNO").val())) {
mui.toast("请输入营业执照注册号!");
return false;
}
// if(utils.isNull($("#BusinessLicenseNO").val()) && utils.isNull($("#UniformCreditNO").val())) {
// mui.toast("营业执照注册号和统一社会信用代码至少填写一项!");
// return false;
// }
if(utils.isNull($("#LegalPerson").val())) {
mui.toast("请输法定代表人!");
return false;
}
if(utils.isNull($("#RegisterAdr").find(".province").html())) {
mui.toast("请选择注册地址!");
return false;
}
if(utils.isNull($("#DetailAddress").val())) {
mui.toast("请输入执照上的住所/经营场所!");
return false;
}
if($("[BusinessTermId].mui-btn-danger").attr("BusinessTermId") == 1) {
if(utils.isNull($("#BusinessTermStart").val())) {
mui.toast("请选择营业期限开始!");
return false;
}
if(utils.isNull($("#BusinessTermEnd").val())) {
mui.toast("请选择营业期限结束!");
return false;
}
}
if(utils.isNull($("#LinkMan").val())) {
mui.toast("请输入指定联系人姓名!");
return false;
}
if(utils.isNull($("#CardNO").val())) {
mui.toast("请输入身份证号!");
return false;
}
if(!utils.idCardNoUtil.checkIdCardNo($("#CardNO").val())) {
mui.toast("输入身份证格式不正确,请检查!");
return false;
}
var btnObj = this;
mui(btnObj).button("loading");
params = {};
params = {
BusinessLicenseId: $("[BusinessLicenseId].mui-btn-danger").attr("BusinessLicenseId"),
BusinessLicenseName: $("#BusinessLicenseName").val(),
//UniformCreditNO: $("#UniformCreditNO").val(),
BusinessLicenseNO: $("#BusinessLicenseNO").val(),
LegalPerson: $("#LegalPerson").val(),
RegisterProvince: $.trim($("#RegisterAdr").find(".province").html()),
RegisterCity: $.trim($("#RegisterAdr").find(".city").html()),
RegisterTown: $.trim($("#RegisterAdr").find(".area").html()),
DetailAddress: $("#DetailAddress").val(),
BusinessTermId: $("[BusinessTermId].mui-btn-danger").attr("BusinessTermId"),
BusinessTermStart: $("#BusinessTermStart").val(),
BusinessTermEnd: $("#BusinessTermEnd").val(),
LinkMan: $("#LinkMan").val(),
CardNO: $("#CardNO").val(),
Email: $("#Email").val(),
LowQuality: $("#LowQuality").val()
};
if($.getUrlParam("p")) {
params.IsPlatform = true;
params.Id = $.cookie("pid");
} else {
params.IsPlatform = false;
params.Id = $.cookie("id");
}
utils.postRequest("localteamOther/updateinfo", params, function(d) {
viewApi.go("#zzxx2");
//获取第3页的数据
if($.getUrlParam("p")) {
if($.cookie("pid")){
getRegisterData($.cookie("pid"),3);
}
} else {
if($.cookie("id")){
getRegisterData($.cookie("id"),3);
}
}
}, true).always(function() {
mui(btnObj).button("reset");
});
}); $(document).on("tap", "#nextStep3", function() {
//验证输入信息
// if($("#AccreditUrl").attr("src") == "/img/mfsczp.jpg") {
// mui.toast("请上传公司授权书!");
// return false;
// }
if($("#BusinessLicenseUrl").attr("src") == "/img/mfsczp.jpg") {
mui.toast("请上传营业执照!");
return false;
}
var btnObj = this;
mui(btnObj).button("loading");
params = {};
params = {
//AccreditUrl: $("#AccreditUrl").attr("src"),
BusinessLicenseUrl: $("#BusinessLicenseUrl").attr("src")
};
if($.getUrlParam("p")) {
params.IsPlatform = true; //是商家还是地方平台
params.Id = $.cookie("pid");
} else {
params.IsPlatform = false; //是商家还是地方平台
params.Id = $.cookie("id");
}
utils.postRequest("localteamOther/updateinfo2", params, function(d) {
viewApi.go("#zzxx3");
//获取第4页的数据
if($.getUrlParam("p")) {
if($.cookie("pid")){
getRegisterData($.cookie("pid"),4);
}
} else {
if($.cookie("id")){
getRegisterData($.cookie("id"),4);
}
}
}, true).always(function() {
mui(btnObj).button("reset");
});
}); $(document).on("tap", "#nextStep4", function() {
//验证输入信息
if($("#CardNOUrl_A").attr("src") == "/img/mfsczp.jpg") {
mui.toast("请上传身份证正面!");
return false;
}
if($("#CardNOUrl_B").attr("src") == "/img/mfsczp.jpg") {
mui.toast("请上传身份证背面!");
return false;
}
var btnObj = this;
mui(btnObj).button("loading");
params = {};
params = {
CardNOUrl_A: $("#CardNOUrl_A").attr("src"),
CardNOUrl_B: $("#CardNOUrl_B").attr("src")
};
if($.getUrlParam("p")) {
params.IsPlatform = true; //是商家还是地方平台
params.Id = $.cookie("pid");
} else {
params.IsPlatform = false; //是商家还是地方平台
params.Id = $.cookie("id");
}
utils.postRequest("localteamOther/updateinfo3", params, function(d) {
viewApi.go("#zzxx4");
//获取第5页的数据
if($.getUrlParam("p")) {
if($.cookie("pid")){
getRegisterData($.cookie("pid"),5);
}
} else {
if($.cookie("id")){
getRegisterData($.cookie("id"),5);
}
}
}, true).always(function() {
mui(btnObj).button("reset");
});
}); $(document).on("tap", "#nextStep5", function() {
//验证输入信息
if($("#PersonCardUrl").attr("src") == "/img/mfsczp.jpg") {
mui.toast("请上传经营者手持身份证照!");
return false;
}
// if($("#PermitUrl").attr("src") == "/img/mfsczp.jpg") {
// mui.toast("请上传许可资质证明!");
// return false;
// }
var btnObj = this;
mui(btnObj).button("loading");
params = {};
params = {
PersonCardUrl: $("#PersonCardUrl").attr("src")
//PermitUrl: $("#PermitUrl").attr("src")
};
if($.getUrlParam("p")) {
params.IsPlatform = true; //是商家还是地方平台
params.Id = $.cookie("pid");
} else {
params.IsPlatform = false; //是商家还是地方平台
params.Id = $.cookie("id");
}
utils.postRequest("localteamOther/updateinfo4", params, function (d) {
viewApi.go("#skxx");
}, true).always(function () {
mui(btnObj).button("reset");
});
}); $(document).on("tap", "#nextStep6", function() {
if(utils.isNull($("#BankCardNO").val())) {
mui.toast("请输入银行卡号!");
return false;
}
//if (!utils.luhmCheck($("#BankCardNO").val())) {
// mui.toast("输入银行卡号格式不正确,请检查!");
// return false;
//}
if(utils.isNull($("#AccountName").val())) {
mui.toast("请输入开户名!");
return false;
}
if(utils.isNull($("#BankItemId").val())) {
mui.toast("请选择开户行!");
return false;
}
if(utils.isNull($("#BankBranchName").val())) {
mui.toast("请输入支行!");
return false;
}
if(utils.isNull($("#Bank").find(".province").html())) {
mui.toast("请选择开户行所在地!");
return false;
} //验证输入信息 递交数据到服务器
var params = {
UserName: $.trim($("#LinkTel").val()),
LinkTel: $.trim($("#LinkTel").val()),
OpeningProvince: $.trim($("#OpeningProvince").find(".province").html()),
OpeningCity: $.trim($("#OpeningProvince").find(".city").html()),
OpeningTown: $.trim($("#OpeningProvince").find(".area").html()),
WorkAddress: $("#WorkAddress").val(),
ManagementId: $("#Management").val(),
BusinessLicenseId: $("[BusinessLicenseId].mui-btn-danger").attr("BusinessLicenseId"),
BusinessLicenseName: $("#BusinessLicenseName").val(),
//UniformCreditNO: $("#UniformCreditNO").val(),
BusinessLicenseNO: $("#BusinessLicenseNO").val(),
LegalPerson: $("#LegalPerson").val(),
RegisterProvince: $.trim($("#RegisterAdr").find(".province").html()),
RegisterCity: $.trim($("#RegisterAdr").find(".city").html()),
RegisterTown: $.trim($("#RegisterAdr").find(".area").html()),
DetailAddress: $("#DetailAddress").val(),
BusinessTermId: $("[BusinessTermId].mui-btn-danger").attr("BusinessTermId"),
BusinessTermStart: $("#BusinessTermStart").val(),
BusinessTermEnd: $("#BusinessTermEnd").val(),
LinkMan: $("#LinkMan").val(),
CardNO: $("#CardNO").val(),
Email: $("#Email").val(),
LowQuality: $("#LowQuality").val(),
//AccreditUrl: $("#AccreditUrl").attr("src"),
BusinessLicenseUrl: $("#BusinessLicenseUrl").attr("src"),
PersonCardUrl: $("#PersonCardUrl").attr("src"),
//PermitUrl: $("#PermitUrl").attr("src"),
CardNOUrl_A: $("#CardNOUrl_A").attr("src"),
CardNOUrl_B: $("#CardNOUrl_B").attr("src"),
AccountTypeId: $("[AccountTypeId].mui-btn-danger").attr("AccountTypeId"),
AccountName: $("#AccountName").val(),
BankCardNO: $("#BankCardNO").val(),
BankProvince: $.trim($("#Bank").find(".province").html()),
BankCity: $.trim($("#Bank").find(".city").html()),
//BankTown:$.trim($("#Bank").find(".area").html()),
BankItemId: $("#BankItemId").val(),
BankBranchName: $("#BankBranchName").val(),
InvitationNO: $("#InvitationNO").val()
};
if($.getUrlParam("p")) {
params.IsPlatform = true; //是商家还是地方平台
params.Id = $.cookie("pid");
} else {
params.IsPlatform = false; //是商家还是地方平台
params.Id = $.cookie("id");
}
var btnObj = this;
mui(btnObj).button("loading");
utils.postRequest("localteamOther/register", params, function() {
viewApi.go("#skxx2");
//这时候需要把保存的信息清掉
if($.getUrlParam("p")) {
$.cookie("pid","");
} else {
$.cookie("id","");
}
}, true).always(function(d) {
mui(btnObj).button("reset");
});
});
$(document).on("tap", "#nextStep7", function() {
mui.openWindow("/index.html", "/index.html");
});
mui.ready(function() {
/**
* 获取对象属性的值
* 主要用于过滤三级联动中,可能出现的最低级的数据不存在的情况,实际开发中需要注意这一点;
* @param {Object} obj 对象
* @param {String} param 属性名
*/
var _getParam = function(obj, param) {
return obj[param] || '';
}; var nativePlacePicker = new mui.PopPicker({
layer: 3
});
nativePlacePicker.setData(cityData3);
$(document).on("tap", "#OpeningProvince,#RegisterAdr", function() {
var obj = $(this);
nativePlacePicker.show(function(items) {
// obj.html('<span class="province">' + _getParam(items[0], 'text') + '</span><span class="city">' + _getParam(items[1], 'text') + '</span>');
obj.html('<span class="province">' + _getParam(items[0], 'text') + '</span><span class="city">' + _getParam(items[1], 'text') + '</span><span class="area">' + _getParam(items[2], 'text') + '</span>');
var Openparams = {}
Openparams.Province = $.trim($("#OpeningProvince").find(".province").html());
Openparams.City = $.trim($("#OpeningProvince").find(".city").html());
Openparams.Town = $.trim($("#OpeningProvince").find(".area").html());
utils.getRequest("localteamOther/IsExist", Openparams, function(d) {
if(d.Data == true) {
if($.getUrlParam("p")) {
mui.toast("该城市已存在地方平台,请选择其他城市!");
}
} else {
if($.getUrlParam("p")) { } else {
mui.toast("该城市暂无地方平台,请选择其他城市!");
}
}
}, true);
});
}); var cityPicker = new mui.PopPicker({
layer: 2
});
cityPicker.setData(cityData);
$(document).on("tap", "#Bank", function() {
var obj = $(this);
cityPicker.show(function(items) {
obj.html('<span class="province">' + _getParam(items[0], 'text') + '</span><span class="city">' + _getParam(items[1], 'text') + '</span>');
});
}); $(document).on("tap", "[BusinessLicenseId]", function() {
$("[BusinessLicenseId]").removeClass("mui-btn-danger").removeClass("mui-btn-outlined");
$(this).addClass("mui-btn-danger").addClass("mui-btn-outlined");
}); $(document).on("tap", "[BusinessTermId]", function() {
$("[BusinessTermId]").removeClass("mui-btn-danger").removeClass("mui-btn-outlined");
$(this).addClass("mui-btn-danger").addClass("mui-btn-outlined");
if($("[BusinessTermId].mui-btn-danger").attr("BusinessTermId") == 2) {
$("#BussinessTime").addClass("hide");
} else {
$("#BussinessTime").removeClass("hide");
}
}); $(document).on("tap", "[AccountTypeId]", function() {
$("[AccountTypeId]").removeClass("mui-btn-danger").removeClass("mui-btn-outlined");
$(this).addClass("mui-btn-danger").addClass("mui-btn-outlined");
}); $("#BusinessTermStart").mobiscroll().date({
theme: "", // Specify theme like: theme: 'ios' or omit setting to use default
mode: "scroller", // Specify scroller mode like: mode: 'mixed' or omit setting to use default
display: "center", // Specify display mode like: display: 'bottom' or omit setting to use default
lang: "zh", // Specify language like: lang: 'pl' or omit setting to use default
dateFormat: "yy-mm-dd"
});
$("#BusinessTermEnd").mobiscroll().date({
theme: "", // Specify theme like: theme: 'ios' or omit setting to use default
mode: "scroller", // Specify scroller mode like: mode: 'mixed' or omit setting to use default
display: "center", // Specify display mode like: display: 'bottom' or omit setting to use default
lang: "zh", // Specify language like: lang: 'pl' or omit setting to use default
dateFormat: "yy-mm-dd", // 日期格式
max: new Date(new Date().getFullYear() + 100, 11, 31)
}); });
}
};
window.accountUi = accountUi;
2、
6.返回顶部
 
作者:ylbtech
出处:http://ylbtech.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

Modules:手机号码验证的更多相关文章

  1. Asp.NetCore轻松学-业务重点-实现一个简单的手机号码验证

    前言     本文纯干货,直接拿走使用,不用付费.在业务开发中,手机号码验证是我们常常需要面对的问题,目前市场上各种各样的手机号码验证方式,比如正则表达式等等,本文结合实际业务场景,在业务级别对手机号 ...

  2. 最新手机号码验证正则表达式(PHP版本)

    1 前言 手机号码是否合规,则需要校验,可以使用正则表达式. 2 代码 function checkPhoneNumberValidate($phone_number){ //@2017-11-25 ...

  3. js 邮箱和手机号码验证

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. JS电话、手机号码验证

    function isTelephone(inpurStr) {            var partten = /^0(([1,2]\d)|([3-9]\d{2}))-\d{7,8}$/;     ...

  5. php手机号码验证正则表达式

    移动:134.135.136.137.138.139.150.151.152.157.158.159.182.183.184.187.188.178(4G).147(上网卡): 联通:130.131. ...

  6. js中的jQuery Validate增加手机号码验证

    $.validator.addMethod("isPhone", function(value,element) { var length = value.length; var ...

  7. jquery validation 简单验证手机号码

    js代码 // 手机号码验证 jQuery.validator.addMethod("isMobile", function(value, element) { var lengt ...

  8. js验证手机号码 ,昵称,密码

    手机号 /^[+]{0,1}(\d){1,3}[ ]?([-]?((\d)|[ ]){1,12})+$/ 传真~  /^(\d{3,4}-)?\d{7,8}$/ 邮箱 ^[a-z0-9]+([._\\ ...

  9. 验证手机号码的JS方法

    function Checkreg() { //验证电话号码手机号码,包含153,159号段 if (document.form.phone.value=="" && ...

随机推荐

  1. Promise API 简介

    Promise API 简介 译者注: 到处是回调函数,代码非常臃肿难看, Promise 主要用来解决这种编程方式, 将某些代码封装于内部. Promise 直译为"承诺",但一 ...

  2. 使用JDK和axis2发布webservice

    最近使用webservice进行远程调用一直很火,自从JDK1.6版本发布后,发布一个webservice项目变得更加简单了 笔者由于工作的需要针对JDK和axis2如何发布webservice做过相 ...

  3. VS2015 & ReSharper CTRL

    如下为个人比较常用的快捷键,部分快捷键有进行修改. 一.VS偏好设置: 1.转到定义:F12 2.查找所有引用:Shift + F12 3.跳转到指定的某一行:Ctrl + G (or 单击状态栏中的 ...

  4. forEach 列出数组的每个元素:

    数组.forEach便利所有的元素 array.forEach(function(currentValue, index, arr), thisValue) function(currentValue ...

  5. 面试官:精通 Mybatis?请回答下这几个问题

    点关注,不迷路:持续更新Java架构相关技术及资讯热文!!! Mybatis是现在非常主流的持久层框架,虽然平时用的多,但是其中几个细节的问题,能说出个所以然来不? 一.最常见,参数中 #{} 和 $ ...

  6. day09网络编程

    一 操作系统基础 操作系统:(Operating System,简称OS)是管理和控制计算机硬件与软件资源的计算机程序,是直接运行在“裸机”上的最基本的系统软件,任何其他软件都必须在操作系统的支持下才 ...

  7. word2016如何英汉互译

    1.如果是一篇英文文档且是pdf格式,可以用word2016打开直接转化成了word,就算不是会员也可以的,在此附上16版的光盘安装包,可以百度自行下载 (链接:https://pan.baidu.c ...

  8. 洛谷P3195 [HNOI2008]玩具装箱TOY 斜率优化

    Code: #include<cstdio> #include<algorithm> using namespace std; const int maxn = 100000 ...

  9. ToDoList(原生JS)了解一下

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. FFMpeg 常用命令格式转换,视频合成

    FFmpeg都是命令行的,用起来肯定不方便.但是,这对技术宅应该不成问题.下面,我就罗列一些比较实用的使用方法吧. FFmpeg的下载与安装 FFmpeg是开源的.但我们不必去下载它的源代码.下载已经 ...