2 asdfzjs asdfzjs 于 2013.08.09 22:35 提问

web端怎么写手机短信推送,java的

web端怎么写手机短信推送,java的。类似飞信货怎么随便什么api.求大神帮助,只要能发短信就好了

1个回答

fzqzxx
fzqzxx   2017.05.31 14:55

这是发短信的核心代码public class SendMsg_webchinese {

public static void main(String[] args)throws Exception{

    HttpClient client = new HttpClient();
    PostMethod post = new PostMethod("http://gbk.sms.webchinese.cn"); 
    post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=gbk");//在头文件中设置转码
    NameValuePair[] data ={ 
    new NameValuePair("Uid", "本站用户名"),
    new NameValuePair("Key", "接口安全密码"),
    new NameValuePair("smsMob","手机号码"),
    new NameValuePair("smsText","短信内容")
    };
    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("gbk")); 
    System.out.println(result);

    post.releaseConnection();
}

}

Csdn user default icon
上传中...
上传图片
插入图片