/**
 * 
 */
package org.springblade.modules.auth.endpoint;

import org.springblade.common.unciom.UnicomUtil;
import org.springblade.core.constant.AppConstant;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.hutool.core.lang.Tuple;
import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @author wookvn
 *
 */
@RestController
@RequestMapping(AppConstant.APPLICATION_AUTH_NAME)
@Api(value = "联通登录短信验证码", tags = "联通登录短信验证码接口")
public class UnicomSmsEndpoint {

	/**
	 * @param userSign
	 * @return
	 */
	@PostMapping("/unicomSms")
	@ApiOperation(value = "获取短信验证码", notes = "Header传递User-Sign")
	public R<Integer> unicomSms(@RequestHeader("User-Sign") String userSign){
		Tuple userIdMobile = UnicomUtil.decryptAes(userSign);
		String mobile = userIdMobile.get(1);
		
		String errMsg = UnicomUtil.sendSms(mobile);
		return StrUtil.isEmpty(errMsg) ? R.success("发送成功") : R.fail(errMsg);
	}
	
	@GetMapping("/testSms")
	public R<String> testSms(String mobile) {
		return R.data(UnicomUtil.sendSms(mobile));
	}
}
