1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace app\common\library;
- class Qxysms
- {
- private $host = '';
- private $appKey = '';
- private $appSecret = '';
- private $appCode = '';
- private $signName = '';
- public function __construct($config){
- $this->host = $config['host'];
- $this->appKey = $config['appKey'];
- $this->appSecret = $config['appSecret'];
- $this->appCode = $config['appCode'];
- $this->signName = $config['signName'];
- }
- /**
- * 发送验证码
- * @param string $mobile
- * @param $code
- * @return bool
- */
- public function send(string $mobile, $code)
- {
- $timestamp = $this->ms_time();
- $data = [
- 'sign' => md5("{$this->appKey}{$this->appSecret}{$timestamp}"),
- 'timestamp' => $timestamp,
- 'phone' => $mobile,
- 'appcode' => $this->appCode,
- 'appkey' => $this->appKey,
- 'msg' => "【{$this->signName}】您的验证码是{$code},请妥善保管"
- ];
- $header = ['Content-type:application/json'];
- $response = curl_post($this->host . '/sms/batch/v1', json_encode($data),$header);
- //dump($response);exit;
- $response = json_decode($response,true);
- if(is_array($response) && isset($response['code']) && $response['code'] == '00000'){
- return true;
- }
- return false;
- }
- protected function ms_time()
- {
- list($ms, $sec) = explode(' ', microtime());
- return intval((floatval($ms) + floatval($sec)) * 1000);
- }
- }
|