static::ACCESS_KEY_ID, // AccessKey Secret 'accessKeySecret' => static::ACCESS_KEY_SECRET ]); // 访问的域名 $config->endpoint = 'dysmsapi.aliyuncs.com'; return new Dysmsapi($config); } /** * 发送验证码 * * @param $phoneNumbers * @param $templateCode * @param array $templateParam * @return bool */ static public function send($phoneNumbers, $templateCode, array $templateParam = array()) { $client = static::createClient(); $sendSmsRequest = new SendSmsRequest([ 'phoneNumbers' => $phoneNumbers, 'signName' => static::SIGN_NAME, 'templateCode' => $templateCode, 'templateParam' => json_encode($templateParam) ]); $runtime = new RuntimeOptions([]); $logFile = ROOT_PATH . DS . 'aliyun-sms.txt'; try { $data = $client->sendSmsWithOptions($sendSmsRequest, $runtime); if ($data->body->code === 'OK') { return TRUE; } $logData = print_r($data, TRUE); } catch (\Exception $ex) { $logData = print_r($ex, TRUE); } file_put_contents($logFile, '[' . date('Y-m-d H:i:s') . ']' . PHP_EOL . $logData . PHP_EOL . PHP_EOL, FILE_APPEND); return FALSE; } }