/** * 短信验证码,用于注册 * @author jry <*****@*****.**> */ public function sendMobileVerify() { $receiver = I('post.mobile'); $user_object = D('User'); $result = $user_object->create($_POST, 5); //调用自动验证 if (!$result) { $this->error($user_object->getError()); } $reg_verify = \Org\Util\String::randString(6, 1); //生成验证码 session('reg_verify', user_md5($reg_verify, $receiver)); $body = $title . '验证码:' . $reg_verify; if (send_mobile_message($receiver, $title, $body)) { $this->success('发送成功,请查收!'); } else { $this->error('发送失败!'); } }
<?php error_reporting(~E_NOTICE & E_ALL); require 'IQueue.php'; require 'RabbitQueue.php'; require 'MemcachedQueue.php'; require 'MongodbQueue.php'; require 'RedisQueue.php'; require 'MessageQueueProxy.php'; $config = (require 'config.php'); $class = $config['driver']; $mq = new $class($config['driverInfo']); $mobileMessageObj = new MessageQueueProxy($mq); $num = 10000; echo $start = microtime(true); for ($i = 0; $i < $num; ++$i) { $message = $mobileMessageObj->pop(); if (empty($message)) { break; } $messageInfo = $message; send_mobile_message($messageInfo['mobile'], $messageInfo['content']); } echo " -- times: {$num} takes: ", microtime(true) - $start, "s size: ", $mobileMessageObj->size(), "\n"; function send_mobile_message($mobile, $content) { usleep(1000); //0.001s }
/** * 短信验证码,用于注册 * @author jry <*****@*****.**> */ public function sendMobileVerify() { $user_object = D('User'); $result = $user_object->create($_POST, 5); //调用自动验证 if (!$result) { $this->error($user_object->getError()); } //生成验证码 $reg_verify = \Org\Util\String::randString(6, 1); session('reg_verify', user_md5($reg_verify, I('post.mobile'))); //构造短信数据 $msg_data['receiver'] = I('post.mobile'); $msg_data['message'] = '短信验证码:' . $reg_verify; if (send_mobile_message($msg_data)) { $this->success('发送成功,请查收!'); } else { $this->error('发送失败!'); } }