common.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. use think\Db;
  3. function getCountryMobile($countryCode){
  4. $where['country_id']=$countryCode;
  5. $lists = Db::name('directory_country')->where($where)->find();
  6. $countryMobile="9999";
  7. if($lists){
  8. $countryMobile =$lists['mobile_code'];
  9. }
  10. return (int)$countryMobile;
  11. }
  12. function checkMobile($countryMobile,$mobile,$countryCode)
  13. {
  14. $mobile= str_replace('-', '', $mobile);
  15. $mobile= str_replace('_', '', $mobile);
  16. $mobile= str_replace('(', '', $mobile);
  17. $mobile= str_replace(')', '', $mobile);
  18. $mobile= str_replace('+', '', $mobile);
  19. $mobile= str_replace(' ', '', $mobile);
  20. $mobile=trim($mobile);
  21. $lenth=strlen($mobile);
  22. $data['status']=5;//不发送
  23. $data['mobile']=$mobile;//不发送
  24. $frist =(int)substr($mobile, 0, 1 );
  25. if($countryMobile==1){//美国 加拿大
  26. $code=0;
  27. if($lenth==11&&$frist==1){//例:14696305087
  28. $data['mobile'] = $mobile;
  29. $code = substr($mobile , 1 , 3);
  30. //$data['status']=1;//待发送
  31. }
  32. if($lenth==10&&$frist!=1){
  33. $data['mobile'] = $countryMobile.$mobile;
  34. $code = substr($mobile , 0 , 3);
  35. //$data['status']=1;//待发送
  36. }
  37. if($code){
  38. $re=checkMobileCode($code);
  39. if($re){
  40. $data['status']=1;//待发送
  41. }
  42. }
  43. $data['sign']='13013071800';//签名
  44. }
  45. /*if($countryMobile==44){//UK
  46. if($lenth==10&&$frist==7){
  47. $data['mobile'] = $countryMobile.$mobile;
  48. $data['status']=1;//待发送
  49. }
  50. if($lenth==11&&$frist==0){
  51. $mobile =substr($mobile,1);
  52. $frists =(int)substr($mobile, 0, 1 );
  53. if($frists==7){
  54. $data['mobile'] = $countryMobile.$mobile;
  55. $data['status']=1;//待发送
  56. }
  57. }
  58. if($lenth==12&&$frist==4){
  59. $mobile=substr($mobile,2);
  60. $frists =(int)substr($mobile, 0, 1 );
  61. if($frists==7){
  62. $data['mobile'] = $countryMobile.$mobile;
  63. $data['status']=1;//待发送
  64. }
  65. }
  66. }
  67. if($countryMobile==33){//France
  68. if($lenth==9){
  69. if($frist==7||$frist==6){
  70. $data['mobile'] = $countryMobile.$mobile;
  71. $data['status']=1;//待发送
  72. }
  73. }
  74. if($lenth==10&&$frist==0){
  75. $mobile =substr($mobile,1);
  76. $frists =(int)substr($mobile, 0, 1 );
  77. if($frists==7||$frists==6){
  78. $data['mobile'] = $countryMobile.$mobile;
  79. $data['status']=1;//待发送
  80. }
  81. }
  82. if($lenth==11&&$frist==3){
  83. $mobile=substr($mobile,0,2);
  84. $frists =(int)substr($mobile, 0, 1 );
  85. if($frists==7||$frists==6){
  86. $data['mobile'] = $countryMobile.$mobile;
  87. $data['status']=1;//待发送
  88. }
  89. }
  90. }*/
  91. return $data;
  92. }
  93. function checkMobileCode($code){
  94. $lists = Db::name('directory_country_code')->select();
  95. $token=[];
  96. foreach ($lists as $v){
  97. $token[]=$v['code'];
  98. }
  99. if (in_array($code, $token)) {
  100. return true;
  101. }else{
  102. return false;
  103. }
  104. }