SendSMSHelper.java 1.85 KB
/**
 * 
 */
package com.yoho.unions.helper;

import com.yoho.core.common.utils.AES;
import com.yoho.unions.utils.HttpUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.net.URLEncoder;

/**
 * @author ping.huang 2016年6月2日
 */
@Component
public class SendSMSHelper {

	static Logger log = LoggerFactory.getLogger(SendSMSHelper.class);

	private String aesKey = "yoho96461qaz2wsx";
	//使用玄武发短信
	private String smsUrl = "http://211.147.239.62:9050/cgi-bin/sendsms";
	private String smsName = "yohoyx@yohoyx";
	private String smsPwd = "EH+iuWSAfINJYwSdPgVqhA==";

	public void sendNoticeSms(String mobile, String content) {
		try {
			String pwd = AES.decrypt(aesKey, smsPwd);
			String text = URLEncoder.encode(content, "GBK");
//			String url = smsUrl + "?username=" + smsName + "&password=" + pwd + "&to=" + mobile + "&text=" + text + "&msgtype=1";
//			AsyncFuture<String> response = serviceCaller.get("sms.sendSMS", url, null, String.class, null);
//			String result = response.get();
			
			String url = smsUrl + "?username=" + smsName + "&password=" + pwd + "&to=" + mobile + "&text=" + text + "&msgtype=1";
			Pair<Integer, String> pair = HttpUtils.httpGet(url, null);
			
			log.info("sendSMS result is {}, mobile is {}", pair, mobile);
		} catch (Exception e) {
			log.error("sendSMS error decrypt error with aesKey={}, smsPwd={}", aesKey, smsPwd, e);
			return;
		}

	}
	
	public static void main(String[] args) {
		String msg = "【Yoho!Buy有货】恭喜您获得新人礼!您的登录账户是13951882433,密码是12345687544554;下载Yoho!Buy有货手机端   http://a.app.qq.com/o/simple.jsp?pkgname=com.yoho, 更多惊喜等着您!【有货】";
		SendSMSHelper s = new SendSMSHelper();
		s.sendNoticeSms("13951882433", msg);
	}
}