package org.sky.resource.rule.sms;

import com.yunpian.sdk.YunpianClient;
import org.sky.core.literule.annotation.LiteRuleComponent;
import org.sky.core.literule.core.RuleComponent;
import org.sky.core.redis.cache.KdRedis;
import org.sky.core.sms.SmsTemplate;
import org.sky.core.sms.YunpianSmsTemplate;
import org.sky.core.sms.props.SmsProperties;
import org.sky.resource.pojo.entity.Sms;
import org.sky.resource.rule.constant.SmsRuleConstant;
import org.sky.resource.rule.context.SmsContext;

/**
 * 云片短信构建类
 *
 */
@LiteRuleComponent(id = SmsRuleConstant.YUNPIAN_SMS_RULE, name = "云片SMS构建")
public class YunpianSmsRule extends RuleComponent {

	@Override
	public void process() {
		// 获取上下文
		SmsContext contextBean = this.getContextBean(SmsContext.class);
		Sms sms = contextBean.getSms();
		KdRedis kdRedis = contextBean.getKdRedis();

		SmsProperties smsProperties = new SmsProperties();
		smsProperties.setTemplateId(sms.getTemplateId());
		smsProperties.setAccessKey(sms.getAccessKey());
		smsProperties.setSignName(sms.getSignName());
		YunpianClient client = new YunpianClient(smsProperties.getAccessKey()).init();
		SmsTemplate smsTemplate = new YunpianSmsTemplate(smsProperties, client, kdRedis);

		// 设置上下文
		contextBean.setSmsTemplate(smsTemplate);

	}
}
