logger = $logger; } /** * @param String $field * @return string * @throws LocalizedException */ protected function getAliyunConfig(String $field) { $path = 'sms/aliyun/'.$field; $value = (string)$this->config->getValue($path); if (!$value) { throw new LocalizedException(__('please config %path', ['path'=>$path])); } return $value; } /** * @return GatewayResponseInterface * @throws LocalizedException */ protected function smsSend() : GatewayResponseInterface { $config = new Config([ "accessKeyId" => $this->getAliyunConfig('accessKeyId'), "accessKeySecret" => $this->getAliyunConfig('accessKeySecret') ]); $config->endpoint = self::ENDPOINT; $client = new Dysmsapi($config); $sendSmsRequest = new SendSmsRequest([ "signName" => $this->getSmsConfig('signature'), "templateCode" => $this->getSmsConfig('template_code'), "phoneNumbers" => $this->mobile, "templateParam" => json_encode(['code'=>$this->code]) ]); $resp = $client->sendSms($sendSmsRequest)->body->toMap(); $this->logger->info('Aliyun Sms api response', $resp); $resp[GatewayResponseInterface::RESPONSE] = $resp; $resp[GatewayResponseInterface::MESSAGE] = $resp['Message']; $resp[GatewayResponseInterface::TYPE] = $this->getSenderType(); $resp[GatewayResponseInterface::IS_SUCCESS] = $resp['Code']==='OK'; return $this->convertArrayToGatewayResponse($resp); } protected function getSenderType(): string { return 'aliyun'; } }