package com.hzs.third.sms.provider;

import com.hzs.common.core.domain.R;
import com.hzs.common.core.enums.EAliSmsTemplate;
import com.hzs.third.sms.ISmsServiceApi;
import com.hzs.third.sms.util.SmsUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;

/**
 * 短信服务提供类
 */
@Slf4j
@DubboService
public class SmsServiceProvider implements ISmsServiceApi {

    @Override
    public R<String> sendAliSms(String phone, String code, EAliSmsTemplate aliSmsTemplate) {
        try {
            String str = SmsUtil.sendAliSms(phone, code, aliSmsTemplate);
            if (null == str) {
                return R.ok();
            }
            log.error("发送阿里短信失败: {}", str);
            return R.fail(str);
        } catch (Exception e) {
            log.error("发送阿里短信异常 phone: {}, code: {}", phone, code, e);
            return R.fail(e.getMessage());
        }
    }

}
