package com.unis.detectionnum.server.message.service.impl;


import com.unis.detectionnum.server.message.service.SubmitDataService;
import com.unis.detectionnum.server.message.utils.ReadXMLByJDom;
import com.unis.detectionnum.server.message.utils.Send;
import com.unis.detectionnum.server.message.entity.SmsDataVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 短信发送 服务实现类
 *
 * @author YangZR
 * @since 2020-03-10
 */
@Service
@Slf4j
@SuppressWarnings("all")
public class SubmitDataServiceImpl implements SubmitDataService {


	/**
	 * 发送短信接口
	 * @version v1.0
	 * @author lfx
	 * @date 2019-2-13 14:04:33
	 * @param smsDataVO
	 * @return
	 * @throws Exception
	 */
	@Override
	public boolean sendingSMS(SmsDataVO smsDataVO) throws Exception {
		String postUrl = "http://cf.51welink.com/submitdata/service.asmx/g_Submit";
		String sname = "dlbjszls";
		String spwd = "wwtl1234";
		String sprdid = "1012888";

//		StringBuilder sb = new StringBuilder();
//		sb.append("sname=").append(sname);
//		sb.append("&spwd=").append(spwd);
//		sb.append("&scorpid=");
//		sb.append("&sprdid=").append(sprdid);
//		sb.append("&sdst=").append(smsDataVO.getSdst());
//		sb.append("&smsg=").append(java.net.URLEncoder.encode(smsDataVO.getSmsg(), "utf-8"));
//		String postData = sb.toString();
		String postData = "sname=dlbjszls&spwd=wwtl1234&scorpid=&sprdid=1012888&sdst=" + smsDataVO.getSdst() + "&smsg="
				+ java.net.URLEncoder.encode(smsDataVO.getSmsg()+"【数量检测平台】", "utf-8");
		//
		String ret = Send.SMS(postData, postUrl);
		List<SmsDataVO> list = ReadXMLByJDom.getBooks(ret);
		if(list.get(0).getState()==0) {//0 发送成功
			return true;
		} else {
			throw new Exception("短信发送失败");
		}

	}
	
}
