package com.slodon.b2b2c.model.member.advich;

import cn.hutool.core.collection.CollectionUtil;
import com.slodon.b2b2c.captcha.work.Producer;
import com.slodon.b2b2c.core.config.DomainUrlUtil;
import com.slodon.b2b2c.core.constant.RedisConst;
import com.slodon.b2b2c.core.constant.SMSConst;
import com.slodon.b2b2c.core.constant.VendorConst;
import com.slodon.b2b2c.core.exception.MallException;
import com.slodon.b2b2c.core.i18n.Language;
import com.slodon.b2b2c.core.random.RandomUtil;
import com.slodon.b2b2c.core.response.JsonResult;
import com.slodon.b2b2c.core.response.SldResponse;
import com.slodon.b2b2c.core.sms.SmsRequest;
import com.slodon.b2b2c.core.sms.SmsResponse;
import com.slodon.b2b2c.core.uid.GoodsIdGenerator;
import com.slodon.b2b2c.core.util.AssertUtil;
import com.slodon.b2b2c.core.util.StringUtil;
import com.slodon.b2b2c.core.util.WebUtil;
import com.slodon.b2b2c.dao.read.member.MemberReadMapper;
import com.slodon.b2b2c.dao.write.member.MemberWriteMapper;
import com.slodon.b2b2c.enums.WebSiteConstant;
import com.slodon.b2b2c.member.example.MemberExample;
import com.slodon.b2b2c.member.pojo.Member;
import com.slodon.b2b2c.model.member.MemberModel;
import com.slodon.b2b2c.model.msg.MsgSendModel;
import com.slodon.b2b2c.model.msg.SmsCodeModel;
import com.slodon.b2b2c.msg.pojo.SmsCode;
import com.slodon.b2b2c.seller.example.VendorExample;
import com.slodon.b2b2c.seller.pojo.Vendor;
import com.slodon.b2b2c.sms.DySmsSender;
import com.slodon.b2b2c.sms.TencentSmsSender;
import com.slodon.b2b2c.sms.YunPianSmsSender;
import com.slodon.b2b2c.sms.base.SmsSender;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @author cyan
 */
@Component
@Slf4j
public class MemberRegisterActiveModel {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Resource
    private MsgSendModel msgSendModel;

    @Resource
    private Producer producer;

    @Resource
    private MemberReadMapper memberReadMapper;

    @Resource
    private MemberWriteMapper memberWriteMapper;

    @Resource
    private MemberModel memberModel;
    @Resource
    private SmsCodeModel smsCodeModel;

    /**
     * 发送注册用户邮件激活链接
     *
     * @param email  邮箱
     * @param source
     */
    public Integer sendRegisterUserEmail(String email, Integer source) {
        int res = 0;
        MemberExample example = new MemberExample();
        example.setMemberEmail(email.toLowerCase());
        List<Member> memberList = memberReadMapper.listByExample(example);
        if (CollectionUtil.isNotEmpty(memberList)) {
            Member memberInfo = memberList.get(0);
            if (memberInfo.getIsEmailActive() == 0) {
                sendEmailActiveLink(email);
                res = 1;
            } else {
                res = 2;
            }
        } else {
            res = 1;
            sendEmailActiveLink(email);
            saveEmailUserInfo(email, source, null);
        }
        return res;
    }

