package com.hwrj.cloud.portal.util;

import com.hwrj.cloud.common.api.CommonResult;
import com.hwrj.cloud.common.entity.NoteInfo;
import com.hwrj.cloud.common.util.SMSEnum;
import com.hwrj.cloud.common.util.SMSUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author xiezt
 */
@Slf4j
@Component("smsComponent")
public class SmsComponent {

    private static final String SEND_SUCCESS="OK";


    @Autowired
    private SMSUtil smsUtil;

    /**
     * 根据电话号码发送验证码
     * @param phone
     * @return
     */
    public CommonResult sendPhoneMsm(String phone, String code,SMSEnum smsEnum){
        //发送验证码
        NoteInfo noteInfo = smsUtil.sendNote(phone, smsEnum.getCode(), code);
        String recode = noteInfo.getCode();

        //发送成功
        if (SEND_SUCCESS.equalsIgnoreCase(recode)){
            log.info("sms send code is ======================>{}",code);
            return CommonResult.success(null,"发送成功");
        }else{
            log.info(phone+"发送短信失败");
            return CommonResult.failed("短信发送失败");
        }

    }
}
