NonNInt('platform_id|平台id', true)->mobile('mobile|手机号码', true)->errors; // if (!empty($errors)) { // return reValue(4002, null, $errors); // } // $id = $request->get('platform_id'); // $info = Code::getCodeInfoById($id); // if (empty($info)) { // return reValue(4002, null, ['未查询到平台数据']); // } // $url = $info->url; // $type = $info->request_type; // $passParm = $info->pass_parm; // $fixedParm = $info->fixed_parm; // $passParm = json_decode($passParm, true); // $fixedParm = json_decode($fixedParm, true); // foreach ($passParm as $k => $v) { // $data[$k] = $v; // } // $must = $passParm['must']; // foreach ($must as $v) { // $tmp = $request->get($v, null); // if (!isset($tmp)) { // return reValue(4002, null, [$v . '参数必填']); // } // $data[$v] = $tmp; // } // $notMust = $passParm['not_must']; // foreach ($notMust as $v) { // $tmp = $request->get($v, null); // $data[$v] = $tmp; // } // if ($type == 1) { // $re = curlInit($url, $data, 'Post'); // } else if ($type == 2) { // $re = curlInit($url, $data, 'Get'); // } else { // return reValue(4002, null, ['请求方式错误']); // } // if ($re === false) { // return reValue(4003, null, ['网络错误或超时']); // } // return reValue(0, $re); // } /** * [sendCode ] * @Author mzb * @DateTime 2018-11-09T16:23:18+0800 * @param Request $request [description] * @return [type] [description] */ public function sendCode(Request $request) { $errors = app('check')->mobile('mobile|手机号码', true)->contain([1, 2], 'type|发送的类型', true)->must('tpl_id|模板id')->json('parameter|参数', true)->NonNInt('aisle|通道', true)->errors; if (!empty($errors)) { return reValue(4002, null, $errors); } //手机号码 $mobile = $request->get('mobile'); //提供商的标志位1:云片 $aisle = $request->get('aisle'); //json格式的参数变量 $parameter = $request->get('parameter'); //发送的类型1短信2语音 $type = $request->get('type', 1); //模板id $tplId = $request->get('tpl_id'); //发送验证码 switch ($aisle) { case 1: $re = Ypsms::sendCode($tplId, $mobile, $parameter, $type); $aisleName = '云片'; break; case 2: $re = Trsms::sendCode($tplId, $mobile, $parameter, $type); $aisleName = '天瑞'; break; case 3: $re = Alisms::sendCode($tplId, $mobile, $parameter, $type); $aisleName = '阿里'; // print_r($re);exit; break; } if (!isset($re)) { return reValue(4002, null, ['通道不存在']); } if ($re === false) { return reValue(4003, null, ['网络错误或超时']); } //计费字段发送成功必有否则发送失败 if ($re['IS_SUCCESS'] == 1) { $appKey = $request->header('appkey'); Code::addStatistics($mobile, $aisleName, $appKey); return reValue(0, $re); }else{ //liujuan error日志表 $appKey = $request->header('appkey'); $reason=$re['reason']; Code::addStatistics_error($mobile, $aisleName, $appKey, $reason); return reValue(4003, $re); } // 原版return reValue(4003, $re); } /** * [sendCodes 群发短信] * @Author mzb * @DateTime 2018-11-09T16:20:01+0800 * @param Request $request [description] * @return [type] [description] */ public function sendCodes(Request $request) { $errors = app('check')->must('mobiles|手机号码')->NonNInt('aisle|通道', true)->must('tpl_id|模板id')->json('parameter|参数', true)->errors; if (!empty($errors)) { return reValue(4002, null, $errors); } //手机号码 $mobiles = $request->get('mobiles'); //json格式的参数变量 $parameter = $request->get('parameter'); //模板id $tplId = $request->get('tpl_id'); //提供商的标志位1:云片 $aisle = $request->get('aisle'); //发送验证码 switch ($aisle) { case 1: $re = Ypsms::sendCodes($tplId, $mobiles, $parameter); $aisleName = '云片'; break; case 2: $re = Trsms::sendCodes($tplId, $mobiles, $parameter); $aisleName = '天瑞'; break; case 3: $re = Alisms::sendCodes($tplId, $mobiles, $parameter); $aisleName = '阿里'; break; } if (!isset($re)) { return reValue(4002, null, ['通道不存在']); } if ($re === false) { return reValue(4003, null, ['网络错误或超时']); } //计费字段发送成功必有否则发送失败 if ($re['IS_SUCCESS'] == 1) { $appKey = $request->header('appkey'); $mobiles = explode(',', $mobiles); //循环插入效率很差需要优化 foreach ($mobiles as $mobile) { Code::addStatistics($mobile, $aisleName, $appKey); } return reValue(0, $re); }else{ //liujuan error日志表 $appKey = $request->header('appkey'); $mobiles = explode(',', $mobiles); $reason=$re['reason']; foreach ($mobiles as $mobile) { Code::addStatistics_error($mobile, $aisleName, $appKey, $reason); } return reValue(4003, $re); } // 原版 // return reValue(4003, $re); } /** * [返回所有通道 ] * @Author zxr * @DateTime 2019-01-21T11:23:18+0800 * @return [type] [description] */ public function returnSmsChannel() { $sms_channels = Code::getSmsChannel(); return reValue(0, $sms_channels); } /** * [根据通道id返回签名和模板 ] * @Author zxr * @DateTime 2019-01-21T11:23:18+0800 * @return [type] [description] */ public function returnSignAndTpl(Request $request) { $sms_channel_id = $request->input('sms_channel_id'); $sms_sign_tpl = Code::getSignAndTpl($sms_channel_id); return reValue(0, $sms_sign_tpl); } }