Send_sms_adminAction.class.php 17 KB

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