    /**
     * 发送邮件验证链接
     *
     * @param email
     */
    public void sendEmailActiveLink(String email) {
        String pcDomainUrl = DomainUrlUtil.SLD_PC_URL.replace("http://", "").replace("https://", "");
        String verifCode = "";
        //邮件激活码过期时间,单位秒
        long expireTime = RedisConst.REGISTER_USER_AND_FORGETPWD_USER_EMAIL_LINK_EXPIRE_TIME;
        //将随机数存在redis中
        String activeEmailKey = RedisConst.SLD_PC_NEW_REGISTER_USER_EMAIL + email;
        if (stringRedisTemplate.hasKey(activeEmailKey)) {
            verifCode = stringRedisTemplate.opsForValue().get(activeEmailKey);
        } else {
            verifCode = producer.createText(3, 7);
            stringRedisTemplate.opsForValue().set(activeEmailKey, verifCode, expireTime, TimeUnit.SECONDS);
        }
        String emailActiveLink = DomainUrlUtil.SLD_PC_URL + "/email/active?email=" + email + "&code=" + verifCode;

        //获取站点名称
        String siteName = stringRedisTemplate.opsForValue().get("basic_site_name");

//        StringBuffer emailMsgTpl = new StringBuffer(Language.translate("亲爱的", Language.EN_LANGUAGE_TYPE));
//        emailMsgTpl.append(email);
//        emailMsgTpl.append("\r\n" + Language.translate("感谢您申请注册", Language.EN_LANGUAGE_TYPE));
//        emailMsgTpl.append(siteName);
//        emailMsgTpl.append("，" + Language.translate("请点击或复制以下链接到浏览器激活账号", Language.EN_LANGUAGE_TYPE) + "\r\n");
//        emailMsgTpl.append(emailActiveLink);

        StringBuffer emailMsgTpl = new StringBuffer(Language.translate("亲爱的会员：请点击以下按钮进行操作。", Language.EN_LANGUAGE_TYPE) + "<br/>");
        String forgetPwdEmailBtnHtml = "<a href=" + emailActiveLink + " style=\"display:block;text-decoration: none;color: #fff;font-size:16px;background-color: #00985e;height: 44px;line-height: 44px;text-align: center;width: 200px;margin: auto;\" target=\"_blank\" >" + Language.translate("账户注册", Language.EN_LANGUAGE_TYPE) + "</a>";
        emailMsgTpl.append("<br/>");
        emailMsgTpl.append(forgetPwdEmailBtnHtml);
        emailMsgTpl.append("<br/>");

        emailMsgTpl.append(Language.translate("您也可以将以下地址粘贴到浏览器中来验证您的帐户：", Language.EN_LANGUAGE_TYPE) + "<br/>");
        emailMsgTpl.append("<a href=" + emailActiveLink + " target=\"_blank\">" + emailActiveLink + "</a>");
        emailMsgTpl.append("<br/>");
        emailMsgTpl.append("<br/>");

        emailMsgTpl.append(Language.translate("请注意：", Language.EN_LANGUAGE_TYPE) + "<br/>");
        emailMsgTpl.append(Language.translate("验证后，即可完成帐号注册。", Language.EN_LANGUAGE_TYPE) + "<br/>");
        emailMsgTpl.append(Language.translate("如果您没有申请账号注册，", Language.EN_LANGUAGE_TYPE) + "<br/>");
        emailMsgTpl.append(Language.translate("请登录您的账户并修改密码，以确保您的账户安全。", Language.EN_LANGUAGE_TYPE) + "<br/>");
        emailMsgTpl.append(Language.translate("为了保护您的帐户，请不要允许他人访问您的电子邮件。", Language.EN_LANGUAGE_TYPE) + "<br/>");
        emailMsgTpl.append("<br/>");
        emailMsgTpl.append(Language.translate("买家服务团队", Language.EN_LANGUAGE_TYPE) + "<br/>");
        emailMsgTpl.append(pcDomainUrl);
        String subject = Language.translate("欢迎注册", Language.EN_LANGUAGE_TYPE) + pcDomainUrl.toUpperCase() + "，" + Language.translate("请验证您的邮箱", Language.EN_LANGUAGE_TYPE);
        msgSendModel.sendHtmlMail(email, subject, emailMsgTpl.toString());
    }

