/** * * 批量发送短信 * @param array $mobile 手机号码 * @param string $content 短信内容 * @param datetime $send_time 发送时间 * @param string $charset 短信字符类型 gbk / utf-8 * @param string $id_code 唯一值 、可用于验证码 */ public function sendSms($token, $content = '', $mobile = '') { //if (C('sms_key')!=''&&C('sms_key')!='key'){ if (C('sms_username') != '' && C('sms_username')) { $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 (intval($thisUser['smscount']) < 1 && $token != 'admin') { return '已用完或者未购买短信包'; exit; } else { // //短信发送状态 if (is_array($mobile)) { $mobile = implode(",", $mobile); } $content = Sms::_safe_replace($content); /*$data = array( 'id' => C('sms_username'), 'pwd' => C('sms_password'), //'encode' => $charset, 'tos' => $mobile, 'content' => iconv("UTF-8","GB2312",$content), 'time' => '' //'mobileids' => time() );*/ if (C('sms_sign') != '') { $content = iconv("UTF-8", "GB2312", $content . '【' . C('sms_sign') . '】'); } else { $content = iconv("UTF-8", "GB2312", $content); } $data = "id=" . C('sms_username') . "&pwd=" . C('sms_password') . "&to=" . $mobile . "&content=" . $content . "&time="; $smsapi_senturl = C('sms_url'); //'http://api.sms.cn/mtutf8/?'; $return = Sms::PostData($smsapi_senturl, $data); $statuscode = $return; //增加到本地数据库 if ($mobile) { $row = array('uid' => $thisUser['id'], 'token' => $thisWxUser['token'], 'time' => time(), 'mp' => $mobile, 'text' => $content, 'status' => $this->statuscode, 'price' => C('sms_price')); M('Sms_record')->add($row); if (intval($this->statuscode) == 00 && $token != 'admin') { M('Users')->where(array('id' => $thisWxUser['uid']))->setDec('smscount'); } } $statustext = ''; switch (intval($statuscode)) { case 00: $statustext = '发送成功'; break; case -01: $statustext = '余额不足'; break; case -02: $statustext = '用户ID错误,请联系客服人员'; break; case -03: $statustext = '密码错误'; break; case -04: $statustext = '参数错误'; break; case -12: $statustext = '其他错误'; break; } return $statuscode . ':' . $statustext; } } }