一、接口文档地址
二、RegionID参数说明
地域 | RegionID |
---|
华东1(杭州) | cn-hangzhou | 华东2(上海) | cn-shanghai | 华北1(青岛) | cn-qingdao | 华北2(北京) | cn-beijing | 华南1(深圳) | cn-shenzhen | 新加坡 | ap-southeast-1 | 马来西亚(吉隆坡) | ap-southeast-3 | 印度尼西亚(雅加达) | ap-southeast-5 | 日本(东京) | ap-northeast-1 | 英国(伦敦) | eu-west-1 |
三、短信模板代码
<?php
use AlibabaCloud\Client\AlibabaCloud;
class AliService {
protected $regionId = '';
protected $accessKey = '';
protected $accessSecret = '';
public function __construct() {
$this->regionId = '<your-region-id>';
$this->accessKey = '<your-access-key-id>';
$this->accessSecret = '<your-access-key-secret>';
}
public function addSmsTemplate($templateType, $templateName, $templateContent, $remark) {
try {
AlibabaCloud::accessKeyClient($this->accessKey, $this->accessSecret)
->regionId($this->regionId)
->asDefaultClient();
$data['RegionId'] = $this->regionId;
$data['TemplateType'] = $templateType;
$data['TemplateName'] = $templateName;
$data['TemplateContent'] = $templateContent;
$data['Remark'] = $remark;
$result = AlibabaCloud::rpc()
->product('Dysmsapi')
->version('2017-05-25')
->action('AddSmsTemplate')
->method('POST')
->options(['query' => $data])
->request();
$result = $result->toArray();
if ($result['Code'] != 'OK') {
throw $result['Message'];
}
return $result;
} catch (\Exception $e) {
throw $e;
}
}
public function modifySmsTemplate($templateType, $templateName, $templateContent, $remark, $templateCode) {
try {
AlibabaCloud::accessKeyClient($this->accessKey, $this->accessSecret)
->regionId($this->regionId)
->asDefaultClient();
$data['RegionId'] = $this->regionId;
$data['TemplateType'] = $templateType;
$data['TemplateName'] = $templateName;
$data['TemplateContent'] = $templateContent;
$data['Remark'] = $remark;
$data['TemplateCode'] = $templateCode;
$result = AlibabaCloud::rpc()
->product('Dysmsapi')
->version('2017-05-25')
->action('ModifySmsTemplate')
->method('POST')
->options(['query' => $data])
->request();
$result = $result->toArray();
if ($result['Code'] != 'OK') {
throw $result['Message'];
}
return $result;
} catch (\Exception $e) {
throw $e;
}
}
public function querySmsTemplate($templateCode) {
try {
AlibabaCloud::accessKeyClient($this->accessKey, $this->accessSecret)
->regionId($this->regionId)
->asDefaultClient();
$data['RegionId'] = $this->regionId;
$data['TemplateCode'] = $templateCode;
$result = AlibabaCloud::rpc()
->product('Dysmsapi')
->version('2017-05-25')
->action('QuerySmsTemplate')
->method('POST')
->options(['query' => $data])
->request();
$result = $result->toArray();
if ($result['Code'] != 'OK') {
throw $result['Message'];
}
return $result;
} catch (\Exception $e) {
throw $e;
}
}
public function deleteSmsTemplate($templateCode) {
try {
AlibabaCloud::accessKeyClient($this->accessKey, $this->accessSecret)
->regionId($this->regionId)
->asDefaultClient();
$data['RegionId'] = $this->regionId;
$data['TemplateCode'] = $templateCode;
$result = AlibabaCloud::rpc()
->product('Dysmsapi')
->version('2017-05-25')
->action('DeleteSmsTemplate')
->method('POST')
->options(['query' => $data])
->request();
$result = $result->toArray();
if ($result['Code'] != 'OK') {
throw $result['Message'];
}
return $result;
} catch (\Exception $e) {
throw $e;
}
}
}
四、关联文章
|