/** * */ public function index() { import("Org.String"); $username = \String::randString(9, 0); $password = \String::randString(6); $entity = ['username' => $username, 'password' => $password, 'from' => OAuth2TypeModel::OTHER_APP, 'email' => '', 'phone' => '']; $result = AccountApi::REGISTER($entity); $this->ajaxReturn($result, "xml"); }
static function GBVerify($length = 4, $type = 'png', $width = 180, $height = 50, $fontface = 'simhei.ttf', $verifyName = 'verify') { import('ORG.Util.String'); $code = String::randString($length, 4); $width = $length * 45 > $width ? $length * 45 : $width; session($verifyName, md5($code)); $im = imagecreatetruecolor($width, $height); $borderColor = imagecolorallocate($im, 100, 100, 100); //边框色 $bkcolor = imagecolorallocate($im, 250, 250, 250); imagefill($im, 0, 0, $bkcolor); @imagerectangle($im, 0, 0, $width - 1, $height - 1, $borderColor); // 干扰 for ($i = 0; $i < 15; $i++) { $fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); imagearc($im, mt_rand(-10, $width), mt_rand(-10, $height), mt_rand(30, 300), mt_rand(20, 200), 55, 44, $fontcolor); } for ($i = 0; $i < 255; $i++) { $fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $fontcolor); } if (!is_file($fontface)) { $fontface = dirname(__FILE__) . "/" . $fontface; } for ($i = 0; $i < $length; $i++) { $fontcolor = imagecolorallocate($im, mt_rand(0, 120), mt_rand(0, 120), mt_rand(0, 120)); //这样保证随机出来的颜色较深。 $codex = String::msubstr($code, $i, 1); imagettftext($im, mt_rand(16, 20), mt_rand(-60, 60), 40 * $i + 20, mt_rand(30, 35), $fontcolor, $fontface, $codex); } Image::output($im, $type); }
/** +---------------------------------------------------------- * 带格式生成随机字符 支持批量生成 * 但可能存在重复 +---------------------------------------------------------- * @param string $format 字符格式 * # 表示数字 * 表示字母和数字 $ 表示字母 * @param integer $number 生成数量 +---------------------------------------------------------- * @return string | array +---------------------------------------------------------- */ public static function buildFormatRand($format, $number = 1) { $str = array(); $length = strlen($format); for ($j = 0; $j < $number; $j++) { $strtemp = ''; for ($i = 0; $i < $length; $i++) { $char = substr($format, $i, 1); switch ($char) { case "*": //字母和数字混合 $strtemp .= String::randString(1); break; case "#": //数字 $strtemp .= String::randString(1, 1); break; case "\$": //大写字母 $strtemp .= String::randString(1, 2); break; default: //其他格式均不转换 $strtemp .= $char; break; } } $str[] = $strtemp; } return $number == 1 ? $strtemp : $str; }
public function store() { if (IS_POST) { import("Org.String"); $id = I('post.id', 0, 'intval'); $len = 43; $EncodingAESKey = I('post.encodingAESKey', ''); if (empty($EncodingAESKey)) { $EncodingAESKey = \String::randString($len, 0, '0123456789'); } $tokenvalue = \String::randString(8, 3); $entity = array('wxname' => I('post.wxname', ''), 'appid' => I('post.appid'), 'appsecret' => I('post.appsecret'), 'weixin' => I('post.weixin'), 'headerpic' => I('post.headerpic', ''), 'qrcode' => I('post.qrcode', ''), 'wxuid' => I('post.wxuid'), 'encodingAESKey' => $EncodingAESKey); if (!empty($id) && $id > 0) { $result = apiCall(WxaccountApi::SAVE_BY_ID, array($id, $entity)); if ($result['status'] === false) { LogRecord('INFO:' . $result['info'], '[FILE] ' . __FILE__ . ' [LINE] ' . __LINE__); $this->error($result['info']); } else { $this->success(L('RESULT_SUCCESS'), U('Admin/Wxaccount/edit')); } } else { $entity['uid'] = UID; $entity['token'] = $tokenvalue . time(); $result = apiCall(WxaccountApi::ADD, array($entity)); if ($result['status'] === false) { LogRecord('INFO:' . $result['info'], '[FILE] ' . __FILE__ . ' [LINE] ' . __LINE__); $this->error($result['info']); } else { $this->success(L('RESULT_SUCCESS'), U('Admin/Wxaccount/edit')); } } } }
/** * 发送验证码 */ public function postmessage() { import('ORG.Util.String'); $randval = String::randString(6, 1); $content = '尊敬的客户,您的验证码为' . $randval . '。【爱阅公益阅芽计划】'; $ml = M('regsms'); if (isset($_POST['del'])) { $flag = $ml->where(array('mobile' => $_POST['mobile']))->delete(); if (false !== $flag) { print_r(json_encode(array("status" => 0))); exit; } else { print_r(json_encode(array('status' => 1))); exit; } } else { $ml = M('regsms'); $data['mobile'] = $_POST['mobile']; $data['smsCode'] = $randval; $flag = $ml->add($data); } $retinfo = ''; $xmlstring = ''; $info = ''; $xmlstring = ''; $userid = '93122'; //$_POST['userid'] ? $_POST['userid'] : false; $password = '******'; //$_POST['password'] ? $_POST['password'] : false; $msg = $content; //$_POST['msg'] ? $_POST['msg'] : false; $destnumbers = $_POST['mobile'] ? $_POST['mobile'] : false; $sendtime = $_POST['sendtime'] ? $_POST['sendtime'] : false; if ($userid && $password && $destnumbers && $msg) { $qUrl = "http://183.61.109.140:9801/CASServer/SmsAPI/SendMessage.jsp"; $qUrl .= '?userid=' . $userid . '&password='******'&destnumbers=' . $destnumbers . '&msg=' . urlencode($msg) . '&sendtime=' . $sendtime; if (function_exists('file_get_contents')) { //(PHP 4 >= 4.3.0, PHP 5) $xmlstring = file_get_contents($qUrl); } else { if (function_exists('fopen')) { //(PHP 3, PHP 4, PHP 5) $fopenXML = fopen($qUrl, 'r'); if ($fopenXML) { while (!feof($fopenXML)) { $xmlstring .= fgets($fopenXML, 4096); } fclose($fopenXML); } } } if ($xmlstring && trim($xmlstring)) { if (function_exists('simplexml_load_string')) { //PHP5.0以上版本(PHP 5) $xml = simplexml_load_string($xmlstring); $retinfo = $xml['return'] . ',' . $xml['info']; if ('' . $xml['return'] === '0') { $info = '总计号码个数:' . $xml['numbers'] . '<br />'; $info .= '总计短信条数:' . $xml['messages'] . '<br />'; } //将验证码存放在session session('checkCode', null); session('checkCode', $randval); } else { //PHP5.0以下版本 require_once 'xml2Array.class.php'; $objXML = new xml2Array(); $arrOutput = $objXML->parse($xmlstring); $retinfo = $arrOutput[0]['attrs']['RETURN'] . ',' . $arrOutput[0]['attrs']['INFO']; if ('' . $arrOutput[0]['attrs']['RETURN'] === "0") { $info = '总计号码个数:' . $arrOutput[0]['attrs']['NUMBERS'] . '<br />'; $info .= '总计短信条数:' . $arrOutput[0]['attrs']['MESSAGES'] . '<br />'; } } } } }
public function findpwSms() { $ml = M('regsms'); if (isset($_POST['del'])) { $flag = $ml->where(array('mobile' => $_POST['mobile']))->delete(); if (false !== $flag) { print_r(json_encode(array("status" => 0))); exit; } else { print_r(json_encode(array('status' => 1))); exit; } } else { import('ORG.Util.String'); $randval = String::randString(6, 1); $content = "你的验证码是:" . $randval; $content = iconv("UTF-8", "GBK", $content); $result = $this->sendSMS($_POST['mobile'], $content); if (isset($result[2])) { $resultArr = explode(":", iconv("GBK", "UTF-8", $result[2])); if ('success' == $resultArr[0]) { $flag = $ml->where(array('mobile' => $_POST['mobile']))->select(); if (null != $flag) { $ml->where(array('mobile' => $_POST['mobile']))->delete(); } $ml->add(array("mobile" => $_POST['mobile'], "smsCode" => $randval, 'time' => time() + 60 * 10)); print_r(json_encode(array("status" => 0))); exit; } else { print_r(json_encode(array("status" => 1))); exit; } } else { print_r(json_encode(array("status" => 1))); exit; } } }
/** * 生成图像验证码(新加,可设置大小) * @static * @access public * @param string $length 位数 * @param string $mode 类型 //0:混合 1:数字 2:英文大写 3:英文小写 4:中文 * @param string $type 图像格式 * @param string $width 宽度 * @param string $height 高度 * @return string */ static function buildDedeVerify($length = 4, $mode = 1, $type = 'png', $width = 64, $height = 28, $verifyName = 'verify', $font_size = 14) { import('ORG.Util.String'); $randval = String::randString($length, $mode); session($verifyName, md5(strtoupper($randval))); //主要参数 $font_file = EXTEND_PATH . 'Fonts/ggbi.ttf'; //创建图片,并设置背景色 $im = @imagecreate($width, $height); imagecolorallocate($im, 255, 255, 255); //文字随机颜色 $fontColor[] = imagecolorallocate($im, 0x15, 0x15, 0x15); $fontColor[] = imagecolorallocate($im, 0x95, 0x1e, 0x4); $fontColor[] = imagecolorallocate($im, 0x93, 0x14, 0xa9); $fontColor[] = imagecolorallocate($im, 0x12, 0x81, 0xa); $fontColor[] = imagecolorallocate($im, 0x6, 0x3a, 0xd5); //背景横线 $lineColor1 = imagecolorallocate($im, 0xda, 0xd9, 0xd1); for ($j = 3; $j <= $height - 3; $j = $j + 3) { imageline($im, 2, $j, $width - 2, $j, $lineColor1); } //背景竖线 $lineColor2 = imagecolorallocate($im, 0xda, 0xd9, 0xd1); for ($j = 2; $j < 100; $j = $j + 6) { imageline($im, $j, 0, $j + 8, $height, $lineColor2); } $bordercolor = imagecolorallocate($im, 0x9d, 0x9e, 0x96); imagerectangle($im, 0, 0, $width - 1, $height - 1, $bordercolor); //输出文字 for ($i = 0; $i < $length; $i++) { $bc = mt_rand(0, 1); $stringColor = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120)); $y_pos = $i == 0 ? ($width - $font_size * $length) / 2 : ($width - $font_size * $length) / 2 + $i * ($font_size + 2); $c = mt_rand(0, 32); @imagettftext($im, $font_size, $c, $y_pos, ($height + $font_size) / 2, $stringColor, $font_file, $randval[$i]); } Image::output($im, $type); }