云信 短信发送 demo

2018-06-18 03:48:41来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

package com.dataTaskListener;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

//全文模板发送
public class SendMsg{
    public static String  sendMSM(String phone,String number){
        try {                    
            HttpClient client = new HttpClient();
            PostMethod post = new PostMethod("http://api.sms.cn/sms/"); 
            post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=utf-8");//在头文件中设置转码
            NameValuePair[] data ={ new NameValuePair("ac", "send"),new NameValuePair("uid", ""),new NameValuePair("pwd", ""),new NameValuePair("mobile",phone),
                     new NameValuePair("encode","utf8"),new NameValuePair("template",""),new NameValuePair("content","{\"number\":\""+number+"\"}")}; post.setRequestBody(data); client.executeMethod(post); Header[] headers = post.getResponseHeaders(); int statusCode = post.getStatusCode(); //System.out.println("statusCode:"+statusCode); for(Header h : headers){ //System.out.println(h.toString()); } String result = new String(post.getResponseBodyAsString().getBytes("utf-8")); //返回信息 //System.out.println(result); //打印返回消息状态 post.releaseConnection(); return result; } catch (Exception e) { e.printStackTrace(); } return null; } }

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:java web response提供文件下载功能

下一篇:Java学习笔记42(序列化流)