短信平台接口调用方法参考

http请求

//说明:此处需引用httpclient、httpcore、commons-logging三个jar包

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.*;
import java.security.MessageDigest;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.*;
import javax.crypto.SecretKey;
import javax.crypto.spec.DESKeySpec;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.SecretKeyFactory;
import javax.crypto.Cipher;

public static void main(String[] args) {
String url="http://xxx.com/api/MsgSend.asmx/SendMes";

List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("userCode", "用户名"));
nvps.add(new BasicNameValuePair("userPass", "密码"));
nvps.add(new BasicNameValuePair("DesNo", "手机号"));
nvps.add(new BasicNameValuePair("Msg", "短信内容【签名】"));
nvps.add(new BasicNameValuePair("Channel", "通道号"));
String post=httpPost(url,nvps); //post请求

String getparam="userCode=用户名&userPass=密码&DesNo=手机号&Msg=短信内容【签名】&Channel=通道号";
String result=httpGet(url,getparam); //get请求
}

public static String httpPost(String url,List<NameValuePair> params) {
String result = "";
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
HttpResponse response = httpclient.execute(httpPost);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instreams = entity.getContent();
result = convertStreamToString(instreams);
System.out.println(result);
}
} catch (Exception e) {
}
return result;
}

public static String httpGet(String url,String params){
String result="";
try{
HttpClient client=new DefaultHttpClient();
if(params!=""){
url=url+"?"+params;
}
HttpGet httpget=new HttpGet(url);
HttpResponse response=client.execute(httpget);
HttpEntity entity=response.getEntity();
if (entity != null) {
InputStream instreams = entity.getContent();
result = convertStreamToString(instreams);
System.out.println(result);
}
}catch(Exception e){}
return result;
}

public static String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();

String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}

webservice请求

public static void main(String[] args) {
org.tempuri.MsgSend service = new org.tempuri.MsgSend();
org.tempuri.MsgSendSoap port = service.getMsgSendSoap();
String result= port.sendMes("用户名","密码","手机号","短信内容【签名】","通道号");
System.out.println(result);
}

时间: 2024-11-08 16:58:50

短信平台接口调用方法参考的相关文章

短信平台接口调用方法(java语言)

//说明:此处需引用httpclient.httpcore.commons-logging三个jar包 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.*; import java.security.MessageDigest; import org.apache.htt

php编程之短信发送接口调用流程的实现

对于一个交互型网站来说,需要用户来登录注册使用,那么一般网站的技术人员肯定需要实现注册时的短信发送功能,但是这个功能很多技术人员发现在添加的过程中有许多问题,要么是无法接收,要么就是时间慢等等原因,对于这个问题,下面就跟大家说一下如何快速有效的实现. 本文主要讲解的是如何利用m.5c.com.cn短信平台发送短信的过程中遇到的问题及接口调用流程实现. 1.打开php.ini,找到extension=php_openssl.dll,将前面的分号去掉,重启服务器.若此配置已打开,跳过这一步. 2.发

【ASP】创蓝253云通讯paas平台短信验证码接口调用demo

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%><%Function Post(url,data)dim Https set Https=server.createobject("MSXML2.XMLHTTP")Https.open "POST",url,falseHttps.setRequestHeader "Content-Type","ap

短信平台接口

1. ASP 调用例子<%'常用函数'输入url目标网页地址,返回值getHTTPPage是目标网页的html代码function getHTTPPage(url)dim Httpset Http=server.createobject("MSXML2.XMLHTTP")Http.open "GET",url,falseHttp.send()if Http.readystate<>4 then exit functionend ifgetHTTPP

云极知客开放平台接口调用方法(C#)

云极知客为企业提供基于SAAS的智能问答服务.支持企业个性化知识库的快速导入,借助语义模型的理解和分析,使企业客户立即就拥有本行业的24小时客服小专家.其SAAS模式实现零成本投入下的实时客服数据的可视化,优化企业业务流程,指导企业决策. 说白了,其实就是一个智能客服机器人,你可以和他聊天,也可以和他扯淡,但重要的是,你可以用他为客服,教他东西,解放自己.OK,广告到此,下面看看接口相关的东西. 云极知客的接口文档请点击这里. 以下使用C#.NET介绍两个接口的调用方法,平台接口均设置为POST

【原创】起步互联网公司内部短信平台杂谈

前言 陆陆续续间间隔隔开发公司短信平台接口已经一段时间了,在年末的时候找个空闲把觉得实际可行的东西记录下来. 想了想,感觉这东西应该没啥好说的,但是又觉得哪里需要记一记,以后换个工作环境,还来一发呢,不就可以避免不必要的坑. 毕竟在实现短信接口的过程中,看似简单,但是有许多需要注意的地方和可以一步到位的地方可以记录下来,请大牛们分享探讨不足指正. 来吧,整理整理思绪. 开发背景 由于公司的APP端.微信公众号端.各种后台端和报警机制端等等的一系列应用和系统都需要用到一个基础功能:发短信.所以一开

C#调用短信接口(通过简单的工厂模式整合多个短信平台)

using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Text; using System.Web; namespace DUANXIN { public class SendSmsFactory { public static SendSmsBase CreateFactory(string className) { S

【PYTHON】创蓝253云通讯平台国际短信API接口DEMO

#!/usr/local/bin/python#-- coding:utf-8 -- Author: jacky Time: 14-2-22 下午11:48 Desc: 短信http接口的python代码调用示例 import httplibimport urllibimport json#服务地址 host = "intapi.253.com" #端口号port = 80 #版本号version = "v1.1" #查账户信息的URIbalance_get_uri

PHP短信接口分享:适用于创蓝253平台下的短信验证码、短信服务接口

<?phpheader("Content-type:text/html; charset=UTF-8"); class ChuanglanSmsApi { //发送短信的接口地址 const API_SEND_URL='http://sms.253.com/msg/send?'; //查询余额的接口地址 const API_BALANCE_QUERY_URL='http://sms.253.com/msg/balance?'; const API_ACCOUNT='*******