婚恋网手机认证接口

source/control/user/certify.php
<?php
public function control_sendcheckcode( )
{
	$service = parent::service( "certify", "us" );
	$mobile = $service->validMobile( );
	unset( $service );
	if ( $mobile == $this->u['mobile'] && $this->u['mobilerz'] == 1 )
	{
					XHandle::halt( "对不起,该手机号码已经通过验证,请不要重复操作。", "", 1 );
	}
	$model = parent::model( "certify", "um" );
	list( $result, $message ) = $mobile->doSendMobile( $mobile );
	unset( $model );
}

public function control_rzmobile( )
{
	$service = parent::service( "certify", "us" );
	list( $mobile, $salt ) = $service->validRzMobile( );
	unset( $service );
	$model = parent::model( "certify", "um" );
	$result = $model->doValidMobile( $mobile, $salt );
	unset( $model );
	if ( TRUE === $result )
	{
					if ( $this->halttype == "jdbox" )
					{
									XHandle::jqdialog( "手机号码验证成功", 1 );
					}
					else
					{
									XHandle::halt( "手机号码验证成功", $this->ucfile."?c=certify", 0 );
					}
	}
	else
	{
					XHandle::halt( "手机号码验证失败", "", 1 );
	}
}
?>
source/service/user/service.ceritfiy.php
<?php
public function validMobile( ){
	$mobile = XRequest::getargs( "mobile" );
	if ( FALSE === XValid::ismobile( $mobile ) )
	{
					XHandle::halt( "对不起,手机号码格式不正确", "", 1 );
	}
	return $mobile;
}

public function validRzMobile( ){
	$mobile = XRequest::getargs( "mobile" );
	$checkcode = XRequest::getargs( "checkcode" );
	if ( FALSE === XValid::ismobile( $mobile ) )
	{
		XHandle::halt( "手机号码格式不正确", "", 1 );
	}
	if ( FALSE === XValid::isnumber( $checkcode ) )
	{
		XHandle::halt( "手机验证码格式不正确", "", 1 );
	}
	return array(
		$mobile,
		$checkcode
	);
}
?>
source/model/user/model/model.ceritfiy.php
<?php
public function doSendMobile( $mobile ){
	$checkcode = XHandle::getrndchar( 6, 1 );
	parent::$obj->update( DB_PREFIX."user_status", array(
					"mobilesalt" => $checkcode
	), "userid='".parent::$wrap_user['userid']."'" );
	$model_am = parent::model( "sms", "am" );
	return $model_am->sendCheckCode( $mobile, $checkcode, array(
		"userid" => parent::$wrap_user['userid']
	));
}

public function doValidMobile( $mobile, $validkey ){
	$result = FALSE;
	$sql = "SELECT userid FROM ".DB_PREFIX.( "user_status WHERE mobilesalt='".$validkey."' AND userid='" ).parent::$wrap_user['userid']."'";
	$rows = parent::$obj->fetch_first( $sql );
	if ( !empty( $rows ) )
	{
		$status_array = array(
						"mobilerz" => 1,
						"mobilesalt" => XHandle::getrndchar( 6, 1 )
		);
		parent::$obj->update( DB_PREFIX."user_status", $status_array, "userid='".parent::$wrap_user['userid']."'" );
		$attr_array = array(
						"mobile" => $mobile
		);
		parent::$obj->update( DB_PREFIX."user_attr", $attr_array, "userid='".parent::$wrap_user['userid']."'" );
		parent::loadlib( "user" );
		$star = XUser::updatestar( parent::$wrap_user['userid'] );
		$result = TRUE;
		if ( TRUE === $result )
		{
						$m_indexs = parent::model( "indexs", "am" );
						$m_indexs->updateIndexs( parent::$wrap_user['userid'], array(
										"rzmobile" => 1,
										"star" => $star
						) );
						unset( $m_indexs );
		}
	}
	return $result;
}
?>
source/model/admin/model/model.sms.php							
<?php
if ( !defined( "IN_OESOFT" ) )
{
	exit( "Access Denied" );
}
class smsAModel extends X
{
	public function sendCheckCode($mobile,$checkcode,$userid){
		parent::loadutil( "session" );
		if(XSession::get("checkmobtime")==''){
			XSession::set("checkmobtime",time());
		}
		if (intval(XSession::get("checkmobtime"))+360 < time ()) { //将获取的缓存时间转换成时间戳加上360秒后与当前时间比较,小于当前时间即为过期
			XSession::del('checkmobtime');
			$success=false;
			$msg='请360秒之后重试';
		} else {
			$content = urlencode("[知音缘]您正在进行账号绑定操作,验证码是:" . $checkcode.",如非本人操作,请删除短信");
			$this->send_mobile($content, $mobile);
			$success=true;
			$msg='验证码发送成功';
		}
		return array($success,$msg);
	}
	public function send_mobile($content, $mobile) {
		$uid = '用户ID'; //--------------------------->>企业ID,请联系我们索取免费测试帐号
		$username = '用户名';
		$pwd = '密码'; //---------->>ID密码,要使用MD5加密为32位密文并转换为大写
		$httpstr = "http://www.sms626.com/sms.aspx?action=send&userid={$uid}&account={$username}&password={$pwd}&mobile={$mobile}&content={$content}&sendTime=&extno=";
		$result = $this->curl_file_get_contents( $httpstr );
	}
	public function curl_file_get_contents($durl){
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $durl);
		curl_setopt($ch, CURLOPT_TIMEOUT, 5);
		//curl_setopt($ch, CURLOPT_USERAGENT, _USERAGENT_);
		//curl_setopt($ch, CURLOPT_REFERER,_REFERER_);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		$r = curl_exec($ch);
		curl_close($ch);
		return $r;
	}
}
?>

