SMS plugin:Alibaba Cloud SMS#
Features#
Provide SMS service support for the platform,SMS service provider is Alibaba Cloud SMS。
Configuration guide#
Enter through the menu bar on the left【Tenant management】->【Plug -in management】,Find the Alibaba Cloud SMS plug -in card in the plug -in lease page,Click to rent
![Plug -in rental] (https://S1.ax1x.com/2022/08/02/lose.png)
After the lease is completed,Enter the lease list,Find Alibaba Cloud SMS plug -in card,Click on the tenant configuration,Configure related data
* Domain name default.aliyuncs.com
![Plug -in tenant configuration] (https://S1.ax1x.com/2022/08/02/vEsDFe.md.png)
After the tenant configuration is completed, return to the rental page,Click on Run on the Alibaba Cloud SMS plug -in card,Click new in the pop -up window,Enter the corresponding SMS template configuration
![Configuration during the plug -in] (https://S1.ax1x.com/2022/08/02/vEyZkD.md.png)
![Configuration during the plug -in] (https://S1.ax1x.com/2022/08/02/Make sure.md.png)
* Notice: If you do not fill in the template parameter, the default is ["code"],Applicable to SMS verification code
Abstract method implementation#
Code#
        
extension_root.com_longgui_sms_aliyun.AliyunSMSExtension            (SmsExtension)
        
#
    Source code in extension_root/com_longgui_sms_aliyun/__init__.py
          class AliyunSMSExtension(SmsExtension):
    def load(self):
        self.register_settings_schema(SettingsSchema)
        self.register_config_schema(ConfigSchema)
        super().load()
    def send_sms(self, event, **kwargs):
        tenant = event.tenant
        config_id = event.data.pop("config_id")
        mobile = event.data.pop("mobile")
        template_params = {}
        settings = self.get_settings(tenant)
        settings = SimpleNamespace(**settings.settings)
        config = self.get_config_by_id(config_id).config
        for key in config.get("template_params",["code"]):
            template_params[key] = event.data.get(key,"")
        template_params = json.dumps(template_params)
        config = SimpleNamespace(**config)
        aliyun_config = models.Config(
            # 您的AccessKey ID,
            access_key_id=settings.access_key_id,
            # 您的AccessKey Secret,
            access_key_secret=settings.access_key_secret,
            # 地域ID
            region_id=settings.region_id or None,
            # 访问的域名
            endpoint=settings.endpoint or None,
        )
        client = Client(aliyun_config)
        send_sms_request = dysmsapi_20170525_models.SendSmsRequest(
            phone_numbers=mobile,
            sign_name=config.sign_name,
            template_code=config.template_code,
            template_param=template_params,
            sms_up_extend_code=config.sms_up_extend_code or None,
            out_id=config.out_id or None,
        )
        res = client.send_sms(send_sms_request)
        return res.body.to_map()
load(self)
#
    
  
send_sms(self, event, **kwargs)
#
    发送短信
Parameters:
| Name | Type | Description | Default | 
|---|---|---|---|
| event | Event | 事件 | required | 
Source code in extension_root/com_longgui_sms_aliyun/__init__.py
          def send_sms(self, event, **kwargs):
    tenant = event.tenant
    config_id = event.data.pop("config_id")
    mobile = event.data.pop("mobile")
    template_params = {}
    settings = self.get_settings(tenant)
    settings = SimpleNamespace(**settings.settings)
    config = self.get_config_by_id(config_id).config
    for key in config.get("template_params",["code"]):
        template_params[key] = event.data.get(key,"")
    template_params = json.dumps(template_params)
    config = SimpleNamespace(**config)
    aliyun_config = models.Config(
        # 您的AccessKey ID,
        access_key_id=settings.access_key_id,
        # 您的AccessKey Secret,
        access_key_secret=settings.access_key_secret,
        # 地域ID
        region_id=settings.region_id or None,
        # 访问的域名
        endpoint=settings.endpoint or None,
    )
    client = Client(aliyun_config)
    send_sms_request = dysmsapi_20170525_models.SendSmsRequest(
        phone_numbers=mobile,
        sign_name=config.sign_name,
        template_code=config.template_code,
        template_param=template_params,
        sms_up_extend_code=config.sms_up_extend_code or None,
        out_id=config.out_id or None,
    )
    res = client.send_sms(send_sms_request)
    return res.body.to_map()