JAVA通过http调用验证码短信接口源码

通过验证码短信http调用接口,您可以很快速的在网站或者app中集成手机号验证功能,该源码只是核心代码,具体可以根据您的实际需求进行扩展。

该DEMO是JAVA通过http调用验证码短信接口源码;

//import java.io.FileInputStream;
//import java.io.FileNotFoundException;

import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

public class sendsms {
	
	private static String Url = "http://106.ihuyi.com/webservice/sms.php?method=Submit";
	
	public static void main(String [] args) {
		
		HttpClient client = new HttpClient(); 
		PostMethod method = new PostMethod(Url); 
			
		//client.getParams().setContentCharset("GBK");		
		client.getParams().setContentCharset("UTF-8");
		method.setRequestHeader("ContentType","application/x-www-form-urlencoded;charset=UTF-8");

	    String content = new String("您的验证码是:7528。请不要把验证码泄露给其他人。"); 
	    
		NameValuePair[] data = {//提交短信
			    new NameValuePair("account", "用户名"), 
			    new NameValuePair("password", "密码"), 			    
			    new NameValuePair("mobile", "手机号码"), 
			    new NameValuePair("content", content),
		};
		
		method.setRequestBody(data);		
		
		
		try {
			client.executeMethod(method);		
			System.out.println(method.getResponseBodyAsString());
			
		} catch (HttpException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}	
		
		//System.out.println("短信提交成功");
	}
	
} 


自助申请帐户地址:http://www.ihuyi.com/product.php
完整接口文件地址:http://www.ihuyi.com/upload/file/cu-fa-jie-kou.rar 

你可能感兴趣的:(短信接口技术)