AjaxAction.class.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. require_once( ONU_ROOT . 'application/module/ctrl/Action.class.php');
  3. require_once ( ONU_ROOT . 'application/lib/data/adminAction.php');
  4. class ajaxAction extends Action{
  5. public function __construct(){
  6. parent::__construct();
  7. }
  8. function sendemail(){
  9. $secret = "cd8412beb15b4ad34d8408d46e3c30a7";
  10. $getSecret = $_REQUEST['secret'];
  11. $store_name = $_REQUEST['store_name'];
  12. $customer_list = $_REQUEST['list'];
  13. $type = $_REQUEST['type'];//发送主题,1是询问收货地址;2确认收货
  14. //echo $store_name;exit;
  15. //测试数据
  16. // $getSecret = $secret;
  17. // $store_name = "alipearlhair";
  18. // $type = 2;
  19. // $customer_list = array(
  20. // "1" => array("email"=>"lxk8875@yahoo.com","logistics_number"=>"888888","uname"=>"hcm"),
  21. // "2" => array("email"=>"hcmdd888@hotmail.com","logistics_number"=>"888888","uname"=>"hcm"),
  22. // );
  23. //end
  24. $count = count($customer_list);//发送数量
  25. if($secret!=$getSecret){
  26. //密钥有误
  27. echo 1;exit;
  28. }
  29. if(empty($store_name)){
  30. //没传店铺名;
  31. echo 2;exit;
  32. }
  33. if($type!=1 && $type!=2){
  34. //发送主题,1是询问收货地址;2确认收货
  35. echo 3;exit;
  36. }
  37. global $EMAIL_MSG_LIST;
  38. global $EMAIL_SUBJECT_LIST;
  39. $subject = $EMAIL_SUBJECT_LIST[$store_name][$type];
  40. $admin = new AdvertAdminAction();
  41. //alipearlhair
  42. $info = $admin->selectUserByName($store_name);
  43. $api_user = $info['api_user'];
  44. $api_key = $info['api_key'];
  45. $from = $info['email_from'];
  46. $replyto = $info['email'];//发件人邮箱地址
  47. $content = $EMAIL_MSG_LIST[$store_name][$type];
  48. $post_url = 'http://api.sendcloud.net/apiv2/mail/send';
  49. //假设一次只能给100个人发,看需要发几次
  50. $c = 100;
  51. $p = ceil($count/100);//需要发总次数
  52. for($i=1;$i<=$p;$i++){
  53. $min = $c*($i-1);
  54. $max = $c*$i;
  55. $x_smtpapi = array();
  56. foreach($customer_list as $key=>$list){
  57. if($key>=$min && $key<$max){
  58. $x_smtpapi['to'][] = $list['email'];
  59. $user_name = $list['uname'];
  60. $x_smtpapi['sub']['%name%'][] = $user_name;
  61. if($type==1){
  62. $x_smtpapi['sub']['%address%'][] = $list['address'];
  63. }
  64. if($type==2){
  65. $x_smtpapi['sub']['%logistics_number%'][] = $list['logistics_number'];
  66. }
  67. }
  68. }
  69. $x_smtpapi = json_encode($x_smtpapi);
  70. $params = array(
  71. 'apiUser' => $api_user,
  72. 'apiKey' => $api_key,
  73. 'xsmtpapi' => $x_smtpapi,
  74. 'from' => $from,
  75. 'subject' => $subject,
  76. 'html' => $content,
  77. 'replyto' => $replyto
  78. );
  79. $result = make_curl($post_url,$params);
  80. //插入 普通邮件发送日志表
  81. $params['uid'] = $info['id'];
  82. $params['message'] = $result['message'];
  83. $params['time'] = time();
  84. $params['to'] = $params['xsmtpapi'];
  85. $insert_log = $admin->inserEmail1Log($params);
  86. }
  87. $msg = $result['message'];
  88. //成功
  89. echo 5;exit;
  90. }
  91. }