package com.upyuns.platform.rs.universal.service;

import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.sms.v20190711.SmsClient;
import com.tencentcloudapi.sms.v20190711.models.SendSmsRequest;
import com.tencentcloudapi.sms.v20190711.models.SendSmsResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @ClassName : TencentSmsService
 * @Description : 腾讯云短信服务
 * @Author : jiaoruizhen
 * @Date: 2020-12-29 14:39
 */
@Service
@Slf4j
public class TencentSmsService {


	public ObjectRestResponse sendSms(String phone, String message) {
		try{

			Credential cred = new Credential("AKIDkfPxIRmqxlgOuDv2XVKgqtlII6waAzPe", "FZhqmqjOQGtJl1PehXD8uhJ1ItHSTH7o");

			HttpProfile httpProfile = new HttpProfile();
			httpProfile.setEndpoint("sms.tencentcloudapi.com");

			ClientProfile clientProfile = new ClientProfile();
			clientProfile.setHttpProfile(httpProfile);

			SmsClient client = new SmsClient(cred, "", clientProfile);

			String params = "{\"PhoneNumberSet\":[\"+86"+ phone +"\"],\"TemplateID\":\"365123\",\"Sign\":\"中科光启\",\"TemplateParamSet\":[\""+message+"\"],\"SmsSdkAppid\":\"1400227859\"}";
			SendSmsRequest req = SendSmsRequest.fromJsonString(params, SendSmsRequest.class);

			SendSmsResponse resp = client.SendSms(req);
			return ObjectRestResponse.succ(resp);
		} catch (TencentCloudSDKException e) {
			System.out.println(e.toString());
		}
		return ObjectRestResponse.succ();
	}

	public static void main(String [] args) {

	}

}
