SendSMSHelper.java
1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
*
*/
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);
}
}