Example #1
0
 /**
  * 
  * 批量发送短信
  * @param array $mobile 手机号码
  * @param string $content 短信内容
  * @param datetime $send_time 发送时间
  * @param string $charset 短信字符类型 gbk / utf-8
  * @param string $id_code 唯一值 、可用于验证码
  * $data = array(mer_id, store_id, content, mobile, uid, type);
  */
 public function sendSms($data = array(), $send_time = '', $charset = 'utf-8', $id_code = '')
 {
     if ($data) {
         $type = isset($data['type']) ? $data['type'] : 'meal';
         $sendto = isset($data['sendto']) ? $data['sendto'] : 'user';
         $mer_id = isset($data['mer_id']) ? intval($data['mer_id']) : 0;
         $store_id = isset($data['store_id']) ? intval($data['store_id']) : 0;
         $uid = isset($data['uid']) ? intval($data['uid']) : 0;
         if (empty($mer_id)) {
             return 'mer_id is null';
         }
         $content = isset($data['content']) ? Sms::_safe_replace($data['content']) : '';
         if (empty($content)) {
             return 'send content is null';
         }
         $mobile = isset($data['mobile']) ? $data['mobile'] : '';
         $phone_array = explode(',', $mobile);
         $mobile = $pre = '';
         foreach ($phone_array as $phone) {
             if (Sms::checkmobile($phone)) {
                 $mobile .= $pre . $phone;
                 $pre = ',';
             }
         }
         if (empty($mobile)) {
             return 'phone is right';
         }
         $data = array('topdomain' => C('config.sms_server_topdomain'), 'key' => trim(C('config.sms_key')), 'token' => $mer_id . 'o2opigcms', 'content' => $content, 'mobile' => $mobile, 'sign' => trim(C('config.sms_sign')));
         $post = '';
         foreach ($data as $k => $v) {
             $post .= $k . '=' . $v . '&';
         }
         $http = 'http://api.sms.cn/mtutf8/';
         $uid = C('config.sms_key');
         $pwd = C('config.sms_sign');
         $mobile = $mobile;
         $content = $content;
         $mobileids = $mobile;
         // dump($mobileids);exit;
         $return = Sms::send_SMS($http, $uid, $pwd, $mobile, $content, $mobileids);
         //dump($return);exit;
         $arr = explode('#', $return);
         $send_time = $send_time ? $send_time : time();
         //增加到本地数据库
         $row = array('mer_id' => $mer_id, 'uid' => $uid, 'store_id' => $store_id, 'time' => $send_time, 'phone' => $mobile, 'text' => $content, 'status' => $return, 'type' => $type, 'sendto' => $sendto);
         D('Sms_record')->add($row);
         return $return;
     } else {
         return false;
     }
     exit;
     if (C('sms_key') != '' && C('sms_key') != 'key') {
         $companyid = 0;
         if (!(strpos($token, '_') === FALSE)) {
             $sarr = explode('_', $token);
             $token = $sarr[0];
             $companyid = intval($sarr[1]);
         }
         if (!$mobile) {
             $companyWhere = array();
             $companyWhere['token'] = $token;
             if ($companyid) {
                 $companyWhere['id'] = $companyid;
             }
             $company = M('Company')->where($companyWhere)->find();
             $mobile = $company['mp'];
         }
         //
         $thisWxUser = M('Wxuser')->where(array('token' => Sms::_safe_replace($token)))->find();
         $thisUser = M('Users')->where(array('id' => $thisWxUser['uid']))->find();
         if ($token == 'admin') {
             $thisUser = array('id' => 0);
             $thisWxUser = array('uid' => 0, 'token' => $this->token);
         }
         //
         //短信发送状态
         if (is_array($mobile)) {
             $mobile = implode(",", $mobile);
         }
         $content = Sms::_safe_replace($content);
         $data = array('topdomain' => C('config.server_topdomain'), 'key' => trim(C('config.sms_key')), 'token' => $token, 'content' => $content, 'mobile' => $mobile, 'sign' => trim(C('config.sms_sign')));
         $post = '';
         foreach ($data as $k => $v) {
             $post .= $k . '=' . $v . '&';
         }
         $http = 'http://api.sms.cn/mtutf8/';
         $uid = C('config.sms_key');
         $pwd = C('config.sms_sign');
         $mobile = $mobile;
         $content = $content;
         $mobileids = $mobile;
         // dump($mobileids);exit;
         $return = Sms::send_SMS($http, $uid, $pwd, $mobile, $content, $mobileids);
         $arr = explode('#', $return);
         $this->statuscode = $arr[0];
         //增加到本地数据库
         if ($mobile) {
             $row = array('uid' => $thisUser['id'], 'token' => $thisWxUser['token'], 'time' => time(), 'mp' => $mobile, 'text' => $content, 'status' => $return, 'price' => C('sms_price'));
             M('Sms_record')->add($row);
             if (intval($this->statuscode) == 0 && $token != 'admin') {
                 M('Users')->where(array('id' => $thisWxUser['uid']))->setDec('smscount');
             }
         }
         //end
         return $return;
     }
 }