①百度秒嘀 进入并注册 会赠送10元 大约200条 足够测试了
②得到accountID和token
③找到API
‘
⑤创建一个模板,你的内容只有和你的模板对应好了才会发送成功。
⑥写一个JAVA程序测试
如果会写的 直接根据API写就行了
我这里用的HttpClient来实现的 代码:
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
public class Main {
// 连接ssl
public static void main(String[] args) {
post();
}
public static void post() {
// 创建默认的httpClient实例.
CloseableHttpClient httpclient = HttpClients.createDefault();
// 创建httppost
HttpPost httppost = new HttpPost(
"https://api.miaodiyun.com/20150822/industrySMS/sendSMS");
List<NameValuePair> formparams = new ArrayList<NameValuePair>();
String accountSid = "你的accountSid";
String token = "你的token";
formparams.add(new BasicNameValuePair("accountSid", accountSid));
formparams.add(new BasicNameValuePair("smsContent", "【计科学院】你好,你已经成功进入学生会,请及时联系部长。"));
formparams.add(new BasicNameValuePair("to", "15028435695"));
Date date = new Date();
DateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
String timestamp = df.format(date);
formparams.add(new BasicNameValuePair("timestamp", timestamp));
String sig = MD5.toMD5(accountSid + token + timestamp);
formparams.add(new BasicNameValuePair("sig", sig));
UrlEncodedFormEntity uefEntity;
try {
uefEntity = new UrlEncodedFormEntity(formparams, "UTF-8");
httppost.setEntity(uefEntity);
System.out.println("executing request " + httppost.getURI());
CloseableHttpResponse response = httpclient.execute(httppost);
System.out.println(EntityUtils.toString(uefEntity,"UTF-8"));
try {
HttpEntity entity = response.getEntity();
if (entity != null) {
System.out.println("--------------------------------------");
System.out.println("Response content: " + EntityUtils.toString(entity, "UTF-8"));
System.out.println("--------------------------------------");
}
} finally {
response.close();
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
// 关闭连接,释放资源
try {
httpclient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
’