Conditions | 6 |
Paths | 7 |
Total Lines | 41 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
28 | public function send($text, $imagePath = null) { |
||
29 | |||
30 | if (empty($text)) { |
||
31 | return false; |
||
32 | } |
||
33 | |||
34 | $request_params = [ |
||
35 | 'headers' => [ |
||
36 | 'Authorization' => 'Bearer ' . $this->token, |
||
37 | ], |
||
38 | ]; |
||
39 | |||
40 | if (!empty($imagePath)) { |
||
41 | $request_params['multipart'] = [ |
||
42 | [ |
||
43 | 'name' => 'message', |
||
44 | 'contents' => $text |
||
45 | ], |
||
46 | [ |
||
47 | 'name' => 'imageFile', |
||
48 | 'contents' => fopen($imagePath, 'r') |
||
49 | ], |
||
50 | ]; |
||
51 | } else { |
||
52 | $request_params['form_params'] = ['message' => $text]; |
||
53 | } |
||
54 | |||
55 | $response = $this->http->request('POST', LineNotify::API_URL, $request_params); |
||
56 | |||
57 | if ($response->getStatusCode() != 200) { |
||
58 | return false; |
||
59 | } |
||
60 | |||
61 | $body = (string) $response->getBody(); |
||
62 | $json = json_decode($body, true); |
||
63 | if (empty($json['status']) || empty($json['message'])) { |
||
64 | return false; |
||
65 | } |
||
66 | |||
67 | return true; |
||
68 | } |
||
69 | |||
71 |