Send_sms_adminAction.class.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <?php
  2. /***
  3. * User: jun_hy
  4. * Date: 2022/7/5
  5. * Time: 16:24
  6. */
  7. /**
  8. * 短信发送,
  9. */
  10. require_once(ONU_ROOT . 'application/module/ctrl/Action.class.php');
  11. require_once(ONU_ROOT . 'application/lib/data/adminAction.php');
  12. header('content-Type: text/html; charset=utf-8');
  13. class Send_sms_adminAction extends Action
  14. {
  15. public function __construct()
  16. {
  17. parent::__construct();
  18. if (empty($_SESSION['mds_user'])) {
  19. header("Location:/?a=index&m=admin_login");
  20. exit();
  21. }
  22. }
  23. public function index()
  24. {
  25. $showtime = $_POST['demo_datetime'];
  26. $datetime=strtotime($showtime);
  27. if(empty($datetime)){
  28. $datetime=time();
  29. }
  30. $info = $_REQUEST['info'];
  31. $uid = $_SESSION['user_infos']['id'];
  32. $fromName = '';
  33. $from='';
  34. $fromDm='';
  35. switch ($uid) {
  36. case 6:
  37. $fromName = 'SuperNova Hair';
  38. $from = 'SuperNova';
  39. $fromDm='14582122478';
  40. break;
  41. case 1:
  42. $fromName = 'Alipearl Hair';
  43. $from = 'Alipearl';
  44. $fromDm='14582122378';
  45. break;
  46. case 3:
  47. $fromName = 'Westkiss Hair';
  48. $from = 'WestKissHair';
  49. $fromDm='14582071604';
  50. break;
  51. case 4:
  52. $fromName = 'Wiggins Hair';
  53. $from = 'WigginsHair';
  54. $fromDm='14582061730';
  55. break;
  56. case 5:
  57. $fromName = 'Asteria Hair';
  58. $from= 'AsteriaHair';
  59. $fromDm='14582026788';
  60. break;
  61. case 7:
  62. $fromName = 'Yolissa Hair';
  63. $from = 'YolissaHair';
  64. $fromDm='14582065939';
  65. break;
  66. case 8:
  67. $fromName = 'Mellow Hair';
  68. $from = 'Mellow';
  69. $fromDm='13013071900';
  70. break;
  71. }
  72. $admin = new AdvertAdminAction();
  73. //查询所有的邮件模板
  74. $where = "where uid='{$_SESSION['user_infos']['id']}' and type=1 and status=1";
  75. $template_list = $admin->select_smstm_list($where);
  76. //查询所有的用户分组
  77. $where2 = "where uid='$uid' ";
  78. $group_list = $admin->select_sms_user_group($where2);
  79. /*if(!empty($_POST['group_name']) && $_POST['group_name']!='all'){
  80. $where3.=" and group_name='{$_POST['group_name']}'";
  81. }
  82. $customer_list = $admin->selesctCustomer($where3);*/
  83. /*if(!empty($_POST['group_name']) && $_POST['group_name']!='all'){
  84. $where3.=" and group_name='{$_POST['group_name']}'";
  85. $customer_list = $admin->selesctCustomer($where3);
  86. }elseif(!empty($_POST['group_name']) && $_POST['group_name']=='all'){
  87. $customer_list = $admin->selesctCustomer($where2);
  88. }
  89. $count = count($customer_list);
  90. //假设一次只能给100个人发,看需要发几次
  91. $c = 100;
  92. $p = ceil($count/100);//需要发总次数*/
  93. $where3 = "where uid='$uid' and is_block=0 and is_send=1 ";
  94. if (!empty($_POST['group_name'])) {
  95. if ($_POST['group_name'] != 'all') {
  96. $where3 .= " and group_name='{$_POST['group_name']}'";
  97. $customer_list = $admin->selesctSmsCustomer($where3);
  98. } elseif ($_POST['group_name'] == 'all') {
  99. $customer_list = $admin->selesctSmsCustomer($where2);
  100. }
  101. $count = count($customer_list);
  102. $c = 100;
  103. $p = ceil($count/100);
  104. }
  105. if ($_POST['template_id']) {
  106. $id = $_POST['template_id'];
  107. $one_info = $admin->select_onesms_template($id);
  108. $content = str_replace("'", '', $one_info['msg_content']);
  109. for($i=1;$i<=$p;$i++){
  110. $min = $c*($i-1);
  111. $data = array();
  112. $x_smtpapi=array();
  113. $customer_list_now = array_slice($customer_list, $min, $c);
  114. foreach($customer_list_now as $key=>$list){
  115. $countryMobile = $this->getCountryMobile($list['country']);
  116. if($countryMobile==1){
  117. $data[$key]['from_name'] =$fromDm;
  118. }else{
  119. $data[$key]['from_name'] =$from;
  120. }
  121. $data[$key]['mobile'] =$countryMobile.$list['tel'];
  122. $appkey='FH1W2L97';
  123. $secretkey='OCio2JBh';
  124. if($uid==7){//--牛信云 yolissahair
  125. $x_smtpapi[] = $countryMobile.$list['tel'];
  126. $from=18332604755;
  127. $appkey='fm6S6TTz';
  128. $secretkey='PNQzoBIk';
  129. }
  130. if($uid==5){//--牛信云 asteriahair
  131. $x_smtpapi[] = $countryMobile.$list['tel'];
  132. $from=18332359525;
  133. $appkey='ss9jHs2r';
  134. $secretkey='XW7iy4uC';
  135. }
  136. if($uid==1){//--牛信云 alipearlhair
  137. $x_smtpapi[] = $countryMobile.$list['tel'];
  138. $from=18444795753;
  139. $appkey='qQcsCT7e';
  140. $secretkey='2Z9dyFyn';
  141. }
  142. if($uid==6){//--牛信云 supernovahair
  143. $x_smtpapi[] = $countryMobile.$list['tel'];
  144. $from=18444796463;
  145. $appkey='4CdNKjBj';
  146. $secretkey='lVd866Tx';
  147. }
  148. if($uid==3){//--牛信云 westkisshair
  149. $x_smtpapi[] = $countryMobile.$list['tel'];
  150. $from=18444797525;
  151. $appkey='MMoVdvdC';
  152. $secretkey='jlkPGrdi';
  153. }
  154. if($uid==4){//--牛信云 wigginshair
  155. $x_smtpapi[] = $countryMobile.$list['tel'];
  156. $from=18337593782;
  157. $appkey='FH1W2L97';
  158. $secretkey='OCio2JBh';
  159. }
  160. }
  161. $params = array(
  162. 'to' => $data,
  163. 'template_id' => $id,
  164. 'uid' => $uid,
  165. 'template_body' => $content
  166. );
  167. if($uid==7||$uid==1||$uid==6||$uid==3||$uid==4){//--牛信云
  168. if($uid==5){
  169. $params = array(
  170. 'appkey' => $appkey,
  171. 'secretkey' =>$secretkey,
  172. 'phone' => $x_smtpapi,
  173. 'content' => $content,
  174. // 'source_address' => $from,
  175. 'uid' => $uid
  176. );
  177. }else{
  178. $params = array(
  179. 'appkey' => $appkey,
  180. 'secretkey' =>$secretkey,
  181. 'phone' => $x_smtpapi,
  182. 'content' => $content,
  183. 'source_address' => $from,
  184. 'uid' => $uid
  185. );
  186. }
  187. }
  188. $params_arr[] = $params;
  189. }
  190. if($uid==7||$uid==1||$uid==6||$uid==3||$uid==4){
  191. $result = $admin->add_sms_data_queue_new($params_arr,$showtime,$datetime);
  192. }else{
  193. $result = $admin->add_sms_data_queue($params_arr,$showtime,$datetime);
  194. }
  195. if ($result) {
  196. $info = '短信已进入待发送队列';
  197. } else {
  198. $info = '短信发送失败';
  199. }
  200. header("Location:/?a=send_sms_admin&m=index&info=$info");
  201. exit();
  202. }
  203. $email = $admin->selectSmsTmpData();
  204. $this->assign('email_counts', $email[0]['ct']);
  205. $this->assign('group_list', $group_list);
  206. $this->assign('info', $info);
  207. $this->assign('template_list', $template_list);
  208. $this->display("index.html");
  209. }
  210. //过滤已加入分组美加用户州区号
  211. public function jinList(){
  212. $admin = new AdvertAdminAction();
  213. $where =" where is_send=0";
  214. $page=1;
  215. $pageSize=50;
  216. $city_code =$admin->selectCityCode() ;
  217. $new=array();
  218. foreach ($city_code as $v){
  219. $new[]=$v['code'];
  220. }
  221. $is_send=1;
  222. do {
  223. try {
  224. $n = ($page-1)*$pageSize;
  225. $limit = " $n,$pageSize";
  226. $customer_list = $admin->selesctSmsCustomer($where,$limit);
  227. foreach ($customer_list as $vs){
  228. $countryMobile = $this->getCountryMobile($vs['country']);
  229. if($countryMobile==1){
  230. $is_send =$this->getSend($vs['tel'],$new);
  231. }
  232. $admin->upCodeSmsCustomer($is_send,$vs['id']);
  233. }
  234. $page=$page+1;
  235. } catch (\Exception $e) {
  236. exit(1);
  237. }
  238. } while (is_array($customer_list) && !empty($customer_list));
  239. echo ' over~~';
  240. }
  241. public function getSend($mobile,$new)
  242. {
  243. $mobile= str_replace('-', '', $mobile);
  244. $mobile= str_replace('_', '', $mobile);
  245. $mobile= str_replace('(', '', $mobile);
  246. $mobile= str_replace(')', '', $mobile);
  247. $mobile= str_replace('+', '', $mobile);
  248. $mobile= str_replace(' ', '', $mobile);
  249. $mobile=trim($mobile);
  250. $lenth=strlen($mobile);
  251. $frist =(int)substr($mobile, 0, 1 );
  252. $code=0;
  253. if($lenth==10){
  254. $code = substr($mobile , 0 , 3);
  255. }
  256. if($lenth==11&&$frist==1){//例:14696305087
  257. $code = substr($mobile , 1 , 3);
  258. }
  259. $is_send=2;
  260. if($code){
  261. if (in_array($code, $new)) {
  262. $is_send=1;
  263. }
  264. }
  265. return $is_send;
  266. }
  267. public function getCountryMobile($countryCode){
  268. $country = $countryCode;
  269. $countrys_en = [ "China", "Afghanistan", "Albania", "Algera",
  270. "Andorra", "Angola", "Anguilla", "Ascension",
  271. "Antigua and Barbuda", "Argentina", "Armenia", "Aruba",
  272. "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain",
  273. "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin",
  274. "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegovina",
  275. "Botwana", "Brazill", "Brunei", "Bulgaria", "Burkina Faso",
  276. "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde",
  277. "Cayman Islands", "Central African Republic", "Chad", "Chile",
  278. "Colombia", "Comoros", "Republic of the Congo",
  279. "Democratic Republic of the Congo", "Cook Islands", "Costa Rica",
  280. "Cote divoire", "Croatia", "Cuba", "Cyprus", "+Czech Republic",
  281. "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador",
  282. "Egypt", "EISalvador", "Estonia", "Ethiopia", "Faroe Islands",
  283. "Fiji", "Finland", "France", "French Guiana", "French Polynesia",
  284. "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar",
  285. "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam",
  286. "Guatemala", "Guinea", "Guernsey", "Guinea", "Guyana", "Haiti",
  287. "Honduras", "Hong Kong", "Myanmar", "Hungary", "Iceland", "Indea",
  288. "Indonesia", "Iran", "Iraq", "Ireland", "Isle of Man", "Israel",
  289. "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazeakhstan",
  290. "Kenya", "Kosovo", "Kuwait", "Kyrgyzstan", "Laos", "Latvia",
  291. "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein",
  292. "Lithuania", "Luxembourg", "Macao", "Macedonia", "Madagascar",
  293. "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Martinique",
  294. "Mauritania", "Mauritius", "Mayotte", "Mexico", "Moldova",
  295. "Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco",
  296. "Mozambique", "Namibia", "Nepal", "Netherlands",
  297. "Netherlands Antillse", "New Caledonia", "NewZealand", "Nicaragua",
  298. "Niger", "Nigeria", "Norway", "Oman", "Pakistan", "Palestinian",
  299. "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines",
  300. "Poland", "Portugal", "PuertoRico", "Qotar", "Reunion", "Romania",
  301. "Russia", "Rwanda", "Samoa Eastern", "Samoa Western", "San Marino",
  302. "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia",
  303. "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia",
  304. "South Africa", "Korea", "Spain", "SriLanka", "St Kitts and Nevis",
  305. "St.Lucia", "St.Vincent", "Sudan", "Suriname", "Swaziland",
  306. "Sweden", "Switzerland", "Syria", "Taiwan", "Tajikistan",
  307. "Tanzania", "Thailand", "Timor Leste", "Togo", "Tonga",
  308. "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan",
  309. "Turks and Caicos Islands", "Uganda", "Ukraine",
  310. "United Arab Emirates", "United Kingdom", "USA", "Uruguay",
  311. "Uzbekistan", "Vanuatu", "Venezuela", "Vietnam", "Virgin Islands",
  312. "Yemen", "Zambia", "Zimbabwe" ];
  313. $countrys = array_keys($countrys_en,$country,true);
  314. if($countrys[0]){
  315. $countryMobile =$this->getCountryCode($countrys[0]);
  316. }else{
  317. $countryMobile ='+1';
  318. }
  319. $countryMobile = str_replace('+','',$countryMobile);
  320. return (int)$countryMobile;
  321. }
  322. //获取国家手机编号
  323. public function getCountryCode($countryCode){
  324. $codes = [ "+86", "+93", "+355", "+213", "+376", "+244", "+1264",
  325. "+247", "+1268", "+54", "+374", "+297", "+61", "+43", "+994",
  326. "+1242", "+973", "+880", "+1246", "+375", "+32", "+501", "+229",
  327. "+1441", "+975", "+591", "+387", "+267", "+55", "+673", "+359",
  328. "+226", "+257", "+855", "+237", "+1", "+238", "+1345", "+236",
  329. "+235", "+56", "+57", "+269", "+242", "+243", "+682", "+506",
  330. "+225", "+385", "+53", "+357", "+420", "+45", "+253", "+1767",
  331. "+1809", "+593", "+20", "+503", "+372", "+251", "+298", "+679",
  332. "+358", "+33", "+594", "+689", "+241", "+220", "+995", "+94",
  333. "+233", "+350", "+30", "+299", "+1473", "+590", "+1671", "+502",
  334. "+240", "+44", "+224", "+592", "+509", "+504", "+852", "+95",
  335. "+36", "+354", "+91", "+62", "+98", "+964", "+353", "+44", "+972",
  336. "+93", "+1876", "+81", "+44", "+962", "+7", "+254", "+383", "+965",
  337. "+996", "+856", "+371", "+961", "+266", "+231", "+218", "+423",
  338. "+370", "+352", "+853", "+389", "+261", "+265", "+60", "+960",
  339. "+223", "+356", "+596", "+222", "+230", "+262", "+52", "+373",
  340. "+377", "+976", "+382", "+1664", "+212", "+258", "+264", "+977",
  341. "+31", "+599", "+687", "+64", "+505", "+227", "+234", "+47",
  342. "+968", "+92", "+970", "+507", "+675", "+595", "+51", "+63", "+48",
  343. "+351", "+1", "+974", "+262", "+40", "+7", "+250", "+684", "+685",
  344. "+378", "+239", "+966", "+221", "+381", "+248", "+232", "+65",
  345. "+421", "+386", "+27", "+82", "+34", "+94", "+1869", "+1758",
  346. "+1784", "+249", "+597", "+268", "+46", "+41", "+963", "+886",
  347. "+992", "+255", "+66", "+670", "+228", "+676", "+1868", "+216",
  348. "+90", "+993", "+1649", "+256", "+380", "+971", "+44", "+1",
  349. "+598", "+998", "+678", "+58", "+84", "+1340", "+967", "+260",
  350. "+263" ];
  351. return $codes[$countryCode];
  352. }
  353. }