common.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. $country = $lists['iso2_code'];
  7. $countrys_en = [ "China", "Afghanistan", "Albania", "Algera",
  8. "Andorra", "Angola", "Anguilla", "Ascension",
  9. "Antigua and Barbuda", "Argentina", "Armenia", "Aruba",
  10. "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain",
  11. "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin",
  12. "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegovina",
  13. "Botwana", "Brazill", "Brunei", "Bulgaria", "Burkina Faso",
  14. "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde",
  15. "Cayman Islands", "Central African Republic", "Chad", "Chile",
  16. "Colombia", "Comoros", "Republic of the Congo",
  17. "Democratic Republic of the Congo", "Cook Islands", "Costa Rica",
  18. "Cote divoire", "Croatia", "Cuba", "Cyprus", "+Czech Republic",
  19. "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador",
  20. "Egypt", "EISalvador", "Estonia", "Ethiopia", "Faroe Islands",
  21. "Fiji", "Finland", "France", "French Guiana", "French Polynesia",
  22. "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar",
  23. "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam",
  24. "Guatemala", "Guinea", "Guernsey", "Guinea", "Guyana", "Haiti",
  25. "Honduras", "Hong Kong", "Myanmar", "Hungary", "Iceland", "Indea",
  26. "Indonesia", "Iran", "Iraq", "Ireland", "Isle of Man", "Israel",
  27. "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazeakhstan",
  28. "Kenya", "Kosovo", "Kuwait", "Kyrgyzstan", "Laos", "Latvia",
  29. "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein",
  30. "Lithuania", "Luxembourg", "Macao", "Macedonia", "Madagascar",
  31. "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Martinique",
  32. "Mauritania", "Mauritius", "Mayotte", "Mexico", "Moldova",
  33. "Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco",
  34. "Mozambique", "Namibia", "Nepal", "Netherlands",
  35. "Netherlands Antillse", "New Caledonia", "NewZealand", "Nicaragua",
  36. "Niger", "Nigeria", "Norway", "Oman", "Pakistan", "Palestinian",
  37. "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines",
  38. "Poland", "Portugal", "PuertoRico", "Qotar", "Reunion", "Romania",
  39. "Russia", "Rwanda", "Samoa Eastern", "Samoa Western", "San Marino",
  40. "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia",
  41. "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia",
  42. "South Africa", "Korea", "Spain", "SriLanka", "St Kitts and Nevis",
  43. "St.Lucia", "St.Vincent", "Sudan", "Suriname", "Swaziland",
  44. "Sweden", "Switzerland", "Syria", "Taiwan", "Tajikistan",
  45. "Tanzania", "Thailand", "Timor Leste", "Togo", "Tonga",
  46. "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan",
  47. "Turks and Caicos Islands", "Uganda", "Ukraine",
  48. "United Arab Emirates", "United Kingdom", "USA", "Uruguay",
  49. "Uzbekistan", "Vanuatu", "Venezuela", "Vietnam", "Virgin Islands",
  50. "Yemen", "Zambia", "Zimbabwe" ];
  51. $countrys = array_keys($countrys_en,$country,true);
  52. if(empty($countrys)){
  53. $country=$lists['iso3_code'];
  54. $countrys =array_keys($countrys_en,$country,true);
  55. }
  56. if(isset($countrys[0])){
  57. $countryMobile =getCountryCode($countrys[0]);
  58. }else{
  59. $countryMobile ='+9';
  60. }
  61. $countryMobile = str_replace('+','',$countryMobile);
  62. return (int)$countryMobile;
  63. }
  64. //获取国家手机编号
  65. function getCountryCode($countryCode){
  66. $codes = [ "+86", "+93", "+355", "+213", "+376", "+244", "+1264",
  67. "+247", "+1268", "+54", "+374", "+297", "+61", "+43", "+994",
  68. "+1242", "+973", "+880", "+1246", "+375", "+32", "+501", "+229",
  69. "+1441", "+975", "+591", "+387", "+267", "+55", "+673", "+359",
  70. "+226", "+257", "+855", "+237", "+1", "+238", "+1345", "+236",
  71. "+235", "+56", "+57", "+269", "+242", "+243", "+682", "+506",
  72. "+225", "+385", "+53", "+357", "+420", "+45", "+253", "+1767",
  73. "+1809", "+593", "+20", "+503", "+372", "+251", "+298", "+679",
  74. "+358", "+33", "+594", "+689", "+241", "+220", "+995", "+94",
  75. "+233", "+350", "+30", "+299", "+1473", "+590", "+1671", "+502",
  76. "+240", "+44", "+224", "+592", "+509", "+504", "+852", "+95",
  77. "+36", "+354", "+91", "+62", "+98", "+964", "+353", "+44", "+972",
  78. "+93", "+1876", "+81", "+44", "+962", "+7", "+254", "+383", "+965",
  79. "+996", "+856", "+371", "+961", "+266", "+231", "+218", "+423",
  80. "+370", "+352", "+853", "+389", "+261", "+265", "+60", "+960",
  81. "+223", "+356", "+596", "+222", "+230", "+262", "+52", "+373",
  82. "+377", "+976", "+382", "+1664", "+212", "+258", "+264", "+977",
  83. "+31", "+599", "+687", "+64", "+505", "+227", "+234", "+47",
  84. "+968", "+92", "+970", "+507", "+675", "+595", "+51", "+63", "+48",
  85. "+351", "+1", "+974", "+262", "+40", "+7", "+250", "+684", "+685",
  86. "+378", "+239", "+966", "+221", "+381", "+248", "+232", "+65",
  87. "+421", "+386", "+27", "+82", "+34", "+94", "+1869", "+1758",
  88. "+1784", "+249", "+597", "+268", "+46", "+41", "+963", "+886",
  89. "+992", "+255", "+66", "+670", "+228", "+676", "+1868", "+216",
  90. "+90", "+993", "+1649", "+256", "+380", "+971", "+44", "+1",
  91. "+598", "+998", "+678", "+58", "+84", "+1340", "+967", "+260",
  92. "+263" ];
  93. return $codes[$countryCode];
  94. }
  95. function checkMobile($countryMobile,$mobile,$countryCode)
  96. {
  97. $mobile= str_replace('-', '', $mobile);
  98. $mobile= str_replace('_', '', $mobile);
  99. $mobile= str_replace('(', '', $mobile);
  100. $mobile= str_replace(')', '', $mobile);
  101. $mobile= str_replace('+', '', $mobile);
  102. $mobile= str_replace(' ', '', $mobile);
  103. $mobile=trim($mobile);
  104. $lenth=strlen($mobile);
  105. $data['status']=5;//不发送
  106. $data['mobile']=$mobile;//不发送
  107. $frist =(int)substr($mobile, 0, 1 );
  108. if($countryMobile==1){//美国 加拿大
  109. $code=0;
  110. if($lenth==11&&$frist==1){//例:14696305087
  111. $data['mobile'] = $mobile;
  112. $code = substr($mobile , 1 , 3);
  113. //$data['status']=1;//待发送
  114. }
  115. if($lenth==10&&$frist!=1){
  116. $data['mobile'] = $countryMobile.$mobile;
  117. $code = substr($mobile , 0 , 3);
  118. //$data['status']=1;//待发送
  119. }
  120. if($code){
  121. $re=checkMobileCode($code);
  122. if($re){
  123. $data['status']=1;//待发送
  124. }
  125. }
  126. $data['sign']='13013071800';//签名
  127. }
  128. if($countryMobile==44){//UK
  129. if($lenth==10&&$frist==7){
  130. $data['mobile'] = $countryMobile.$mobile;
  131. $data['status']=1;//待发送
  132. }
  133. if($lenth==11&&$frist==0){
  134. $mobile =substr($mobile,1);
  135. $frists =(int)substr($mobile, 0, 1 );
  136. if($frists==7){
  137. $data['mobile'] = $countryMobile.$mobile;
  138. $data['status']=1;//待发送
  139. }
  140. }
  141. if($lenth==12&&$frist==4){
  142. $mobile=substr($mobile,2);
  143. $frists =(int)substr($mobile, 0, 1 );
  144. if($frists==7){
  145. $data['mobile'] = $countryMobile.$mobile;
  146. $data['status']=1;//待发送
  147. }
  148. }
  149. }
  150. if($countryMobile==33){//France
  151. if($lenth==9){
  152. if($frist==7||$frist==6){
  153. $data['mobile'] = $countryMobile.$mobile;
  154. $data['status']=1;//待发送
  155. }
  156. }
  157. if($lenth==10&&$frist==0){
  158. $mobile =substr($mobile,1);
  159. $frists =(int)substr($mobile, 0, 1 );
  160. if($frists==7||$frists==6){
  161. $data['mobile'] = $countryMobile.$mobile;
  162. $data['status']=1;//待发送
  163. }
  164. }
  165. if($lenth==11&&$frist==3){
  166. $mobile=substr($mobile,0,2);
  167. $frists =(int)substr($mobile, 0, 1 );
  168. if($frists==7||$frists==6){
  169. $data['mobile'] = $countryMobile.$mobile;
  170. $data['status']=1;//待发送
  171. }
  172. }
  173. }
  174. return $data;
  175. }
  176. function checkMobileCode($code){
  177. $lists = Db::name('directory_country_code')->select();
  178. $token=[];
  179. foreach ($lists as $v){
  180. $token[]=$v['code'];
  181. }
  182. if (in_array($code, $token)) {
  183. return true;
  184. }else{
  185. return false;
  186. }
  187. }