RegularServer.class.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <?php
  2. namespace Common\Server;
  3. use Common\Server\BaseServer;
  4. /**
  5. * 正则表达式等相关 server
  6. */
  7. class RegularServer extends BaseServer {
  8. /**
  9. * 判断登录密码格式是否正确
  10. * @param type $password 登录密码
  11. * @return string4
  12. */
  13. public function check_password($password) {
  14. if(empty($password)){
  15. jsonReturn(1001, '密码不能为空');
  16. }
  17. $password = trim($password);
  18. if (!preg_match('/^(?=.*[^\d]).{6,16}$/', $password)) {
  19. jsonReturn(1032, '密码由6-16位非纯数字组成');
  20. } else {
  21. //判断是否包含中文
  22. if (preg_match("/[\x7f-\xff]/", $password)) {
  23. jsonReturn(1001, '密码请不要包含中文'); //含有中文
  24. }
  25. }
  26. return true;
  27. }
  28. /**
  29. * 判断登录密码格式是否正确
  30. * @param type $password 登录密码
  31. * @return string4
  32. */
  33. public function m_check_password($password) {
  34. if(empty($password)){
  35. return array('code' => 1001, 'msg' => '密码不能为空');
  36. }
  37. $password = trim($password);
  38. if (!preg_match('/^(?=.*[^\d]).{6,16}$/', $password)) {
  39. return array('code' => 1032, 'msg' => '密码由6-16位非纯数字组成');
  40. } else {
  41. //判断是否包含中文
  42. if (preg_match("/[\x7f-\xff]/", $password)) {
  43. return array('code' => 1001, 'msg' => '密码请不要包含中文');//含有中文
  44. }
  45. }
  46. return array('code' => 1000, 'msg' => '密码验证通过');
  47. }
  48. /**
  49. * 判断支付密码格式是否正确
  50. * @param type $password 登录密码
  51. * @return string4
  52. */
  53. public function check_pay_password($password) {
  54. if(empty($password)){
  55. jsonReturn(1001, '密码不能为空');
  56. }
  57. $password = trim($password);
  58. if (!preg_match('/^[0-9]\d{5}$/', $password)) {
  59. jsonReturn(1089, '支付密码由6位纯数字组成');
  60. } else {
  61. //判断是否包含中文
  62. if (preg_match("/[\x7f-\xff]/", $password)) {
  63. jsonReturn(1001, '支付密码请不要包含中文'); //含有中文
  64. }
  65. }
  66. return true;
  67. }
  68. /**
  69. * 验证用户名
  70. * @param $username
  71. */
  72. public function check_username($username) {
  73. $username = trim($username);
  74. if (preg_match("/\/|\~|\!|\@|\#|\\$|\%|\^|\&|\*|\(|\)|\_|\+|\{|\}|\:|\<|\>|\?|\[|\]|\,|\.|\/|\;|\'|\`|\-|\=|\\\|\|/", $username)) {
  75. jsonReturn(1001, '用户名不能包含特殊字符');
  76. }
  77. return true;
  78. }
  79. /**
  80. * 判断交易密码格式是否正确
  81. * @param type $password 交易密码
  82. * @return string
  83. */
  84. public function checkPayPwd($password) {
  85. $password = trim($password);
  86. //验证纯数字
  87. if (!preg_match('/^\d{6}$/', $password)) {
  88. return CpError(CP_ERROR, '支付密码由6位纯数字组成');
  89. } else {
  90. return CpSuccess('ok');
  91. }
  92. }
  93. /**
  94. * 判断手机号码是否正确
  95. * @param type $tel 手机号码
  96. * @return string
  97. */
  98. public function check_tel($tel) {
  99. $tel = trim($tel);
  100. if (!preg_match('/^1\d{10}$/', $tel)) {
  101. return false;
  102. } else {
  103. return true;
  104. }
  105. }
  106. /**
  107. * 判断身份证号码是否正确
  108. * @param type $card_id 手机号码
  109. * @return string
  110. */
  111. public function checkCardId($card_id) {
  112. $card_id = trim($card_id);
  113. if (!preg_match('/^[a-zA-Z0-9]{15,20}$/', $card_id)) {
  114. return CpError(CP_ERROR, '身份证号码不正确');
  115. } else {
  116. return CpSuccess('ok');
  117. }
  118. }
  119. /**
  120. * 判断银行卡号码是否正确
  121. * @param type $bank_id 身份证号码
  122. * @return string
  123. */
  124. public function checkBankNo($bank_id) {
  125. $bank_id = trim($bank_id);
  126. if (!preg_match('/^[0-9]{16,20}$/', $bank_id)) {
  127. return CpError(CP_ERROR, '银行卡号码不正确');
  128. } else {
  129. return CpSuccess('ok');
  130. }
  131. }
  132. /**
  133. * @param $username
  134. */
  135. public function check_user_name($username) {
  136. if(empty($username)){
  137. jsonReturn(B_USERNAME_NULL, '用户名不能为空');
  138. }
  139. $username = trim($username);
  140. if (!preg_match('/^(?=.*[^\d]).{1,50}$/', $username)) {
  141. jsonReturn(B_USERNAME_LETTER_NUM, '用户名必须由字母及数字组成');
  142. } else {
  143. //判断是否包含中文
  144. if (preg_match("/[\x7f-\xff]/", $username)) {
  145. jsonReturn(B_USERNAME_ZH, '用户名请不要包含中文'); //含有中文
  146. }
  147. }
  148. }
  149. /**
  150. * 判断手机号码是否正确
  151. * @param type $tel 手机号码
  152. */
  153. public function check_binsiness_tel($tel) {
  154. $tel = trim($tel);
  155. if (!preg_match('/^1\d{10}$/', $tel)) {
  156. jsonReturn(B_TEL_ERROR, '手机号码不正确');
  157. }
  158. }
  159. /**
  160. * 判断联系方式是否正确
  161. * @param type $tel 手机号码或座机号
  162. */
  163. public function check_contact_tel($tel) {
  164. $tel = trim($tel);
  165. if (preg_match('/^(0[0-9]{2,3}-)?([2-9][0-9]{6,7})+(-[0-9]{1,4})?$/', $tel)) {//判断座机号
  166. return true;
  167. }
  168. if (preg_match('/^1\d{10}$/', $tel)) {//判断手机号
  169. return true;
  170. }
  171. return false;
  172. }
  173. /**
  174. * 判断是否手机端访问
  175. * @author: linch
  176. * @return bool
  177. */
  178. function is_mobile_request() {
  179. $_SERVER['ALL_HTTP'] = isset($_SERVER['ALL_HTTP']) ? $_SERVER['ALL_HTTP'] : '';
  180. $mobile_browser = '0';
  181. if (preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|iphone|ipad|ipod|android|xoom)/i', strtolower($_SERVER['HTTP_USER_AGENT'])))
  182. $mobile_browser++;
  183. if ((isset($_SERVER['HTTP_ACCEPT'])) and (strpos(strtolower($_SERVER['HTTP_ACCEPT']), 'application/vnd.wap.xhtml+xml') !== false))
  184. $mobile_browser++;
  185. if (isset($_SERVER['HTTP_X_WAP_PROFILE']))
  186. $mobile_browser++;
  187. if (isset($_SERVER['HTTP_PROFILE']))
  188. $mobile_browser++;
  189. $mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'], 0, 4));
  190. $mobile_agents = array(
  191. 'w3c ', 'acs-', 'alav', 'alca', 'amoi', 'audi', 'avan', 'benq', 'bird', 'blac',
  192. 'blaz', 'brew', 'cell', 'cldc', 'cmd-', 'dang', 'doco', 'eric', 'hipt', 'inno',
  193. 'ipaq', 'java', 'jigs', 'kddi', 'keji', 'leno', 'lg-c', 'lg-d', 'lg-g', 'lge-',
  194. 'maui', 'maxo', 'midp', 'mits', 'mmef', 'mobi', 'mot-', 'moto', 'mwbp', 'nec-',
  195. 'newt', 'noki', 'oper', 'palm', 'pana', 'pant', 'phil', 'play', 'port', 'prox',
  196. 'qwap', 'sage', 'sams', 'sany', 'sch-', 'sec-', 'send', 'seri', 'sgh-', 'shar',
  197. 'sie-', 'siem', 'smal', 'smar', 'sony', 'sph-', 'symb', 't-mo', 'teli', 'tim-',
  198. 'tosh', 'tsm-', 'upg1', 'upsi', 'vk-v', 'voda', 'wap-', 'wapa', 'wapi', 'wapp',
  199. 'wapr', 'webc', 'winw', 'winw', 'xda', 'xda-'
  200. );
  201. if (in_array($mobile_ua, $mobile_agents))
  202. $mobile_browser++;
  203. if (strpos(strtolower($_SERVER['ALL_HTTP']), 'operamini') !== false)
  204. $mobile_browser++;
  205. // Pre-final check to reset everything if the user is on Windows
  206. if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows') !== false)
  207. $mobile_browser = 0;
  208. // But WP7 is also Windows, with a slightly different characteristic
  209. if (strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows phone') !== false)
  210. $mobile_browser++;
  211. if ($mobile_browser > 0)
  212. return true;
  213. else
  214. return false;
  215. }
  216. }