1 | <?php |
||
2 | |||
3 | namespace Dongdavid\Notify; |
||
4 | |||
5 | class QuickSend |
||
6 | { |
||
7 | /** |
||
8 | * 微信公众号模版消息. |
||
9 | * |
||
10 | * @param $access_token |
||
11 | * @param $openid |
||
12 | * @param $template_id |
||
13 | * @param $data |
||
14 | * @param string $url |
||
15 | * @param false $miniProgram |
||
16 | * |
||
17 | * @return bool|string |
||
18 | */ |
||
19 | public static function offical($access_token, $openid, $template_id, $data, $url = '', $miniProgram = false) |
||
20 | { |
||
21 | $msg = [ |
||
22 | 'type' => 'wechatoffical', |
||
23 | 'config' => [ |
||
24 | 'access_token' => $access_token, |
||
25 | ], |
||
26 | 'data' => [ |
||
27 | 'touser' => $openid, |
||
28 | 'template_id' => $template_id, |
||
29 | 'data' => $data, |
||
30 | 'url' => $url, |
||
31 | ], |
||
32 | ]; |
||
33 | if ($miniProgram) { |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
34 | $msg['data']['miniprogram'] = $miniProgram; |
||
35 | } |
||
36 | try { |
||
37 | return Notify::send($msg); |
||
38 | } catch (\Exception $e) { |
||
39 | return $e->getMessage(); |
||
40 | } |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * 微信小程序. |
||
45 | * |
||
46 | * @param $access_token |
||
47 | * @param $openid |
||
48 | * @param $template_id |
||
49 | * @param $data |
||
50 | * @param string $page |
||
51 | * @param string $miniprogram_state |
||
52 | * @param string $lang |
||
53 | * |
||
54 | * @return bool|string |
||
55 | */ |
||
56 | public static function miniProgram( |
||
57 | $access_token, |
||
58 | $openid, |
||
59 | $template_id, |
||
60 | $data, |
||
61 | $page = '', |
||
62 | $miniprogram_state = 'formal', |
||
63 | $lang = 'zh_CN' |
||
64 | ) { |
||
65 | $msg = [ |
||
66 | 'type' => 'miniprogram', |
||
67 | 'config' => [ |
||
68 | 'access_token' => $access_token, |
||
69 | ], |
||
70 | 'data' => [ |
||
71 | 'touser' => $openid, |
||
72 | 'template_id' => $template_id, |
||
73 | 'data' => $data, |
||
74 | 'page' => $page, |
||
75 | 'miniprogram_state' => $miniprogram_state, |
||
76 | 'lang' => $lang, |
||
77 | ], |
||
78 | ]; |
||
79 | try { |
||
80 | return Notify::send($msg); |
||
81 | } catch (\Exception $e) { |
||
82 | return $e->getMessage(); |
||
83 | } |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * 发送邮件. |
||
88 | * |
||
89 | * @param $config |
||
90 | * @param $subject |
||
91 | * @param $body |
||
92 | * @param $to |
||
93 | * @param array $attachments |
||
94 | * @param array $cc |
||
95 | * @param array $bcc |
||
96 | * |
||
97 | * @return bool|string |
||
98 | */ |
||
99 | public static function mail($config, $subject, $body, $to, $attachments = [], $cc = [], $bcc = []) |
||
100 | { |
||
101 | $msg = [ |
||
102 | 'type' => 'email', |
||
103 | 'config' => $config, |
||
104 | 'data' => [ |
||
105 | 'subject' => $subject, |
||
106 | 'body' => $body, |
||
107 | 'to' => $to, |
||
108 | ], |
||
109 | ]; |
||
110 | if (!empty($attachments)) { |
||
111 | $msg['data']['attachments'] = $attachments; |
||
112 | } |
||
113 | if (!empty($cc)) { |
||
114 | $msg['data']['cc'] = $cc; |
||
115 | } |
||
116 | if (!empty($bcc)) { |
||
117 | $msg['data']['bcc'] = $bcc; |
||
118 | } |
||
119 | |||
120 | try { |
||
121 | return Notify::send($msg); |
||
122 | } catch (\Exception $e) { |
||
123 | return $e->getMessage(); |
||
124 | } |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * @param $config |
||
129 | * @param $phone |
||
130 | * @param $template_code |
||
131 | * @param array $template_param |
||
132 | * |
||
133 | * @return array|string |
||
134 | */ |
||
135 | public static function alisms($config, $phone, $template_param = []) |
||
136 | { |
||
137 | $msg = [ |
||
138 | 'type' => 'alisms', |
||
139 | 'config' => $config, |
||
140 | 'data' => [ |
||
141 | 'phone' => $phone, |
||
142 | 'template_param' => $template_param, |
||
143 | ], |
||
144 | ]; |
||
145 | try { |
||
146 | return Notify::send($msg); |
||
147 | } catch (\Exception $e) { |
||
148 | return $e->getMessage(); |
||
149 | } |
||
150 | } |
||
151 | } |
||
152 |