|  | @@ -0,0 +1,67 @@
 | 
	
		
			
				|  |  | +<?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},请妥善保管"
 | 
	
		
			
				|  |  | +        ];
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        $response  = curl_post($this->host . '/sms/batch/v1', json_encode($data),['Content-type:application/json']);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //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);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * @param $url
 | 
	
		
			
				|  |  | +     * @param array $params
 | 
	
		
			
				|  |  | +     * @param array $header
 | 
	
		
			
				|  |  | +     * @return PromiseInterface|Response
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    protected function postJson($url, array $params = [], array $header = [])
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +        return Http::withHeaders($header)->acceptJson()->post($this->host . $url, $params);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +}
 |