模板管理
更新时间:2021-07-16
创建模板
通过以下代码可以申请一个SMS模板:
                Python
                
            
            1try:
2    response = sms_client.create_template(name="测试模板", content="模板样例${content}", sms_type="CommonNotice",
3                                          description="用于测试的模板", country_type="DOMESTIC")
4except ex.BceHttpClientError as e:
5    if isinstance(e.last_error, ex.BceServerError):
6        LOG.error('send request failed. Response %s, code: %s, request_id: %s'
7                  % (e.last_error.status_code, e.last_error.code, e.last_error.request_id))
8    else:
9        LOG.error('send request failed. Unknown exception: %s' % e)
            提示: 详细的参数配置及限制条件,可以参考SMS API详情创建模板
获取模板详情
通过以下代码可以获取指定的SMS模板详情:
                Python
                
            
            1try:
2    response = sms_client.get_template_detail(template_id)
3except ex.BceHttpClientError as e:
4    if isinstance(e.last_error, ex.BceServerError):
5        LOG.error('send request failed. Response %s, code: %s, request_id: %s'
6                  % (e.last_error.status_code, e.last_error.code, e.last_error.request_id))
7    else:
8        LOG.error('send request failed. Unknown exception: %s' % e)
            提示: 详细的参数配置及限制条件,可以参考SMS API详情查询模板
变更模板
通过以下代码可以更新指定的SMS模板:
                Python
                
            
            1try:
2    response = sms_client.update_template(template_id=template_id, name="测试模板2", content="模板样例${content}2",
3                                          sms_type="CommonSale", country_type="GLOBAL")
4except ex.BceHttpClientError as e:
5    if isinstance(e.last_error, ex.BceServerError):
6        LOG.error('send request failed. Response %s, code: %s, request_id: %s'
7                  % (e.last_error.status_code, e.last_error.code, e.last_error.request_id))
8    else:
9        LOG.error('send request failed. Unknown exception: %s' % e)
            提示: 详细的参数配置及限制条件,可以参考SMS API详情变更模板
删除模板
通过以下代码可以删除指定的SMS模板:
                Python
                
            
            1try:
2    response = sms_client.delete_template(template_id)
3except ex.BceHttpClientError as e:
4    if isinstance(e.last_error, ex.BceServerError):
5        LOG.error('send request failed. Response %s, code: %s, request_id: %s'
6                  % (e.last_error.status_code, e.last_error.code, e.last_error.request_id))
7    else:
8        LOG.error('send request failed. Unknown exception: %s' % e)
            提示: 详细的参数配置及限制条件,可以参考SMS API详情删除模板
