package com.leromro.core.utils;

import cn.hutool.core.util.StrUtil;
import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.dysmsapi20170525.models.SendSmsResponseBody;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.teautil.models.RuntimeOptions;

public class SendSmsUtil {
    private static final String accessKeyId = "LTAI5t7Xyw23riTKPgy99FNP";
    private static final String accessKeySecret = "vPXlxXmL5QVE0Iop4NCKvZQvGCZYgP";
    private static final String endpoint = "dysmsapi.aliyuncs.com";
    private static final String signName = "金树林";

    public static String send(String phone, String templateParam, String templateCode) {
        try {
            Config config = new Config().setAccessKeyId(accessKeyId).setAccessKeySecret(accessKeySecret).setEndpoint(endpoint);
            SendSmsRequest sendSmsRequest = new SendSmsRequest().setPhoneNumbers(phone).setSignName(signName).setTemplateCode(templateCode).setTemplateParam(templateParam);
            RuntimeOptions runtime = new RuntimeOptions();
            Client client = new Client(config);
            SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, runtime);
            SendSmsResponseBody body = sendSmsResponse.getBody();
            if (StrUtil.equals("OK", body.getCode())) {
                return body.getCode();
            }
            return null;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}