    /**
     * 保存邮件用户信息
     *
     * @param email
     * @param source
     */
    @Transactional(rollbackFor = Exception.class)
    public void saveEmailUserInfo(String email, Integer source, String webSite) {
        Member member = new Member();
        member.setMemberName(email);
//        member.setMemberName(GoodsIdGenerator.getMemberName());
        member.setLoginPwd("");
        member.setPayPwd("");
        member.setLastLoginIp("");
        member.setLoginNumber(0);
        member.setRegisterTime(new Date());
        member.setLastLoginTime(new Date());
        member.setRegisterChannel(source);
        member.setMemberEmail(email);
        member.setIsEmailActive(0);
        member.setWebSite(webSite);
        memberModel.saveMember(member);
    }

    /**
     * 根据邮箱检测Member信息
     *
     * @param email
     */
    public Integer checkMemberUserInfo(String email) {
        int res = 0;
        MemberExample memberExample = new MemberExample();
        memberExample.setMemberEmail(email);
        List<Member> memberList = memberReadMapper.listByExample(memberExample);
        if (CollectionUtil.isNotEmpty(memberList)) {
            Member memberInfo = memberList.get(0);
            if (memberInfo.getIsEmailActive() == 1) {
                sendEmailForgetPasswordLink(email, memberInfo.getMemberNickName());
                res = 1;
            } else {
                res = 2;
            }
        } else {
            res = 3;
        }
        return res;
    }

    /**
     * 发送邮件忘记密码链接
     *
     * @param email
     */
    public void sendEmailForgetPasswordLink(String email, String nickName) {
        String pcDomainUrl = DomainUrlUtil.SLD_PC_URL.replace("http://", "").replace("https://", "");
        String verifCode = "";
        //邮件重置密码过期时间,单位秒
        long expireTime = RedisConst.REGISTER_USER_AND_FORGETPWD_USER_EMAIL_LINK_EXPIRE_TIME;
        //将随机数存在redis中
        String forgetPwdEmailKey = RedisConst.SLD_PC_FORGET_PWD_USER_EMAIL + email;
        if (stringRedisTemplate.hasKey(forgetPwdEmailKey)) {
            verifCode = stringRedisTemplate.opsForValue().get(forgetPwdEmailKey);
        } else {
            verifCode = producer.createText(3, 7);
            stringRedisTemplate.opsForValue().set(forgetPwdEmailKey, verifCode, expireTime, TimeUnit.SECONDS);
        }
        String emailActiveLink = DomainUrlUtil.SLD_PC_URL + "/email/reset/pwd?email=" + email + "&code=" + verifCode;

        //获取站点名称
        String siteName = stringRedisTemplate.opsForValue().get("basic_site_name");

//        StringBuffer emailMsgTpl = new StringBuffer(Language.translate("亲爱的", Language.EN_LANGUAGE_TYPE));
//        emailMsgTpl.append(StringUtil.isEmpty(nickName) ? email : nickName);
//        emailMsgTpl.append("\r\n" + Language.translate("您是否忘记了密码", Language.EN_LANGUAGE_TYPE) + "?\r\n");
//        emailMsgTpl.append(Language.translate("请点击或复制以下链接到浏览器激活账号", Language.EN_LANGUAGE_TYPE) + "\r\n");
//        emailMsgTpl.append(emailActiveLink);
//        emailMsgTpl.append("\r\n" + Language.translate("此链接有效期为24小时，且只能使用一次", Language.EN_LANGUAGE_TYPE) + "\r\n" + Language.translate("如果您不想更改密码或未请求更改密码，请忽略并删除此邮件", Language.EN_LANGUAGE_TYPE) + "\r\n" + Language.translate("谢谢", Language.EN_LANGUAGE_TYPE) + "\r\n");
//        emailMsgTpl.append(siteName);
        StringBuffer emailMsgTpl = new StringBuffer(Language.translate("亲爱的", Language.EN_LANGUAGE_TYPE));
        emailMsgTpl.append(StringUtil.isEmpty(nickName) ? email : nickName + ":" + "<br/>");
//        emailMsgTpl.append(StringUtil.isEmpty(nickName) ? "<font color='#e13841'>"+email+"</font>" : "<font color='#e13841'>"+nickName+"</font>" + ",<br/>");
        emailMsgTpl.append(Language.translate("链接在24小时内有效，请尽快修改密码。", Language.EN_LANGUAGE_TYPE) + "<br/>");
        emailMsgTpl.append(Language.translate("我们给你发这封邮件是因为你要求重置新密码。请点击以下按钮进行操作。", Language.EN_LANGUAGE_TYPE) + "<br/>");
        String forgetPwdEmailBtnHtml = "<a href=" + emailActiveLink + " style=\"display:block;text-decoration: none;color: #fff;font-size:16px;background-color: #e13841;height: 44px;line-height: 44px;text-align: center;width: 200px;margin: auto;\" target=\"_blank\" >" + Language.translate("重置密码", Language.EN_LANGUAGE_TYPE) + "</a>";
        emailMsgTpl.append("<br/>");
        emailMsgTpl.append(forgetPwdEmailBtnHtml);
        emailMsgTpl.append("<br/>");

        emailMsgTpl.append(Language.translate("您也可以将以下地址粘贴到浏览器中重置密码：", Language.EN_LANGUAGE_TYPE) + "<br/>");
        emailMsgTpl.append("<a href=" + emailActiveLink + " target=\"_blank\">" + emailActiveLink + "</a>");
        emailMsgTpl.append("<br/>");
        emailMsgTpl.append("<br/>");

        emailMsgTpl.append(Language.translate("如果您没有请求新密码，请忽略此邮件。", Language.EN_LANGUAGE_TYPE) + "<br/>");
        emailMsgTpl.append(Language.translate("这是系统邮件，请不要回复。", Language.EN_LANGUAGE_TYPE) + "<br/>");
        emailMsgTpl.append("<br/>");
        emailMsgTpl.append(Language.translate("最好的问候", Language.EN_LANGUAGE_TYPE) + "<br/>");
        emailMsgTpl.append(pcDomainUrl);
        String subject = Language.translate("重设您的", Language.EN_LANGUAGE_TYPE) + pcDomainUrl.toUpperCase() + " " + Language.translate("帐户密码", Language.EN_LANGUAGE_TYPE);
        msgSendModel.sendHtmlMail(email, subject, emailMsgTpl.toString());
    }