/tpl/static/js/ajax.js
function ajax_getmbkey(mobile, tipid, button) {
	if (typeof(tipid) == "undefined") {
		tipid = ""
	};
	if (typeof(button) == "undefined") {
		button = ""
	};
	if (tipid != "") {
		$("#" + tipid).html("验证码发送中,请稍候...")
	};
	if (button != "") {
		$("#" + button).attr("disabled", true)
	};
	if (mobile > 0) {
		$.ajax({
			type: "POST",
			url: _ROOT_PATH + "index.php?c=ajax&a=getmbkey",
			cache: false,
			data: {
				mobile: mobile,
				r: get_rndnum(8)
			},
			dataType: "json",
			beforeSend: function(XMLHttpRequest) {
				XMLHttpRequest.setRequestHeader("request_type", "ajax")
			},
			success: function(data) {
				var json = eval(data);
				var response = json.response;
				var message = json.message;
				if (response == true) {
					if (message == "") {
						message = "验证码发送成功,请注意查收。"
					};
					if (tipid != "") {
						$("#" + tipid).html("<font color=green>" + message + "</font>")
					} else {
						alert(message)
					}
				} else {
					if (message == "") {
						message = "验证码发送失败"
					};
					if (tipid != "") {
						$("#" + tipid).html("<font color=red>" + message + "</font>")
					} else {
						alert(message)
					}
				}
			},
			error: function() {}
		})
	}
};

source/control/index/ajax.php
<?php
public function control_getmbkey( ){
	$this->_new( );
	$this->action->action_getmbkey( );
	$this->_unset( );
}
?>
source/action/index/action.ajax.php
<?php
public function action_getmbkey( ){
		$this->_new( );
		list( $mobile, $error ) = $this->service->validMobileKey( );
		$this->_unset( );
		$response = FALSE;
		if ( empty( $error ) )
		{
						$model = parent::model( "ajax", "im" );
						list( $result, $error ) = $model->ajaxGetMobileKey( $mobile );
						unset( $model );
						if ( $result == 0 )
						{
										$error = "会员数据不存在!";
						}
						else if ( $result == 1 )
						{
										$error = "该手机号码已认证!";
						}
						else if ( $result == 2 )
						{
										$response = TRUE;
										$error = "验证码发送成功,请注意查收";
						}
						else if ( empty( $error ) )
						{
										$error = "验证码发送失败";
						}
		}
		echo json_encode( array(
						"response" => $response,
						"message" => $error
		) );
}
?>
source/model/index/model.ajax.php
<?php
public function ajaxGetMobileKey($mobile) {
	$result = 0;
	$message = null;
	$me_sql = "SELECT v.mobile, s.mobilerz".
	" FROM ".DB_PREFIX."user_attr AS v".
	" LEFT JOIN ".DB_PREFIX."user_status AS s ON v.userid=s.userid".
	" WHERE v.userid='".parent::$wrap_user['userid']."'";
	$me_rows = parent::$obj->fetch_first($me_sql);
	if (!empty($me_rows)) {
		if ($mobile == $me_rows['mobile']) {
			if ($me_rows['mobilerz'] == 1) {
				$result = 1;
			}
		}
		if ($result != 1) {
			$checkcode = XHandle::getRndChar(6,1);
			parent::$obj->update(DB_PREFIX.'user_status',array('mobilesalt'=>$checkcode),"userid='".parent::$wrap_user['userid']."'");
			$m_sms = parent::model('sms','am');
			list($sms_result,$sms_message) = $m_sms->sendCheckCode($mobile,$checkcode,array('userid'=>parent::$wrap_user['userid']));
			unset($m_sms);
			if (true === $sms_result) {
				$result = 2;
			}
			else {
				$result = 3;
				$message = $sms_message;
			}
		}
	}
	unset($me_rows);
	unset($me_sql);
	return array($result,$message);
}
?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值