天天看点

java web 项目向手机发送短信

璇存槑锛孞AVA鍙戦€佹墜鏈虹煭淇?娴佷紶鏈夊嚑绉嶆柟娉?(1)浣跨敤webservice鎺ュ彛鍙戦€佹墜鏈虹煭淇?杩欎釜鍙互浣跨敤sina鎻愪緵鐨剋ebservice杩涜鍙戦€?浣嗘槸闇€瑕佽繘琛屾敞鍐?(2)浣跨敤鐭俊mao鐨勬柟寮忚繘琛岀煭淇$殑鍙戦€?杩欑鏂瑰紡搴旇鏄瘮杈冪殑甯哥敤,鍓嶆彁鏄渶瑕佽喘涔扮‖浠惰澶? (3)浣跨敤涓浗缃戝缓鎻愪緵鐨凷MS鐭俊骞冲彴.

杩欓噷浣跨敤涓浗缃戝缓鎻愪緵鐨凙PI缁欐墜鏈哄彂閫佺煭淇°€備负浜嗕娇鐢ㄤ腑鍥界綉寤虹粰瀵规柟鎵嬫満鍙戦€佺煭淇★紝闇€瑕佷互涓嬪嚑姝ユ搷浣滐細

1.鐧诲綍涓浗缃戝缓锛屽湴鍧€涓猴細http://sms.webchinese.cn/

2.娉ㄥ唽锛屾敞鍐屽悗浣犲氨浼氭湁鐢ㄦ埛鍚嶅拰瀵嗙爜锛屽瘑鐮佷細鑷姩鍙戝埌浣犵殑鎵嬫満閲?

3.鑾峰彇缃戠鎺ュ彛瀵嗙爜锛岃嚦浜庡浣曡幏寰楃綉鍏虫帴鍙e瘑鐮侊紝鎴戞槸杩欐牱鍋跺皵鑾峰緱鐨勶紙娉ㄦ剰锛岃繖閲岀殑缃戠鎺ュ彛瀵嗙爜骞朵笉鏄綘娉ㄥ唽鏃跺彂閫佸埌浣犳墜鏈洪噷鐨勫瘑鐮侊紝閭e瘑鐮佹槸鐧诲綍瀵嗙爜锛夈€傚湪璇ョ綉绔欓噷灏濊瘯鍙戜竴鏉$煭淇★紝鍙戠煭淇℃椂浼氭湁鐩稿簲鐨勬彁绀猴紝鍦ㄥ彂閫佺殑杩囩▼涓細鍑虹幇浣犵殑缃戝叧鎺ュ彛瀵嗙爜銆?

娉ㄦ剰锛氫綘瑕佷繚瀛樺ソ浣犵殑缃戝叧鎺ュ彛绉樺瘑锛屽洜涓烘瘡娆″綋浣犱娇鐢ㄤ唬鐮佸彂閫佷俊鎭椂閮介渶瑕佽繖涓綉鍏虫帴鍙e瘑鐮併€?

浠ヤ笅浠g爜鎵€浣跨敤鐨刯ar鍙互浠巋ttp://sms.webchinese.cn/鐩存帴鑾峰緱銆?

import java.io.UnsupportedEncodingException;

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_webchinese {

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

HttpClient client = new HttpClient();

PostMethod post = new PostMethod(鈥渉ttp://gbk.sms.webchinese.cn鈥?;

post.addRequestHeader(鈥淐ontent-Type鈥?

鈥渁pplication/x-www-form-urlencoded;charset=gbk鈥?;// 鍦ㄥご鏂囦欢涓缃浆鐮?

NameValuePair[] data = { new NameValuePair(鈥淯id鈥? 鈥滃湪杩欓噷濉啓鍦ㄤ腑鍥界綉寤烘敞鍐岀殑鐢ㄦ埛鍚嶁€?,

new NameValuePair(鈥淜ey鈥? 鈥滃湪姝ゅ~鍐欑綉鍏虫帴鍙e瘑鐮佲€?,

new NameValuePair(鈥渟msMob鈥? 鈥滃湪杩欓噷濉啓鍙戦€佺洰鐨勫湴鎵嬫満鍙封€?,

new NameValuePair(鈥渟msText鈥? 鈥滃湪姝ゅ~鍐欑煭淇″唴瀹光€? };

post.setRequestBody(data);

client.executeMethod(post);

Header[] headers = post.getResponseHeaders();

int statusCode = post.getStatusCode();

System.out.println(鈥渟tatusCode:鈥?+ statusCode);

for (Header h : headers) {

System.out.println(h.toString());

}

String result = new String(post.getResponseBodyAsString().getBytes(

鈥済bk鈥?);

System.out.println(result);

post.releaseConnection();

}

}

继续阅读