當前位置: 首頁>>代碼示例>>PHP>>正文


PHP String::randString方法代碼示例

本文整理匯總了PHP中String::randString方法的典型用法代碼示例。如果您正苦於以下問題:PHP String::randString方法的具體用法?PHP String::randString怎麽用?PHP String::randString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在String的用法示例。


在下文中一共展示了String::randString方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: index

 /**
  *
  */
 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");
 }
開發者ID:netsnail,項目名稱:201507guoshu,代碼行數:12,代碼來源:TestAccountApiController.class.php

示例2: GBVerify

 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);
 }
開發者ID:fengsmith1988,項目名稱:weixin-1,代碼行數:32,代碼來源:Image.class.php

示例3: buildFormatRand

 /**
  +----------------------------------------------------------
 *  帶格式生成隨機字符 支持批量生成
 *  但可能存在重複
  +----------------------------------------------------------
 * @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;
 }
開發者ID:BGCX262,項目名稱:ztoa-svn-to-git,代碼行數:43,代碼來源:String.class.php

示例4: store

 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'));
             }
         }
     }
 }
開發者ID:netsnail,項目名稱:201507guoshu,代碼行數:33,代碼來源:WxaccountController.class.php

示例5: postmessage

 /**
  * 發送驗證碼
  */
 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 = 'celllf';
     //$_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=' . urlencode($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 />';
                 }
             }
         }
     }
 }
開發者ID:ShengpouLai,項目名稱:aiyue,代碼行數:80,代碼來源:ShuMuAction.class.php

示例6: findpwSms

 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;
         }
     }
 }
開發者ID:ShengpouLai,項目名稱:aiyue,代碼行數:38,代碼來源:UserAction.class.php

示例7: buildDedeVerify

 /**
  * 生成圖像驗證碼(新加,可設置大小)
  * @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);
 }
開發者ID:gg1122,項目名稱:Dswjcms,代碼行數:49,代碼來源:Image.class.php


注:本文中的String::randString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。