|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the smsmode-bundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2019 WEBEWEB |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace WBW\Bundle\SMSModeBundle\Controller; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\HttpFoundation\JsonResponse; |
|
15
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
16
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
17
|
|
|
use WBW\Bundle\SMSModeBundle\Event\DeliveryReportCallbackEvent; |
|
18
|
|
|
use WBW\Bundle\SMSModeBundle\Event\SMSModeEvents; |
|
19
|
|
|
use WBW\Bundle\SMSModeBundle\Event\SMSReplyCallbackEvent; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* sMsmode controller |
|
23
|
|
|
* |
|
24
|
|
|
* @author webeweb <https://github.com/webeweb/> |
|
25
|
|
|
* @package WBW\Bundle\SMSModeBundle\Controller |
|
26
|
|
|
*/ |
|
27
|
|
|
class SMSModeController extends AbstractController { |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Delivery report callback. |
|
31
|
|
|
* |
|
32
|
|
|
* @param Request $request The request. |
|
33
|
|
|
* @return Response Returns the response. |
|
34
|
|
|
*/ |
|
35
|
|
|
public function deliveryReportCallbackAction(Request $request) { |
|
36
|
|
|
|
|
37
|
|
|
$eventName = SMSModeEvents::DELIVERY_REPORT_CALLBACK; |
|
38
|
|
|
|
|
39
|
|
|
$eventDispatcher = $this->getEventDispatcher(); |
|
40
|
|
|
if (null !== $eventDispatcher && true === $eventDispatcher->hasListeners($eventName)) { |
|
41
|
|
|
|
|
42
|
|
|
$this->getLogger()->info(sprintf("sMsmode controller dispatch an event with name \"%s\"", $eventName)); |
|
43
|
|
|
|
|
44
|
|
|
$deliveryReportCallback = $this->newDeliveryReportCallback($request); |
|
45
|
|
|
|
|
46
|
|
|
$event = new DeliveryReportCallbackEvent($eventName, $deliveryReportCallback); |
|
47
|
|
|
|
|
48
|
|
|
$eventDispatcher->dispatch($eventName, $event); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return new JsonResponse(["code" => 200, "message" => "OK"]); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* SMS reply callback. |
|
56
|
|
|
* |
|
57
|
|
|
* @param Request $request The request. |
|
58
|
|
|
* @return Response Returns the response. |
|
59
|
|
|
*/ |
|
60
|
|
|
public function smsReplyCallbackAction(Request $request) { |
|
61
|
|
|
|
|
62
|
|
|
$eventName = SMSModeEvents::SMS_REPLY_CALLBACK; |
|
63
|
|
|
|
|
64
|
|
|
$eventDispatcher = $this->getEventDispatcher(); |
|
65
|
|
|
if (null !== $eventDispatcher && true === $eventDispatcher->hasListeners($eventName)) { |
|
66
|
|
|
|
|
67
|
|
|
$this->getLogger()->info(sprintf("sMsmode controller dispatch an event with name \"%s\"", $eventName)); |
|
68
|
|
|
|
|
69
|
|
|
$smsReplyCallback = $this->newSMSReplyCallback($request); |
|
70
|
|
|
|
|
71
|
|
|
$event = new SMSReplyCallbackEvent($eventName, $smsReplyCallback); |
|
72
|
|
|
|
|
73
|
|
|
$eventDispatcher->dispatch($eventName, $event); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
return new JsonResponse(["code" => 200, "message" => "OK"]); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|