短信发送

短信发送驱动器SmsProcessor相关实现代码

//短信发送地址
var sendSmsUrl = "http://web.duanxinwang.cc/asmx/smsservice.aspx";
//获取短信配置
var smsAccount = getSmsConfigCacheValue("smsAccount");
var smsPass = getSmsConfigCacheValue("smsPassword");
var providerName = getSmsConfigCacheValue("provider");
//短信接口
function sendSms(mobile, content, type){
    if(mobile == null || mobile == ""){
      return "手机号码不能为空";
    }
    if(content == null || content == ""){
      return "短信内容不能为空";
    }
    var pamram = _webTools.jsonStringToMap("{}");
    if(smsAccount == null){
       var smsConfig = _db.findData("bmx-cms","SmsConfig","smsConfigId");
       smsAccount = smsConfig.get("interfaceAccount");
       smsPass = smsConfig.get("interfacePassword");
       providerName = smsConfig.get("provider");
      _cache.putCacheEntry("SMSCONFIGCACHE", "smsAcc", smsAccount);
       _cache.putCacheEntry("SMSCONFIGCACHE", "smsPass", smsPass);
       _cache.putCacheEntry("SMSCONFIGCACHE", "providerName", providerName);
    }
    pamram.put("name", smsAccount);
    pamram.put("pwd", smsPass);
    pamram.put("content", content);
    pamram.put("mobile", mobile);
    pamram.put("sign", "越诚云");
    pamram.put("type", "pt");
    var smsSendId = "";
    var message = "";
    var mobiles = mobile.split(",");
    var mobileCount = mobiles.length;
    try{
       var responseMessage = _http.sendPost(sendSmsUrl, pamram);
       var responseStatus = responseMessage.substring(0, responseMessage.indexOf(","))
       if(responseStatus == "0"){//发送成功
          var resMessages = responseMessage.split(",");
          message = resMessages[6];
          smsSendId = resMessages[1];
       }else{//发送失败
          message = responseMessage.substring(responseMessage.indexOf(",") + 1);
       }    
       for(var i=0;i
 

调用短信接口驱动器TestSmsProcessor代码

function run(){
   var resultMap = _webTools.jsonStringToMap("{}");
   var customer = _webParams.getSessionItem().get("PRINCIPAL_CUSTOMER_OBJECT");
   if(customer != null){
      var cId = customer.get("id");
      var phone = customer.get("MobilePhone");
      if(phone == null || phone == ""){
         resultMap.put("message", "您的手机信息不存在");
      }else{
         var validCode = getPhoneValidCode();        var content = "欢迎您注册会员,验证码"+ validCode +",验证成功后,您将拥有更多特权。";
         var sendResult = sendSms(phone, content, "PHONEVALID");
         if(sendResult == "success"){
            _webParams.getSessionItem().put(cId + "PV", validCode);
            resultMap.put("success", true);
         }else{
            resultMap.put("message", sendResult);
         }
      }
   }else{
      resultMap.put("message", "用户登录失效,请重新登录");
   }
   return resultMap;
}

//生成6位随机码
function getPhoneValidCode(){
   var validCode="";
   for(var i=0;i<6;i++){
     validCode+=Math.floor(Math.random()*10);
   }
   return validCode;
}

run();

模板页面发送短信验证码相关代码




	function sendPhoneValidCode(){
		var phoneNumber = $("#phoneNumber").val();
		if(strTrim(phoneNumber) == ""){
			alert("请输入手机号码");
			$("#phoneNumber").focus();
			return false;
		}
		$(".smsSendOpt").hide();
		$(".smsSendTips").show();
		jQuery.post(getUUIDURL("sendPhoneLoginCode"),{phoneNumber:phoneNumber}, function(data){
			if(data.message == "true"){
				alert("手机短信验证码已发送,请注意查收!");
			}else{
				alert(data.message);
			}
			$(".smsSendOpt").show();
			$(".smsSendTips").hide();
		});
	}