package com.izouma.awesomeadmin.web;

import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.izouma.awesomeadmin.dto.Result;
import com.izouma.awesomeadmin.util.MbappUtil;
import com.izouma.awesomeadmin.util.MsgUtil;

/**
 * 
 * <p>页面控制。</p> 
 * 
 * @version 1.0
 * @author 姓名 <br />
 * 更新履历 <br />
 *  日期 : 姓名: 更新内容<br />
 */
@Controller
@RequestMapping("/msg")
@RequiresAuthentication
public class MsgSenderController  {

    @RequestMapping(value = "/sendCodeMsg", method = RequestMethod.GET)
    @ResponseBody
    public Result sendCodeMsg(@RequestParam(required = true, value = "mobile") String mobile) {

        String result;
        try {
            result = MbappUtil.getRandomNum(6);
            String content = "【享开店】您好，您的验证码是：" + result;

            MsgUtil.sendSms(mobile, content);

            return new Result(true, result);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return new Result(false, "发送失败，请稍后重试");
    }

}
