| 1234567891011121314151617181920212223242526272829303132333435363738 |
- <?php
- namespace common\components;
- use common\helpers\LoggerTool;
- use yii\base\Component;
- use yii\helpers\Json;
- use yii\httpclient\Client;
- class SilverStreet extends Component {
- public $username;
- public $password;
- public $sender;
- public $apiUrl;
- public function sendSms($mobile, $content): bool
- {
- $client = new Client();
- $params = [
- 'username' => $this->username,
- 'password' => $this->password,
- 'sender' => $this->sender,
- 'destination' => $mobile,
- 'body' => $content,
- ];
- try {
- $response = $client->post($this->apiUrl, $params)->send();
- if ($response->getStatusCode() == 200) {
- return true;
- } else {
- return false;
- }
- } catch (\Exception $e) {
- // 处理异常
- return false;
- }
- }
- }
|