Send_sms_adminAction.class.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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='13013071900';
  40. break;
  41. case 1:
  42. $fromName = 'Alipearl Hair';
  43. $from = 'Alipearl';
  44. $fromDm='13013071900';
  45. break;
  46. case 3:
  47. $fromName = 'Westkiss Hair';
  48. $from = 'WestKissHair';
  49. $fromDm='13013071800';
  50. break;
  51. case 4:
  52. $fromName = 'Wiggins Hair';
  53. $from = 'WigginsHair';
  54. $fromDm='13013071800';
  55. break;
  56. case 5:
  57. $fromName = 'Asteria Hair';
  58. $from= 'AsteriaHair';
  59. $fromDm='13013071800';
  60. break;
  61. case 7:
  62. $fromName = 'Yolissa Hair';
  63. $from = 'YolissaHair';
  64. $fromDm='13013071900';
  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='4CdNKjBj';
  134. $secretkey='lVd866Tx';
  135. }
  136. if($uid==1){//--牛信云 alipearlhair
  137. $x_smtpapi[] = $countryMobile.$list['tel'];
  138. $from=18447116894;
  139. $appkey='qQcsCT7e';
  140. $secretkey='2Z9dyFyn';
  141. }
  142. if($uid==6){//--牛信云 supernovahair
  143. $x_smtpapi[] = $countryMobile.$list['tel'];
  144. $from=18447117128;
  145. $appkey='4CdNKjBj';
  146. $secretkey='lVd866Tx';
  147. }
  148. if($uid==3){//--牛信云 westkisshair
  149. $x_smtpapi[] = $countryMobile.$list['tel'];
  150. $from=18333170164;
  151. $appkey='FH1W2L97';
  152. $secretkey='OCio2JBh';
  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==5||$uid==3||$uid==4){//--牛信云
  168. $params = array(
  169. 'appkey' => $appkey,
  170. 'secretkey' =>$secretkey,
  171. 'phone' => $x_smtpapi,
  172. 'content' => $content,
  173. 'source_address' => $from,
  174. 'uid' => $uid
  175. );
  176. }
  177. $params_arr[] = $params;
  178. }
  179. if($uid==7||$uid==1||$uid==6||$uid==5||$uid==3||$uid==4){
  180. $result = $admin->add_sms_data_queue_new($params_arr,$showtime,$datetime);
  181. }else{
  182. $result = $admin->add_sms_data_queue($params_arr,$showtime,$datetime);
  183. }
  184. if ($result) {
  185. $info = '短信已进入待发送队列';
  186. } else {
  187. $info = '短信发送失败';
  188. }
  189. header("Location:/?a=send_sms_admin&m=index&info=$info");
  190. exit();
  191. }
  192. $email = $admin->selectSmsTmpData();
  193. $this->assign('email_counts', $email[0]['ct']);
  194. $this->assign('group_list', $group_list);
  195. $this->assign('info', $info);
  196. $this->assign('template_list', $template_list);
  197. $this->display("index.html");
  198. }
  199. //过滤已加入分组美加用户州区号
  200. public function jinList(){
  201. $admin = new AdvertAdminAction();
  202. $where =" where is_send=0";
  203. $page=1;
  204. $pageSize=50;
  205. $city_code =$admin->selectCityCode();
  206. $new=array();
  207. foreach ($city_code as $v){
  208. $new[]=$v['code'];
  209. }
  210. $is_send=1;
  211. do {
  212. try {
  213. $n = ($page-1)*$pageSize;
  214. $limit = " $n,$pageSize";
  215. $customer_list = $admin->selesctSmsCustomer($where,$limit);
  216. foreach ($customer_list as $vs){
  217. $countryMobile = $this->getCountryMobile($vs['country']);
  218. if($countryMobile==1){
  219. $code = substr($vs['tel'] , 0 , 3);
  220. if (in_array($code, $new)) {
  221. $is_send=1;
  222. }else{
  223. $is_send=2;
  224. }
  225. }
  226. $admin->upCodeSmsCustomer($is_send,$vs['id']);
  227. }
  228. $page=$page+1;
  229. } catch (\Exception $e) {
  230. exit(1);
  231. }
  232. } while (is_array($customer_list) && !empty($customer_list));
  233. echo ' over~~';
  234. }
  235. public function getCountryMobile($countryCode){
  236. $country = $countryCode;
  237. $countrys_en = [ "China", "Afghanistan", "Albania", "Algera",
  238. "Andorra", "Angola", "Anguilla", "Ascension",
  239. "Antigua and Barbuda", "Argentina", "Armenia", "Aruba",
  240. "Australia", "Austria", "Azerbaijan", "Bahamas", "Bahrain",
  241. "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin",
  242. "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegovina",
  243. "Botwana", "Brazill", "Brunei", "Bulgaria", "Burkina Faso",
  244. "Burundi", "Cambodia", "Cameroon", "Canada", "Cape Verde",
  245. "Cayman Islands", "Central African Republic", "Chad", "Chile",
  246. "Colombia", "Comoros", "Republic of the Congo",
  247. "Democratic Republic of the Congo", "Cook Islands", "Costa Rica",
  248. "Cote divoire", "Croatia", "Cuba", "Cyprus", "+Czech Republic",
  249. "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador",
  250. "Egypt", "EISalvador", "Estonia", "Ethiopia", "Faroe Islands",
  251. "Fiji", "Finland", "France", "French Guiana", "French Polynesia",
  252. "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar",
  253. "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam",
  254. "Guatemala", "Guinea", "Guernsey", "Guinea", "Guyana", "Haiti",
  255. "Honduras", "Hong Kong", "Myanmar", "Hungary", "Iceland", "Indea",
  256. "Indonesia", "Iran", "Iraq", "Ireland", "Isle of Man", "Israel",
  257. "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazeakhstan",
  258. "Kenya", "Kosovo", "Kuwait", "Kyrgyzstan", "Laos", "Latvia",
  259. "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein",
  260. "Lithuania", "Luxembourg", "Macao", "Macedonia", "Madagascar",
  261. "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Martinique",
  262. "Mauritania", "Mauritius", "Mayotte", "Mexico", "Moldova",
  263. "Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco",
  264. "Mozambique", "Namibia", "Nepal", "Netherlands",
  265. "Netherlands Antillse", "New Caledonia", "NewZealand", "Nicaragua",
  266. "Niger", "Nigeria", "Norway", "Oman", "Pakistan", "Palestinian",
  267. "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines",
  268. "Poland", "Portugal", "PuertoRico", "Qotar", "Reunion", "Romania",
  269. "Russia", "Rwanda", "Samoa Eastern", "Samoa Western", "San Marino",
  270. "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Serbia",
  271. "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia",
  272. "South Africa", "Korea", "Spain", "SriLanka", "St Kitts and Nevis",
  273. "St.Lucia", "St.Vincent", "Sudan", "Suriname", "Swaziland",
  274. "Sweden", "Switzerland", "Syria", "Taiwan", "Tajikistan",
  275. "Tanzania", "Thailand", "Timor Leste", "Togo", "Tonga",
  276. "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan",
  277. "Turks and Caicos Islands", "Uganda", "Ukraine",
  278. "United Arab Emirates", "United Kingdom", "USA", "Uruguay",
  279. "Uzbekistan", "Vanuatu", "Venezuela", "Vietnam", "Virgin Islands",
  280. "Yemen", "Zambia", "Zimbabwe" ];
  281. $countrys = array_keys($countrys_en,$country,true);
  282. if($countrys[0]){
  283. $countryMobile =$this->getCountryCode($countrys[0]);
  284. }else{
  285. $countryMobile ='+1';
  286. }
  287. $countryMobile = str_replace('+','',$countryMobile);
  288. return (int)$countryMobile;
  289. }
  290. //获取国家手机编号
  291. public function getCountryCode($countryCode){
  292. $codes = [ "+86", "+93", "+355", "+213", "+376", "+244", "+1264",
  293. "+247", "+1268", "+54", "+374", "+297", "+61", "+43", "+994",
  294. "+1242", "+973", "+880", "+1246", "+375", "+32", "+501", "+229",
  295. "+1441", "+975", "+591", "+387", "+267", "+55", "+673", "+359",
  296. "+226", "+257", "+855", "+237", "+1", "+238", "+1345", "+236",
  297. "+235", "+56", "+57", "+269", "+242", "+243", "+682", "+506",
  298. "+225", "+385", "+53", "+357", "+420", "+45", "+253", "+1767",
  299. "+1809", "+593", "+20", "+503", "+372", "+251", "+298", "+679",
  300. "+358", "+33", "+594", "+689", "+241", "+220", "+995", "+94",
  301. "+233", "+350", "+30", "+299", "+1473", "+590", "+1671", "+502",
  302. "+240", "+44", "+224", "+592", "+509", "+504", "+852", "+95",
  303. "+36", "+354", "+91", "+62", "+98", "+964", "+353", "+44", "+972",
  304. "+93", "+1876", "+81", "+44", "+962", "+7", "+254", "+383", "+965",
  305. "+996", "+856", "+371", "+961", "+266", "+231", "+218", "+423",
  306. "+370", "+352", "+853", "+389", "+261", "+265", "+60", "+960",
  307. "+223", "+356", "+596", "+222", "+230", "+262", "+52", "+373",
  308. "+377", "+976", "+382", "+1664", "+212", "+258", "+264", "+977",
  309. "+31", "+599", "+687", "+64", "+505", "+227", "+234", "+47",
  310. "+968", "+92", "+970", "+507", "+675", "+595", "+51", "+63", "+48",
  311. "+351", "+1", "+974", "+262", "+40", "+7", "+250", "+684", "+685",
  312. "+378", "+239", "+966", "+221", "+381", "+248", "+232", "+65",
  313. "+421", "+386", "+27", "+82", "+34", "+94", "+1869", "+1758",
  314. "+1784", "+249", "+597", "+268", "+46", "+41", "+963", "+886",
  315. "+992", "+255", "+66", "+670", "+228", "+676", "+1868", "+216",
  316. "+90", "+993", "+1649", "+256", "+380", "+971", "+44", "+1",
  317. "+598", "+998", "+678", "+58", "+84", "+1340", "+967", "+260",
  318. "+263" ];
  319. return $codes[$countryCode];
  320. }
  321. }