1212
1313use GuzzleHttp \ClientInterface ;
1414use Illuminate \Mail \Transport \Transport ;
15+ use Illuminate \Support \Arr ;
16+ use Psr \Http \Message \ResponseInterface ;
1517use Swift_Mime_SimpleMessage ;
1618
1719/**
18- * Class Transport.
19- *
20- * @author overtrue <i@overtrue.me>
20+ * Class DirectMailTransport
2121 */
2222class DirectMailTransport extends Transport
2323{
2424 /**
25- * Guzzle client instance.
26- *
2725 * @var \GuzzleHttp\ClientInterface
2826 */
2927 protected $ client ;
@@ -46,7 +44,7 @@ class DirectMailTransport extends Transport
4644 /**
4745 * @var string
4846 */
49- protected $ regons = [
47+ protected $ regions = [
5048 'cn-hangzhou ' => [
5149 'id ' => 'cn-hangzhou ' ,
5250 'url ' => 'https://dm.aliyuncs.com ' ,
@@ -97,8 +95,8 @@ public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = nul
9795
9896 $ message ->setBcc ([]);
9997
100- $ regionId = \array_get ($ this ->options , 'region_id ' , 'cn-hangzhou ' );
101- $ region = $ this ->regons [$ regionId ];
98+ $ regionId = Arr:: get ($ this ->options , 'region_id ' , 'cn-hangzhou ' );
99+ $ region = $ this ->regions [$ regionId ];
102100
103101 $ this ->client ->post ($ region ['url ' ], ['form_params ' => $ this ->payload ($ message , $ region )]);
104102
@@ -118,14 +116,14 @@ public function send(Swift_Mime_SimpleMessage $message, &$failedRecipients = nul
118116 protected function payload (Swift_Mime_SimpleMessage $ message , array $ region )
119117 {
120118 $ parameters = array_filter ([
121- 'AccountName ' => array_get ($ this ->options , 'from_address ' , \config ('mail.from.address ' , key ($ message ->getFrom ()))),
119+ 'AccountName ' => Arr:: get ($ this ->options , 'from_address ' , \config ('mail.from.address ' , key ($ message ->getFrom ()))),
122120 'ReplyToAddress ' => 'true ' ,
123- 'AddressType ' => array_get ($ this ->options , 'address_type ' , 1 ),
121+ 'AddressType ' => Arr:: get ($ this ->options , 'address_type ' , 1 ),
124122 'ToAddress ' => $ this ->getTo ($ message ),
125- 'FromAlias ' => array_get ($ this ->options , 'from_alias ' ),
123+ 'FromAlias ' => Arr:: get ($ this ->options , 'from_alias ' ),
126124 'Subject ' => $ message ->getSubject (),
127125 'HtmlBody ' => $ message ->getBody (),
128- 'ClickTrace ' => array_get ($ this ->options , 'click_trace ' , 0 ),
126+ 'ClickTrace ' => Arr:: get ($ this ->options , 'click_trace ' , 0 ),
129127 'Format ' => 'json ' ,
130128 'Action ' => 'SingleSendMail ' ,
131129 'Version ' => $ region ['version ' ],
@@ -177,22 +175,18 @@ protected function getTo(Swift_Mime_SimpleMessage $message)
177175 }
178176
179177 /**
180- * Get the transmission ID from the response.
178+ * @param \Psr\Http\Message\ResponseInterface $ response
181179 *
182- * @param \GuzzleHttp\Psr7\Response $response
183- *
184- * @return string
180+ * @return mixed
185181 */
186- protected function getTransmissionId ($ response )
182+ protected function getTransmissionId (ResponseInterface $ response )
187183 {
188- return object_get (
189- json_decode ($ response ->getBody ()->getContents ()), 'RequestId '
184+ return Arr:: get (
185+ json_decode ($ response ->getBody ()->getContents (), true ), 'RequestId '
190186 );
191187 }
192188
193189 /**
194- * Get all of the contacts for the message.
195- *
196190 * @param \Swift_Mime_SimpleMessage $message
197191 *
198192 * @return array
@@ -205,8 +199,6 @@ protected function allContacts(Swift_Mime_SimpleMessage $message)
205199 }
206200
207201 /**
208- * Get the API key being used by the transport.
209- *
210202 * @return string
211203 */
212204 public function getKey ()
@@ -215,8 +207,6 @@ public function getKey()
215207 }
216208
217209 /**
218- * Get the API key being used by the transport.
219- *
220210 * @return string
221211 */
222212 public function getSecret ()
@@ -225,8 +215,6 @@ public function getSecret()
225215 }
226216
227217 /**
228- * Set the API key being used by the transport.
229- *
230218 * @param string $key
231219 *
232220 * @return string
@@ -237,7 +225,7 @@ public function setKey(string $key)
237225 }
238226
239227 /**
240- * Get the API key being used by the transport.
228+ * @param string $secret
241229 *
242230 * @return string
243231 */
0 commit comments