package com.bjtdba.utils;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.teautil.models.RuntimeOptions;

/**
 * 阿里云验证码发送util
 */

public class aliyunDysmsapiUtil {

    public static Client createClient(String accessKeyId, String accessKeySecret) throws Exception{
        Config config = new Config()
                  // 您的 AccessKey ID
                  .setAccessKeyId(accessKeyId)
                  // 您的 AccessKey Secret
                  .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new Client(config);
    }
    public static SendSmsResponse ceshi(String phone,int mobile_code) throws Exception {
        Client client = aliyunDysmsapiUtil.createClient("LTAI5tKivJSckMYz5BHev3u8","nvetSdLB1YP7OgvpJcVeyhdJDVs4Ik");
        String code = "{\"code\":"+mobile_code+"}";
        SendSmsRequest sendSmsRequest = new SendSmsRequest();
        sendSmsRequest.setSignName("融合华夏");
        sendSmsRequest.setTemplateCode("SMS_311255692");
        sendSmsRequest.setPhoneNumbers(phone);
        sendSmsRequest.setTemplateParam(code);
        RuntimeOptions runtime = new RuntimeOptions();
        // 复制代码运行请自行打印 API 的返回值
        SendSmsResponse sendSmsResponse = client.sendSmsWithOptions(sendSmsRequest, runtime);
        System.out.println(sendSmsResponse);
        return sendSmsResponse;
    }
}