    /**
     * 发送账户注册成功邮件信息
     *
     * @param email
     */
    public void sendRegisterSuccessEmail(String email, String nickName) {
        //获取站点名称
        String siteName = stringRedisTemplate.opsForValue().get("basic_site_name");
        String pcDomainUrl = DomainUrlUtil.SLD_PC_URL.replace("http://", "").replace("https://", "");

        StringBuffer emailMsgTpl = new StringBuffer(Language.translate("你好", Language.EN_LANGUAGE_TYPE) + " ");
//        emailMsgTpl.append(StringUtil.isEmpty(nickName) ? "<font color='#e13841'>"+email+"</font>" : "<font color='#e13841'>"+nickName+"</font>" + ",<br/>");
        emailMsgTpl.append(StringUtil.isEmpty(nickName) ? email : nickName + ":" + "<br/>");
        emailMsgTpl.append("<br/>");

        String enText1 = Language.translate("感谢您注册成为${URL}的明星买家。明星买家是${URL}上的特殊买家。", Language.EN_LANGUAGE_TYPE);
        enText1 = enText1.replace("${URL}", pcDomainUrl);
        emailMsgTpl.append(enText1 + "<br/>");
        emailMsgTpl.append("<br/>");

        String enText2 = Language.translate("您可以通过您的电子邮件地址登录您的${URL}帐户：", Language.EN_LANGUAGE_TYPE);
        enText2 = enText2.replace("${URL}", pcDomainUrl);
        emailMsgTpl.append(enText2);
//        emailMsgTpl.append("<font color='#e13841'>"+email+"</font>");
        emailMsgTpl.append(email);
        emailMsgTpl.append("<br/>");
        emailMsgTpl.append("<br/>");

        String enText3 = Language.translate("在${URL}上寻找供应商既快捷又方便。凭借我们提供的独家明星买家福利和有用工具，您的采购之旅将变得更安全、更容易、更高效!", Language.EN_LANGUAGE_TYPE);
        enText3 = enText3.replace("${URL}", pcDomainUrl);
        emailMsgTpl.append(enText3);
        emailMsgTpl.append("<br/>");
        emailMsgTpl.append("<br/>");

        emailMsgTpl.append(Language.translate("买家服务团队", Language.EN_LANGUAGE_TYPE) + "<br/>");
        emailMsgTpl.append(pcDomainUrl);
        String subject = Language.translate("注册成功", Language.EN_LANGUAGE_TYPE) + " " + pcDomainUrl.toUpperCase();
        msgSendModel.sendHtmlMail(email, subject, emailMsgTpl.toString());
    }

