CertController.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. if (isset($request['Title']) && isset($request['Msg'])) {
  52. $title = $request['Title'];
  53. $msg = $request['Msg'];
  54. } else {
  55. $title ='본인확인';
  56. $msg ="[Dabory] 본인확인 인증번호는 [{$smsCert}]입니다. 정확히 입력해주세요.";
  57. session()->put('smsCert.'.$request['Name'], $reqInfo);
  58. }
  59. $response = $this->smsService->sendMessage($title, $msg, $receiver);
  60. return response()->json(['error' => false, 'message' => $response]);
  61. }
  62. }