凌凯短信接口

凌凯短信接口对接(java)

提交短信BatchSend2

CorpID 账号 String
Pwd 密码 String
Mobile 发送手机号码 String
群发(号码之间用英文逗号隔开,建议500个号码)例如:13812345678,13519876543,15812349876
Content 发送内容 (RULencoder的GBK或GB2312编码) String
Cell 扩展号(必须为数字或为空) String
SendTime 定时发送时间(可为空) String(14)

返回值参数

大于0的数字 提交成功
–1 账号未注册
–2 其他错误
–3 帐号或密码错误
–5 余额不足,请充值
–6 定时发送时间不是有效的时间格式
-7 提交信息末尾未签名,请添加中文的企业签名【 】
–8 发送内容需在1到300字之间
-9 发送号码为空
-10 定时时间不能小于系统当前时间
-100 IP黑名单
-102 账号黑名单
-103 IP未导白

需要的jar包

commons-codec-1.10.jar
commons-logging-4.0.6.jar
httpclient-4.5.2.jar
httpcore-4.4.4.jar

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.AuthCache;
import org.apache.http.client.CredentialsProvider;
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.client.protocol.HttpClientContext;
import org.apache.http.impl.client.BasicAuthCache;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;


public class LinkSMS {
	  private String CorpID = "账号";// 接口账户名
	  
	  private String Pwd = "密码";// 接口密码
	  

  public static String HttpClientTest(String mobile,String content) {
  		    String result="";
       	try {
			CloseableHttpClient httpclient = HttpClients.createDefault();
			AuthCache authCache = new BasicAuthCache();
			HttpClientContext context = HttpClientContext.create();
			context.setAuthCache (authCache);
			//2.封装短信接口参数
			List<NameValuePair> params = new ArrayList<NameValuePair>();  
			params.add(new BasicNameValuePair("CorpID", CorpID));
			params.add(new BasicNameValuePair("Pwd",Pwd));
			params.add(new BasicNameValuePair("Mobile", mobile));
			params.add(new BasicNameValuePair("Content", content));
			params.add(new BasicNameValuePair("Cell", ""));
			params.add(new BasicNameValuePair("SendTime", ""));
			HttpEntity entity = new UrlEncodedFormEntity(params,"GBK");
			//3.提交访问地址
			HttpPost request = new HttpPost ("https://sdk2.028lk.com/sdk2/BatchSend2.aspx");
			request.setEntity(entity);
			//4.提交访问短信接口
			CloseableHttpResponse response = httpclient.execute(request);
			//5.获取返回值并解析
			HttpEntity entity2 = response.getEntity();
            BufferedReader br = new BufferedReader(new InputStreamReader(entity2.getContent(), "GBK"));  
            String line="";  
            while ((line = br.readLine()) != null) {  
            	result+= line+"\n";  
            }  
	        //4.关闭链接
            br.close();  
	        response.close ();
	        httpclient.close ();
       	} catch (Exception e) {
       		e.getLocalizedMessage();
   		}	
       	return result;
     }
      /**
      *main测试
      */
    public static void main(String[] args) {
    	String message="您的验证码为:233112,有效时间5分钟。【凌凯通信】";
		String phone="15881014695";
		
		String result=LinkSMS.HttpClientTest(phone,message);
		System.out.println("----------------接口提交返回值-------------------"); 
	    System.out.print(result); 
	    System.out.println("----------------------------------------------");
	    //对返回值的判断。。。此处省略
	}
}

代码仅供参考,学习阶段,大神们多多指正,虚心学习

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值