第一步,登录中国网建注册账号并设置短信签名(设置短信签名很重要,不然一直返回-51短信签名格式不正确)
第二步,上代码
public static void main(String[] args) { //获得http链接对象 HttpClient httpClient = HttpClient.singleInstacne(); String url="http://utf8.api.smschinese.cn"; //中国网建账号 String Uid="xxxx0"; //中国网建秘钥 String Key="d41d8cd98f00bxxxxx"; //要发送的手机号 String smsMob="187xxxx"; //短信内容 String smsText="你好"; String message=null; try { message=httpClient.sendWithPost(url+"?Uid="+Uid+"&Key="+Key+"&smsMob="+smsMob+"&smsText="+smsText,""); System.out.println(message); } catch (IOException e) { e.printStackTrace(); } }
