package com.mmc.iuav.user.util;

import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.teaopenapi.models.Config;
import com.google.gson.Gson;

/**
 * @author: zj
 * @Date: 2023/7/25 17:00
 */
public class SmsUtil {

    public static String ALIYUN_OSS_ACCESS_KEY_ID = "LTAI5tS3GNPRZAkG9LCQBZmc";
    public static String ALIYUN_OSS_ACCESS_KEY_SECRET = "ZkPrv1u2mN2DmOIc7GfPKRuy4Risqe";

    public static String CLOUD_JOIN_WEBSITE = "云享飞";

    private static String ENDPOINT = "dysmsapi.aliyuncs.com";
    /**
     *
     * 加盟审核通过
     */
    private static String COOPERATION_TEMPLATE_PASS_CODE_0 = "SMS_461986130";
    private static String COOPERATION_TEMPLATE_PASS_CODE_2 = "SMS_462240459";
    private static String COOPERATION_TEMPLATE_PASS_CODE_3 = "SMS_462620535";
    private static String COOPERATION_TEMPLATE_PASS_CODE_4 = "SMS_462605558";
    private static String COOPERATION_TEMPLATE_PASS_CODE_5 = "SMS_464125992";
    private static String COOPERATION_TEMPLATE_PASS_CODE_6 = "SMS_464380042";

    private static String COOPERATION_TEMPLATE_PASS_CODE_7 = "SMS_464335035";
    //短信验证码模板
    private static String VERIFYCODE="SMS_211825548";

    /**
     * 加盟审核未通过
     */
    private static String COOPERATION_TEMPLATE_CODE_1 = "SMS_462095054";

    public static String sendPassCooperationApply(String phone) {
        return send(CLOUD_JOIN_WEBSITE, COOPERATION_TEMPLATE_PASS_CODE_5, null, phone);
    }

    public static String sendNotPassCooperationApply(String phone) {
        return send(CLOUD_JOIN_WEBSITE, COOPERATION_TEMPLATE_CODE_1, null, phone);
    }

//    飞手审核通过通知
    public static String sendPassPilotApply(String phone) {
        return send(CLOUD_JOIN_WEBSITE, COOPERATION_TEMPLATE_PASS_CODE_6, null, phone);
    }

    //飞手提现通知
    public static String sendPassWithdrawalApply(String phone) {
        return send(CLOUD_JOIN_WEBSITE, COOPERATION_TEMPLATE_PASS_CODE_7, null, phone);
    }

    public static String send(String TemplateCode, String param, String phone) {
        return send(CLOUD_JOIN_WEBSITE, TemplateCode, param, phone);
    }

    public static String send(String signName, String TemplateCode, String param, String phone) {
        Config config = new Config().setAccessKeyId(ALIYUN_OSS_ACCESS_KEY_ID).setAccessKeySecret(ALIYUN_OSS_ACCESS_KEY_SECRET);
        config.endpoint = ENDPOINT;
        com.aliyun.dysmsapi20170525.Client client = null;
        SendSmsRequest request = new SendSmsRequest();
        request.setPhoneNumbers(phone);
        request.setSignName(signName);
        request.setTemplateCode(TemplateCode);
        if (param != null) {
            request.setTemplateParam(param);
        }
        SendSmsResponse response = null;
        try {
            client = new com.aliyun.dysmsapi20170525.Client(config);
            response = client.sendSms(request);
        } catch (Exception e) {
            return e.getMessage();
        }
        return new Gson().toJson(response.body);
    }

    /**
     * 短信验证码
     * @param verifyCode
     * @param phone
     * @return
     */
    public  static String verifyCode(String verifyCode,String phone){
        return send(VERIFYCODE,"{\"code\":\""+verifyCode+"\"}",phone);
    }
}
