public function actionSendMobileMess() { $sendMessage = new SendMessage(); $response = array(); $target = $this->request->getParam('target'); $user_name = $this->request->getParam('user_name'); $condition_user_name = array('condition' => 'nick_name = :nick_name OR phone_num = :phone_num', 'params' => array(':nick_name' => $user_name, ':phone_num' => $user_name)); if (!empty($user_name)) { $userList = $this->user_model->find($condition_user_name); $target = $userList->phone_num; } if (!$target) { $response['content'] = '请输入目标手机号'; $response['status'] = 100001; Yii::app()->end(FHelper::json($response['content'], $response['status'])); } if (empty($user_name)) { if (!$this->verifyPhone($target)) { $response['content'] = '该手机号已经被验证过来'; $response['status'] = 100002; Yii::app()->end(FHelper::json($response['content'], $response['status'])); } } $code = FHelper::generate_code(); $content = FConfig::item('siteMessage.register.first') . $code . FConfig::item('siteMessage.register.end'); $user = FConfig::item('config.ws_mobile.userName'); $pass = FConfig::item('config.ws_mobile.passWord'); //查询发送条数 $today = date('Y-m-d 0:0:0', time()); $condition = array('condition' => "mobile_no = '{$target}' and send_time >= '{$today}'"); $messageCount = $sendMessage->count($condition); if ($messageCount < 5) { Yii::import('ext.wsMobile.ws.*'); require_once 'ws-demo.php'; $engine = WS_SDK::getInstance($user, $pass); $res = $engine->sendSmsAsNormal($target, $content, '', 0); if (intval($res) === 0) { //短息发送成功对短信进行加密 $cryRes = Fn::crypt($code, FConfig::item('config.cookie.phone_code')); FCookie::set(FConfig::item('config.cookie.phone_key'), $cryRes); //放到cookie中 $response['status'] = 100000; $response['content'] = $target; // 短信发送成功 $telArr = array('mobile_no' => $target, 'mess_code' => $code, 'send_time' => FF_DATE_TIME); $sendMessage->attributes = $telArr; $sendMessage->save(); } else { $response['status'] = 100003; $response['content'] = '短信发送失败,请重试'; } } else { $response['status'] = 100004; $response['content'] = '该手机号码今天发送验证码过多'; } Yii::app()->end(FHelper::json($response['content'], $response['status'])); }
public function actionSendMsgPhone() { $sendMessage = new SendMessage(); $response = array(); $code = FHelper::generate_code(); $content = FConfig::item('siteMessage.register.first') . $code . FConfig::item('siteMessage.register.end'); $user = FConfig::item('config.ws_mobile.userName'); $pass = FConfig::item('config.ws_mobile.passWord'); $today = date('Y-m-d 0:0:0', time()); $condition = array('condition' => "mobile_no = '{$this->user['phone_num']}' and send_time >= '{$today}'"); $messageCount = $sendMessage->count($condition); if ($messageCount < 5) { Yii::import('ext.wsMobile.ws.*'); require_once 'ws-demo.php'; $engine = WS_SDK::getInstance($user, $pass); $res = $engine->sendSmsAsNormal($this->user['phone_num'], $content, '', 0); if (intval($res) === 0) { $cryRes = Fn::crypt($code, FConfig::item('config.cookie.phone_code')); FCookie::set(FConfig::item('config.cookie.phone_key'), $cryRes); $response['status'] = 100000; $response['content'] = '短信发送成功'; $telArr = array('mobile_no' => $this->user['phone_num'], 'mess_code' => $code, 'send_time' => FF_DATE_TIME); $sendMessage->attributes = $telArr; $sendMessage->save(); } else { $response['status'] = 100001; $response['content'] = '短信发送失败,请重试'; } } else { $response['status'] = 100002; $response['content'] = '该手机号码今天发送验证码过多'; } Yii::app()->end(FHelper::json($response['content'], $response['status'])); }