共计 3334 个字符,预计需要花费 9 分钟才能阅读完成。
本文丸趣 TV 小编为大家详细介绍“java 短信接口怎么用”,内容详细,步骤清晰,细节处理妥当,希望这篇“java 短信接口怎么用”文章能帮助大家解决疑惑,下面跟着丸趣 TV 小编的思路慢慢深入,一起来学习新知识吧。
短信发送接口 1.1 请求地址
请求地址是客户接口程序调用时请求的 url 地址,采用的是 https post 接口,地址是
https://sh3.ipyy.com/sms.aspx 对应 UTF-8
https://sh3.ipyy.com/smsGBK.aspx 对应 GB2312
https://sh3.ipyy.com/smsJson.aspx 对应 UTF-8(返回值为 json 格式)
https://sh3.ipyy.com/ensms.ashx 对应 UTF-8(加密传输, 使用 json)
入口地址一般不会发生变化,当发生变化的时候,会通知接口用户
1.2 参数说明
参数名称
含义
说明
userid
企业 id
企业 ID(不验证)
account
发送用户帐号
用户帐号,由系统管理员
password
发送帐号密码
用户账号对应的密码
可以使用明文,也可以全用 md5 加密方式,md5 采用 32 位大写
如 abc123 加密后为
E99A18C428CB38D5F260853678922E03
mobile
全部被叫号码
短信发送的目的号码. 多个号码之间用半角逗号隔开
content
发送内容
短信的内容,内容需要 UTF- 8 编码,提交内容格式:内容 +【签名】。签名是公司的名字或者公司项目名称。示例:您的验证码:1439【腾飞】。【】是签名的标识符。请按照正规的格式提交内容测试
sendTime
定时发送时间
为空表示立即发送,定时发送格式 2010-10-24 09:08:10
action
发送任务命令
设置为固定的:send
extno
扩展子号
请先询问配置的通道是否支持扩展子号,如果不支持,请填空。子号只能为数字,且最多 5 位数。
例如:
https://sh3.ipyy.com/sms.aspx?action=send userid= account= 账号 password= 密码 mobile=15023239810,13527576163 content= 内容 sendTime= extno=
1.3 返回值
在接收到客户端发送的 https 请求后,返回以 xml 的方式返回处理结果。格式为:
?xml version= 1.0 encoding= utf-8 ?
returnsms
returnstatus status /returnstatus ———- 返回状态值:成功返回 Success 失败返回:Faild
message message /message ———- 相关的错误描述
remainpoint remainpoint /remainpoint ———- 返回余额
taskID taskID /taskID ———– 返回本次任务的序列 ID
successCounts successCounts /successCounts – 成功短信数:当成功后返回提交成功短信数
/returnsms
1.4 Json 返回值
{returnstatus : Success ,
message : 操作成功 ,
remainpoint : -4 ,
taskID : 1504080852350206 ,
successCounts : 1 }
package com.yy.test;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.json.JSONObject;
import sun.misc.BASE64Encoder;
public class HttpEnsms {
/**
* http 加密
* @param args
*/
public static void main(String[] args) {
SimpleDateFormat df=new SimpleDateFormat(MMddHHmmss
String Stamp = df.format(new Date());
String password= 123456
String Secret=MD5.GetMD5Code(password+Stamp).toUpperCase();
try {
JSONObject j=new JSONObject();
j.put(UserName , qq
j.put(Stamp , Stamp);
j.put(Secret , Secret);
j.put(Moblie , 17721077856 // 可以 call 协助对接
j.put(Text , 您的验证码是:8859【华信】
j.put(Ext ,
j.put(SendTime ,
// 获取 json 字符串
String json=j.toString();
byte[] data=json.getBytes( utf-8
byte[] key=password.getBytes();
// 获取加密的 key
byte[] nkey=new byte[8];
System.arraycopy(key, 0, nkey, 0, key.length 8 ? 8 : key.length);
//Des 加密,base64 转码
String str=new BASE64Encoder().encode(DesHelper.encrypt(data, nkey));
System.out.println(str);
//url 编码
//str=URLEncoder.encode(str, utf-8
// 发送 http 请求
String Url= http://42.96.205.165/ensms.ashx
HttpClient client=new HttpClient();
PostMethod post=new PostMethod(Url);
post.setRequestHeader(Content-type , application/x-www-form-urlencoded;charset=utf-8
NameValuePair UserId=new NameValuePair(UserId , 1
NameValuePair Text64=new NameValuePair(Text64 ,str);
post.setRequestBody(new NameValuePair[]{UserId,Text64});
int statu=client.executeMethod(post);
System.out.println(statu= +statu);
// 返回结果
String result=post.getResponseBodyAsString();
System.out.println(result= +result);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
读到这里,这篇“java 短信接口怎么用”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注丸趣 TV 行业资讯频道。