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); } ?>