package com.qirui.senddemo; import java.net.URLEncoder; import org.apache.http.HttpEntity; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; public class SendDemo { public static void main(String[] args) throws Exception { String url = "http://api.duanxin.com:7891/mt" ; //apiKey和apiSecret String apiKey = "2288**0010" ; String apiSecret = "ae2600e9456f5b0b3ab8" ; //接受手机号 String mobile = "18500000000" ; //短信内容(【签名】+短信内容),发送短信需要预先申请报备短信签名,控制台>接口短信>签名报备 String message = "【短信网】您的验证码是:5277" ; StringBuilder sb = new StringBuilder( 2000 ); sb.append(url); sb.append( "?dc=15" ); sb.append( "&sm=" ).append(URLEncoder.encode(message, "utf8" )); sb.append( "&da=" ).append(mobile); sb.append( "&un=" ).append(apiKey); sb.append( "&pw=" ).append(apiSecret); sb.append( "&tf=3&rf=2&rd=0" ); //短信内容编码为 urlencode+utf8 String request = sb.toString(); //System.out.println(request); CloseableHttpClient client = HttpClients.createDefault(); HttpGet httpGet = new HttpGet(request); CloseableHttpResponse response = client.execute(httpGet); String respStr = null ; HttpEntity entity = response.getEntity(); if (entity != null ) { respStr = EntityUtils.toString(entity, "UTF-8" ); } System.out.println(respStr); } } |
√ 短信接口 :
1)短信内容一定要带签名,签名放在短信内容的最前面;
2)签名格式:【***】,签名内容为三个汉字以上(包括三个);
3)短信内容不允许双签名,即短信内容里只有一个"【】";
4)短信签名先申请报备后使用,控制台>接口短信>签名报备;