    public Integer sendRegisterUserVerificationCode(String webSite, String email, String mobile, Integer source) {
        int res = 0;
        MemberExample example = new MemberExample();
        if (WebSiteConstant.MEMBER_OVERSEA.equals(webSite)) {
            example.setMemberEmail(email.toLowerCase());
        } else {
            example.setMemberMobile(mobile);
        }
        example.setWebSite(webSite);
        List<Member> memberList = memberReadMapper.listByExample(example);
        if (CollectionUtil.isNotEmpty(memberList)) {
            Member memberInfo = memberList.get(0);
            if (memberInfo.getIsEmailActive() == 0) {
                if (WebSiteConstant.MEMBER_OVERSEA.equals(webSite)) {
                    sendEmailRegisterVerificationCode(email);
                } else {
                    sendMobileRegisterVerificationCode(mobile);
                }

                res = 1;
            } else {
                res = 2;
            }
        } else {
            res = 1;
            if (WebSiteConstant.MEMBER_OVERSEA.equals(webSite)) {
                sendEmailRegisterVerificationCode(email);
            } else {
                sendMobileRegisterVerificationCode(mobile);
            }
            saveUserInfo(webSite, email, mobile, source);
        }
        return res;
    }

    private void sendMobileRegisterVerificationCode(String mobile) {
        // 记录手机短信验证码
        SmsCode code = new SmsCode();
        code.setMobile(mobile);
        code.setRequestIp("");
        code.setCreateTime(new Date());
        code.setMemberId(0);
        code.setMemberName(mobile);
        // 阿里云发送
        Integer sendSmsType = 3;
        code.setSmsType(SMSConst.SMS_TYPE_1);
        String templateCode = stringRedisTemplate.opsForValue().get("notification_sms_ali_register_sms_template");
        sendSms(mobile, code, sendSmsType, templateCode, "register");
    }


