app_key = $app_key; $this->app_secret = $app_secret; $this->sign_key = $sign_key; $this->httpClient=new Client([ 'http_errors' => false ]); } /** * 发送基本短信 * @param string $mobile * @param SmsTemplate $template * @param array $params * @return bool */ public function sendSms(string $mobile, SmsTemplate $template, array $params = []): bool { $time=(int)(microtime(true)*1000); $id=$time; $appKey=$this->app_key; $phoneNums=$mobile; $content="【舟山市就业局】".$template->value; $flag=1; $wsdlUrl="http://115.236.191.137:8080/APL-SMSService/SMSService?wsdl"; $post_data = "" . "" . "" . "" . "" . $id . "" . "" . $appKey . "" . "" . $phoneNums . "" . "" . $content . "" . "" . "" . $flag . "" . "" . "" . ""; $response=$this->httpClient->post($wsdlUrl, ['body'=>$post_data]); return true; } /** * 发送确认短信,需要缓存验证码code * @param string $mobile * @param SmsTemplate $template * @return bool */ public function sendAuthSms(string $mobile, SmsTemplate $template): bool { $params['code']=rand(100000, 999999); $template->value=render_template($template->value, $params); $this->sendSms($mobile, $template, $params); Cache::put($template->alias.'_'.$mobile, $params['code'], 15); return true; } /** * 批量发送短信 * @param array $mobiles * @param SmsTemplate $template * @param array $params * @return bool */ public function sendBatchSms(array $mobiles, SmsTemplate $template, array $params = []): bool { // } }