| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- namespace common\components;
- 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,
- 'mobile' => $mobile,
- 'content' => $content,
- ];
- try {
- $response = $client->post($this->apiUrl, $params)->send();
- if ($response->isOk) {
- $result = Json::decode($response->content);
- if ($result['status'] === 'success') {
- return true;
- } else {
- return false;
- }
- } else {
- return false;
- }
- } catch (\Exception $e) {
- // 处理异常
- return false;
- }
- }
- }
|