CertController.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Services\CallApiService;
  4. use App\Services\Msg\MailTemplateService;
  5. use App\ThirdPartyApi\Interfaces\SmsInterface;
  6. use Exception;
  7. use Illuminate\Http\Request;
  8. class CertController extends Controller
  9. {
  10. private $callApiService;
  11. private $smsService;
  12. private $mailTemplateService;
  13. public function __construct(CallApiService $callApiService,
  14. SmsInterface $smsService,
  15. MailTemplateService $mailTemplateService)
  16. {
  17. $this->callApiService = $callApiService;
  18. $this->smsService = $smsService;
  19. $this->mailTemplateService = $mailTemplateService;
  20. }
  21. public function mail(Request $request)
  22. {
  23. $certNumber = rand(100000, 999999);
  24. $reqInfo = [
  25. 'number' => $certNumber,
  26. 'date' => date('YmdHis'),
  27. 'time' => time(),
  28. 'email' => $request['ToMail']
  29. ];
  30. session()->put('mailCert', $reqInfo);
  31. try {
  32. if (! $this->mailTemplateService->send($request['Component'], [ 'C11' => $certNumber ],
  33. $request['ToMail'], $request['Subject'])) {
  34. return response()->json([ 'error' => true, 'message' => 'Failed to send password reset email, please try again.']);
  35. }
  36. } catch (Exception $e) {
  37. return response()->json(['error' => true, 'message' => 'Unauthorized']);
  38. }
  39. return response()->json(['error' => false, 'message' => 'Success']);
  40. }
  41. public function mobile(Request $request)
  42. {
  43. $receiver = $request['MobileNo'];
  44. $smsCert = rand(100000, 999999);
  45. $reqInfo = [
  46. 'number' => $smsCert,
  47. 'date' => date('YmdHis'),
  48. 'time' => time(),
  49. 'mobile_no' => $receiver
  50. ];
  51. $title ='본인확인';
  52. $msg ="[Dabory] 본인확인 인증번호는 [{$smsCert}]입니다. 정확히 입력해주세요.";
  53. session()->put('smsCert.'.$request['Name'], $reqInfo);
  54. $response = $this->smsService->sendMessage($title, $msg, $receiver);
  55. return response()->json(['error' => false, 'message' => $response]);
  56. }
  57. }