    /**
     * 发送短信
     *
     * @param mobile 手机号
     * @param code   短信验证码记录信息
     * @return 返回值
     */
    private void sendSms(String mobile, SmsCode code, Integer sendSmsType, String templateCode, String type) {
        SmsRequest smsRequest = new SmsRequest();
        smsRequest.setSmsType(SMSConst.VERIFY_SMS);
        smsRequest.setMobile(mobile);
        //根据系统配置的发送方式，获取短信发送对象
        SmsSender smsSender;
        if (sendSmsType == null) {
            sendSmsType = DomainUrlUtil.SEND_SMS_TYPE;
        }
        switch (sendSmsType) {
            case 1:
                //腾讯云发送
                smsSender = new TencentSmsSender(stringRedisTemplate);
                break;
            case 2:
                //云片发送
                smsSender = new YunPianSmsSender(stringRedisTemplate);
                break;
            case 3:
                //阿里云发送
                smsSender = new DySmsSender(stringRedisTemplate);
                break;
            default:
                throw new MallException("发送短信失败");
        }
        if (sendSmsType == 3) {
            AssertUtil.notEmpty(templateCode, "短信配置没有填写,无法发送短信");
            smsRequest.setTemplateId(templateCode);
        }
        SmsResponse smsResponse = smsSender.sendSms(smsRequest);

        code.setVerifyCode(smsResponse.getVerifyCode());
        smsCodeModel.saveSmsCode(code);

        //将随机数存在redis中
        if ("register".equals(type)) {
            stringRedisTemplate.opsForValue().set(RedisConst.SLD_PC_NEW_REGISTER_USER_MOBILE + mobile, smsResponse.getVerifyCode(), 60L * 5, TimeUnit.SECONDS);
        } else if ("forget".equals(type)) {
            stringRedisTemplate.opsForValue().set(RedisConst.SLD_PC_FORGET_PWD_USER_MOBILE + mobile, smsResponse.getVerifyCode(), 60L * 5, TimeUnit.SECONDS);
        }

    }

    /**
     * 保存用户信息
     *
     * @param webSite
     * @param email
     * @param mobile
     * @param source
     */
    private void saveUserInfo(String webSite, String email, String mobile, Integer source) {
        Member member = new Member();
        if (WebSiteConstant.MEMBER_OVERSEA.equals(webSite)) {
            member.setMemberName(email);
            member.setMemberEmail(email);
        } else {
            member.setMemberName(mobile);
            member.setMemberMobile(mobile);
        }
        member.setLoginPwd("");
        member.setPayPwd("");
        member.setLastLoginIp("");
        member.setLoginNumber(0);
        member.setRegisterTime(new Date());
        member.setLastLoginTime(new Date());
        member.setRegisterChannel(source);

        member.setIsEmailActive(0);
        member.setWebSite(webSite);
        memberModel.saveMember(member);
    }

    private void sendEmailRegisterVerificationCode(String email) {
        String pcDomainUrl = DomainUrlUtil.SLD_PC_URL.replace("http://", "").replace("https://", "");
        String verifCode = "";
        //邮件验证码过期时间,单位秒
        long expireTime = RedisConst.REGISTER_USER_AND_FORGETPWD_USER_EMAIL_VERIFICATION_CODE_EXPIRE_TIME;

        //将随机数存在redis中
        String activeEmailKey = RedisConst.SLD_PC_NEW_REGISTER_USER_EMAIL + email;
        verifCode = RandomUtil.randomNumber(4);
        stringRedisTemplate.opsForValue().set(activeEmailKey, verifCode, expireTime, TimeUnit.SECONDS);

        StringBuffer emailMsgTpl = new StringBuffer();
        emailMsgTpl.append(Language.translate("感谢您申请注册", Language.EN_LANGUAGE_TYPE) + "\r\n");
        emailMsgTpl.append(Language.translate("验证码", Language.EN_LANGUAGE_TYPE));
        emailMsgTpl.append(":" + verifCode);

        String subject = Language.translate("欢迎注册", Language.EN_LANGUAGE_TYPE) + pcDomainUrl.toUpperCase() + "，" + Language.translate("请验证您的邮箱", Language.EN_LANGUAGE_TYPE);
        msgSendModel.sendHtmlMail(email, subject, emailMsgTpl.toString());
    }

