/** * @method send * * @author 云小印[yunyin.org] * * @param $pid,$fid */ public function send() { $pid = pri_id(U('Index/index')); if ($pid) { $fid = I('fid', null, 'intval'); $map['pri_id'] = $pid; $map['id'] = $fid; $map['status'] = array('eq', C('FILE_PRINTED')); $map['sended'] = 0; $File = D('FileView'); $info = $File->where($map)->field('use_id,phone,name')->find(); $Printer = M('Printer'); $info['pri_name'] = M('Printer')->getFieldById($pid, 'name'); if ($info['phone'] && $info['name']) { unset($info['phone']); if (mb_strlen($info['name']) > 18) { $info['name'] = mb_substr($info['name'], 0, 18); } $phone = get_phone_by_id($info['use_id']); unset($info['use_id']); $info['fid'] = $fid; $SMS = new \Vendor\Sms(); if ($SMS->printed($phone, $info)) { $File = M('File'); $map['id'] = $fid; $result = $File->where($map)->setField('sended', 1); $this->success('提醒信息已发送'); } else { $this->error('发送不成功'); } } else { $this->success('已发送'); } } else { $this->error('请先登录'); } }
private function _sendDownloadMessage($pid, $fid) { $File = D('FileView'); $map['id'] = $fid; $info = $File->where($map)->field('use_id,phone,name')->find(); if ($info['phone'] && $info['name']) { unset($info['phone']); if (mb_strlen($info['name']) > 18) { $info['name'] = mb_substr($info['name'], 0, 18); } $phone = get_phone_by_id($info['use_id']); $info['user_name'] = M('User')->getFieldById($info['use_id'], 'name'); unset($info['use_id']); $info['info'] = $info['name']; $info['status'] = '已下载'; $SMS = new \Vendor\Sms(); if ($SMS->noticeUser($phone, $info)) { return true; } else { return false; } } else { return false; } }
/** * 给用户发送验证码 * @method send_sms_code($phone,$code,$type) * * @author NewFuture * * @param $phone 手机码 * @param $type 类型 * @return string 返回号码 */ function send_sms_code($phone, $type) { $info = S($type . $phone); if ($info) { if ($info['times'] > 5) { \Think\Log::record('手机号验证发送失败:ip:' . get_client_ip() . ',phone:' . $phone); return 0; } else { $code = $info['code']; $info['times'] = $info['times'] + 1; } } else { $code = random(6, 'N'); $info['code'] = $code; $info['times'] = 0; $info['tries'] = 0; } S($type . $phone, $info, 600); $SMS = new \Vendor\Sms(); switch ($type) { case 'bind': return $SMS->bindPhone($phone, $code); break; case 'findPwd': return $SMS->findPwd($phone, $code); break; default: E('unknow sms type '); } }
/** * find() * 核实信息 * @param number 学号 * @param name 姓名 */ public function find() { $uid = use_id(); $number = I('number', false, C('REGEX_NUMBER')); $name = I('name', false, 'trim'); $User = M('User'); $Card = M('Card'); $send_user = $uid ? $User->field('id,sch_id,student_number,name,phone,email')->getById($uid) : false; if (!$send_user) { $this->error('请登录!', '/'); } elseif (!$send_user['phone']) { $this->error('尚未绑定手机', '/User/index'); } elseif ($send_user['student_number'] == $number) { $this->error('不要用自己的做实验哦!'); } elseif ($Card->cache(true)->getFieldById($uid, 'blocked')) { $this->error('由于恶意使用,您的此功能已被禁用', '/Card/help'); } elseif (!$name && !$number) { $this->error('信息不足'); } else { /*尝试 验证 匹配 通知*/ $School = M('School'); $recv_user = $User->field('id,name,student_number AS number,sch_id,phone,email')->getByStudentNumber($number); if (!$recv_user) { /* 判断学校*/ if (preg_match(C('REGEX_NUMBER_NKU'), $number)) { $this->_saveReceiver($name, $number, 1, false); } elseif (preg_match(C('REGEX_NUMBER_TJU'), $number)) { $this->_saveReceiver($name, $number, 2, false); } else { $this->error('对不起,目前平台仅对南开大学和天津大学在校生开放,其他需求或者学校请联系我们!'); } $this->error($name . "({$number})尚未加入,你可以在此广播到社交网络", '/Card/broadcast'); } elseif ($name !== $recv_user['name']) { $this->error('失主信息核对失败!'); } elseif ($recv_off = $Card->cache(120)->getFieldById($recv_user['id'], 'off')) { $this->error('对方关闭了此功能,不希望你打扰TA,我们爱莫能助╮(╯-╰)╭'); } elseif (!($recv_user['phone'] || $recv_user['email'])) { $this->_saveReceiver($recv_user['name'], $recv_user['number'], $recv_user['sch_id'], $recv_user['id']); $this->error($name . "({$number})尚未绑定联系方式,你可以在此广播到社交网络", '/Card/broadcast'); } else { /*验证成功 ,手机或者邮箱存在 通知并记录*/ if ($recv_off === null) { //该同学不在card记录之中,则先创建 $Card->add(array('id' => $recv_user['id'])); } $msg = ''; //提示消息 $success = false; import('Common.Encrypt', COMMON_PATH, '.php'); $send_phone = decrypt_phone($send_user['phone'], $send_user['student_number'], $send_user['id']); if ($recv_user['phone']) { /*发送短信通知*/ $recv_phone = decrypt_phone($recv_user['phone'], $recv_user['number'], $recv_user['id']); $SMS = new \Vendor\Sms(); $info = array('send_phone' => $send_phone, 'send_name' => $send_user['name'], 'recv_name' => $recv_user['name']); $sms_result = $SMS->findCard($recv_phone, $info); $success |= $sms_result; if ($sms_result) { $msg = '短信已发送!<br/>'; } else { $msg = '短信发送失败!<br/>'; } } if ($recv_user['email']) { /*发送邮件通知*/ $recv_email = decrypt_email($recv_user['email']); $send_user['school'] = $School->cache(true)->getFieldById($send_user['sch_id'], 'name'); if ($send_user['email']) { $send_user['email'] = decrypt_email($send_user['email']); } /*拼装邮件*/ $mail_msg = L('MAIL_CARD', array('name' => $recv_user['name'], 'school' => $send_user['school'], 'sender_name' => $send_user['name'], 'phone' => $send_user['phone'], 'email' => $send_user['email'])); $mail_result = send_mail($recv_user, $mail_msg, C('MAIL_NOTIFY')); $success |= $mail_result; if ($mail_result) { $msg .= '邮件已发送!<br/>'; } else { $msg .= '邮件发送失败!'; } } if (!$success) { $this->_saveReceiver($recv_user['name'], $recv_user['number'], $recv_user['sch_id'], $recv_user['id']); $this->error('消息发送失败!请重试或者交由第三方平台!', '/Card/broadcast'); } else { /*记录招领信息*/ $log = array('find_id' => $send_user['id'], 'lost_id' => $recv_user['id']); if (!M('Cardlog')->add($log)) { $this->error('记录失败!!!<br/>' . $msg); } else { $this->success($msg); } } } } }
public function notifyUsers() { //identify $verify_key = I('get.key'); if ($verify_key != C('VERIFY_KEY')) { return; } $condition['_string'] = '(file.status=2 AND copies=0) OR file.status=4'; $condition['time'] = array('lt', date('Y-m-d h:i:s', time() - 3600 * 24)); $NotifyUser = D('NotifyUser'); $result = array(); $result1 = $NotifyUser->field('user_id,stu_num,phone,use_name,file_name,count("use_name") as count,$status')->where($condition)->group('use_name')->select(); $result3 = $NotifyUser->field('user_id,stu_num,phone,use_name,file_name,status')->where($condition)->select(); for ($i = 0; $i < count($result1); $i++) { $item1 = $result1[$i]; if ($item1['count'] == 1) { array_push($result, array($item1['phone'], $item1['use_name'], $item1['file_name'], "已经下载", $item1['user_id'], $item1['stu_num'])); } else { if ($item1['count'] > 1) { $count = 0; $info = ""; for ($k = 0; $k < count($result3); $k++) { $item3 = $result3[$k]; if ($item3['user_id'] == $item1['user_id']) { $count++; $info = $info . substr($item3['file_name'], 0, 8) . ".."; if ($count == 2) { break; } else { $info = $info . "、"; } } } $info = $info . "等" . $item1['count'] . "个文件"; array_push($result, array($item1['phone'], $item1['use_name'], $info, "已经下载", $item1['user_id'], $item1['stu_num'])); } } } echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>"; $SMS = new \Vendor\Sms(); for ($i = 0; $i < count($result); $i++) { $item = $result[$i]; import('Common.Encrypt', COMMON_PATH, '.php'); $phone = decrypt_phone($item[0], $item[5], $item[4]); echo $phone; if (!empty($phone)) { $msgInfo = array("user_name" => $item[1], "info" => $item[2], "status" => $item[3]); if ($SMS->noticeUser($phone, $msgInfo)) { echo "提醒信息已经发送"; } else { echo "发送不成功"; } echo $phone . "\t\t" . $msgInfo["user_name"] . "\t\t" . $msgInfo["info"] . "\t\t" . $msgInfo["status"]; } } }