package test;
import com.alibaba.fastjson.JSON;
import message.ContainFilter;
import message.MessageContext;
import message.MwRuleSelectParam;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class test11 {
public static void main(String[] args) throws ParseException, IOException, NoSuchAlgorithmException {
String url = "https://sms.189ek.com/yktsms/send?appid=APPID&mobile=MOBILE&msg=MSG&sign=SIGN";
String appid = "appid";
//签名:【写bug】;内容:测试
String msg = "【写bug】测试";
String phone = "1******9,1******8";
String appKey = "appkey";
String sign = appid + phone + msg + appKey;
sign = MD5(sign);
System.out.println(sign);
String msgEncode = URLEncoder.encode(msg,"utf-8");
System.out.println(msgEncode);
url = url.replaceAll("APPID", appid).replaceAll("MOBILE",phone)
.replaceAll("MSG",msgEncode).replaceAll("SIGN",sign);
String result = doPost(url,null,null);
System.out.println(result);
}
public static String doPost(String url, Map<String, Object> param, Map<String, String> header) throws IOException {
// 创建Httpclient对象
HttpClient httpclient = HttpClients.createDefault();
HttpPost httppost = new HttpPost(url);
httppost.addHeader("Content-Type", "application/json; charset=utf-8");
if (header != null) {
for (Map.Entry<String, String> entry : header.entrySet()) {
httppost.addHeader(entry.getKey(), entry.getValue());
}
}
if(param != null){
StringEntity se = new StringEntity(JSON.toJSONString(param), "utf-8");
httppost.setEntity(se);
}
HttpResponse response = httpclient.execute(httppost);
String result = null;
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
result = EntityUtils.toString(response.getEntity());
}
return result;
}
public static String MD5(String strSrc) {
try {
MessageDigest md5 = MessageDigest.getInstance("MD5");
byte[] b = strSrc.getBytes("utf-8");
md5.update(b);
String result = "";
byte[] temp = md5.digest();
String s = "";
for (byte bb : temp) {
s += (bb + " ");
}
for (int i = 0; i < temp.length; i++) {
result += Integer.toHexString((0x000000ff & temp[i]) | 0xffffff00).substring(6);
}
return result;
} catch (NoSuchAlgorithmException e) {
} catch (Exception e) {
}
return "";
}
public static String getSendTouer(HashSet<String> sendPhones) {
StringBuffer touser = new StringBuffer();
if (sendPhones != null && sendPhones.size() > 0 && sendPhones.size() <= 1000) {
Iterator iterator = sendPhones.iterator();
while (iterator.hasNext()) {
touser.append(",").append(iterator.next());
}
}else {
return "";
}
touser.replace(0, 1, "");
return touser.toString();
}
public static String getHostMac(InetAddress ia) throws SocketException {
NetworkInterface byInetAddress = NetworkInterface.getByInetAddress(ia);
byte[] mac = byInetAddress.getHardwareAddress();
StringBuffer sb = new StringBuffer("");
for (int i = 0; i <mac.length ; i++) {
if(i!=0){
sb.append("—");
}
int temp=mac[i]&0xff;
String s = Integer.toHexString(temp);
if(s.length()==1){
sb.append("0"+s);
}else{
sb.append(s);
}
}
return sb.toString().toUpperCase();
}
}
java翼讯通短信对接
最新推荐文章于 2024-04-10 16:46:28 发布