    public Integer checkMemberUserInfo(String webSite, String email, String mobile) {
        int res = 0;
        MemberExample memberExample = new MemberExample();
        if (WebSiteConstant.MEMBER_OVERSEA.equals(webSite)) {
            memberExample.setMemberEmail(email.toLowerCase());
        } else {
            memberExample.setMemberMobile(mobile);
        }
        memberExample.setWebSite(webSite);
        List<Member> memberList = memberReadMapper.listByExample(memberExample);
        if (CollectionUtil.isNotEmpty(memberList)) {
            Member memberInfo = memberList.get(0);
            if (memberInfo.getIsEmailActive() == 1) {
                if (WebSiteConstant.MEMBER_OVERSEA.equals(webSite)) {
                    sendEmailForgetPasswordVerificationCode(email, memberInfo.getMemberNickName());
                } else {
                    sendMobileForgetPasswordVerificationCode(mobile);
                }

                res = 1;
            } else {
                res = 2;
            }
        } else {
            res = 3;
        }
        return res;
    }

    private void sendMobileForgetPasswordVerificationCode(String mobile) {
        // 记录手机短信验证码
        SmsCode code = new SmsCode();
        code.setMobile(mobile);
        code.setRequestIp("");
        code.setCreateTime(new Date());
        code.setMemberId(0);
        code.setMemberName(mobile);
        // 阿里云发送
        Integer sendSmsType = 3;
        code.setSmsType(SMSConst.SMS_TYPE_3);
        String templateCode = stringRedisTemplate.opsForValue().get("notification_sms_ali_forget_sms_template");
        sendSms(mobile, code, sendSmsType, templateCode, "forget");
    }

    private void sendEmailForgetPasswordVerificationCode(String email, String nickName) {
        String pcDomainUrl = DomainUrlUtil.SLD_PC_URL.replace("http://", "").replace("https://", "");
        String verifCode = "";
        //重置密码验证码过期时间,单位秒
        long expireTime = RedisConst.REGISTER_USER_AND_FORGETPWD_USER_EMAIL_VERIFICATION_CODE_EXPIRE_TIME;

        //将随机数存在redis中
        String forgetPwdEmailKey = RedisConst.SLD_PC_FORGET_PWD_USER_EMAIL + email;
        verifCode = RandomUtil.randomNumber(4);
        stringRedisTemplate.opsForValue().set(forgetPwdEmailKey, verifCode, expireTime, TimeUnit.SECONDS);

        StringBuffer emailMsgTpl = new StringBuffer(Language.translate("亲爱的", Language.EN_LANGUAGE_TYPE));
        emailMsgTpl.append(StringUtil.isEmpty(nickName) ? email : nickName + ":" + "<br/>");
        emailMsgTpl.append(Language.translate("验证码", Language.EN_LANGUAGE_TYPE));
        emailMsgTpl.append(":" + verifCode);
        emailMsgTpl.append("<br/>");
        emailMsgTpl.append(Language.translate("如果您没有请求新密码，请忽略此邮件。", Language.EN_LANGUAGE_TYPE) + "<br/>");
        emailMsgTpl.append(Language.translate("这是系统邮件，请不要回复。", Language.EN_LANGUAGE_TYPE) + "<br/>");
        emailMsgTpl.append("<br/>");
        emailMsgTpl.append(Language.translate("最好的问候", Language.EN_LANGUAGE_TYPE) + "<br/>");
        emailMsgTpl.append(pcDomainUrl);
        String subject = Language.translate("重设您的", Language.EN_LANGUAGE_TYPE) + pcDomainUrl.toUpperCase() + " " + Language.translate("帐户密码", Language.EN_LANGUAGE_TYPE);
        msgSendModel.sendHtmlMail(email, subject, emailMsgTpl.toString());
    }

    public void sendRegisterSuccessSms(String mobile) {
        SmsCode code = new SmsCode();
        code.setMobile(mobile);
        code.setRequestIp("");
        code.setCreateTime(new Date());
        code.setMemberId(0);
        code.setMemberName(mobile);
        // 阿里云发送
        Integer sendSmsType = 3;
        code.setSmsType(SMSConst.SMS_TYPE_4);
        String templateCode = stringRedisTemplate.opsForValue().get("notification_sms_ali_register_success_sms_template");
        sendSms(mobile, code, sendSmsType, templateCode, "success");
    }
}
