-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSms.php
More file actions
94 lines (85 loc) · 2.89 KB
/
Copy pathSms.php
File metadata and controls
94 lines (85 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* Created by PhpStorm.
* User: lzw
* Date: 16/2/25
* Time: 上午3:49
*/
class Sms extends BaseDao
{
public $leanCloud;
public $userDao;
public $eventDao;
function __construct()
{
parent::__construct();
$this->load->library(LeanCloud::class);
$this->load->model(UserDao::class);
$this->load->model(EventDao::class);
$this->leanCloud = new LeanCloud();
$this->userDao = new UserDao();
$this->eventDao = new EventDao();
$this->load->helper('date');
}
function notifyNewOrderBySms($order)
{
$data = array(
SMS_REVIEWER => $order->reviewer->username,
SMS_LEARNER => $order->learner->username,
KEY_AMOUNT => amountToYuan($order->amount),
SMS_CODE_URL => $order->gitHubUrl,
);
$user = $this->userDao->findUserById($order->reviewer->id);
$phone = $user->mobilePhoneNumber;
$this->leanCloud->sendTemplateSms($phone, 'order', $data);
}
function notifyApplySucceed($userId)
{
$user = $this->userDao->findUserById($userId);
$phone = $user->mobilePhoneNumber;
$data = array(
SMS_REVIEWER => $user->username
);
$this->leanCloud->sendTemplateSms($phone, 'ApplySucceed', $data);
}
function notifyReviewFinish($learner, $reviewer, $reviewId)
{
$reviewUrl = 'http://reviewcode.cn/article.html?reviewId=' . $reviewId;
$data = array(
SMS_LEARNER => $learner->username,
SMS_REVIEWER => $reviewer->username,
SMS_REVIEW_URL => $reviewUrl
);
$user = $this->userDao->findUserById($learner->id);
$this->leanCloud->sendTemplateSms($user->mobilePhoneNumber, 'ReviewFinish', $data);
}
function notifyAttendEvent($userId, $eventId)
{
$user = $this->userDao->findUserById($userId);
$event = $this->eventDao->getEvent($eventId, null);
$data = array(
SMS_USER => $user->username,
SMS_LOCAION => $event->location,
SMS_DATE => $this->formatDate($event->startDate),
);
$this->leanCloud->sendTemplateSms($user->mobilePhoneNumber, 'AttendEvent', $data);
}
private function formatDate($date)
{
$time = strtotime($date);
return mdate('%m-%d %D %h:%i%a', $time);
}
function notifyEventComing($userId, $eventId, $otherTips = '')
{
$user = $this->userDao->findUserById($userId);
$event = $this->eventDao->getEvent($eventId, null);
$data = array(
SMS_USER => $user->username,
SMS_EVENT => $event->name,
SMS_LOCATION => $event->location,
SMS_DATE => $this->formatDate($event->startDate),
SMS_OTHER_TIPS => $otherTips
);
$this->leanCloud->sendTemplateSms($user->mobilePhoneNumber, 'EventComing', $data);
}
}