暫無描述

SmsController.php 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. /**
  3. * 摘要:短信发送
  4. * user:liuyb
  5. */
  6. namespace App\Http\Controllers\Code\V2;
  7. use App\Http\Controllers\Controller;
  8. use App\Model\Code\V2\TrSms;
  9. use Illuminate\Http\Request;
  10. use Illuminate\Support\Facades\Validator;
  11. class SmsController extends Controller
  12. {
  13. //发送验证码
  14. public function singleSms(Request $request)
  15. {
  16. //验参
  17. $validator = Validator::make($request->all(), [
  18. 'account' => 'required|numeric',
  19. 'sign' => 'required|numeric',
  20. 'mobile' => 'required|size:11',
  21. 'content' => 'required',
  22. 'templateId' => 'required',
  23. ], [
  24. 'account.required' => '短息渠道账号不能为空',
  25. 'sign.required' => '签名id不能为空',
  26. 'mobile.required' => 'mobile不能为空',
  27. 'mobile.size' => 'mobile长度必须是11位',
  28. 'content.required' => 'content不能为空',
  29. 'templateId.required' => 'templateId不能为空',
  30. ]);
  31. if ($validator->fails()) {
  32. return $validator->errors()->all();
  33. }
  34. $account = $request->input('account'); //短信平台账号 153132952
  35. $sign = $request->input('sign'); //签名id 17522
  36. $mobile = $request->input('mobile'); //接受者手机号
  37. $content = $request->input('content'); //短信内容, 验证码
  38. $templateId = $request->input('templateId'); //模板id 29070
  39. $TrSmsModel = new TrSms();
  40. $result = $TrSmsModel->singleSend($account, $sign, $mobile, $content, $templateId);
  41. return $result;
  42. }
  43. //短信群发
  44. public function multiSms(Request $request)
  45. {
  46. //验参
  47. $validator = Validator::make($request->all(), [
  48. 'account' => 'required|numeric',
  49. 'sign' => 'required|numeric',
  50. 'mobile' => 'required',
  51. 'content' => 'required',
  52. ], [
  53. 'account.required' => '短息渠道账号不能为空',
  54. 'sign.required' => '签名id不能为空',
  55. 'mobile.required' => 'mobile不能为空',
  56. 'content.required' => 'content不能为空',
  57. ]);
  58. if ($validator->fails()) {
  59. return $validator->errors()->all();
  60. }
  61. $account = $request->input('account');//153132952
  62. $sign = $request->input('sign'); //17522
  63. $mobile = $request->input('mobile');//13522199350
  64. $content = $request->input('content');
  65. $templateId = $request->input('templateId'); //29070
  66. $scheduleSendTime = $request->input('scheduleSendTime');
  67. $TrSmsModel = new TrSms();
  68. $result = $TrSmsModel->multiSend($account, $sign, $mobile, $content, $templateId, $scheduleSendTime);
  69. return $result;
  70. }
  71. //短信模板
  72. public function templateList(Request $request)
  73. {
  74. //验参
  75. $validator = Validator::make($request->all(), [
  76. 'account' => 'required|numeric',
  77. ], [
  78. 'account.required' => '短息渠道账号不能为空',
  79. ]);
  80. if ($validator->fails()) {
  81. return $validator->errors()->all();
  82. }
  83. $account = $request->input('account');//153132952
  84. $TrSmsModel = new TrSms();
  85. $result = $TrSmsModel->templateList($account);
  86. return $result;
  87. }
  88. //短信签名
  89. public function signList(Request $request)
  90. {
  91. //验参
  92. $validator = Validator::make($request->all(), [
  93. 'account' => 'required|numeric',
  94. ], [
  95. 'account.required' => '短息渠道账号不能为空',
  96. ]);
  97. if ($validator->fails()) {
  98. return $validator->errors()->all();
  99. }
  100. $account = $request->input('account');//153132952
  101. $TrSmsModel = new TrSms();
  102. $result = $TrSmsModel->signList($account);
  103. return $result;
  104. }
  105. //语音验证码
  106. public function voiceCode(Request $request)
  107. {
  108. //验参
  109. $validator = Validator::make($request->all(), [
  110. 'account' => 'required|numeric',
  111. 'mobile' => 'required',
  112. 'voiceCode' => 'required',
  113. ], [
  114. 'account.required' => '短息渠道账号不能为空',
  115. 'mobile.required' => 'mobile不能为空',
  116. 'voiceCode.required' => 'voiceCode不能为空',
  117. ]);
  118. if ($validator->fails()) {
  119. return $validator->errors()->all();
  120. }
  121. $account = $request->input('account');//153132952
  122. $mobile = $request->input('mobile');
  123. $voiceCode = $request->input('voiceCode');
  124. $TrSmsModel = new TrSms();
  125. $result = $TrSmsModel->voiceCode($account, $mobile, $voiceCode);
  126. return $result;
  127. }
  128. }