123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <?php
- namespace App\Http\Controllers\Code\V1;
- use App\Http\Controllers\Controller;
- use App\Model\Code\V1\Code;
- use App\Support\Code\Alisms;
- use App\Support\Code\Trsms;
- use App\Support\Code\Ypsms;
- use Illuminate\Http\Request;
- class SendCode extends Controller
- {
- // public function sendsCode(Request $request)
- // {
- // $errors = app('check')->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);
- }
- }
|