第一步:注册成为应用工厂用户,并完善必要的资料;第二步:用户登录应用工厂;第三步:购买发送短信API接口;第四步:订购后,在API频道个人账户中心查询APID和密钥;第五步:编写程序,根据获取的APID和密钥调用“发送短信API接口”;第六步:进入“个人账户中心”,查看短信使用情况。注意:短信少于70个字按一条计费;短信超过70字按每67字一条进行计费
public class LongSMSDemo {
private static int CONNECTION_TIMEOUT = 100000;
private static int SO_TIMEOUT = 120000;
public static void main(String[] args) {
long a= System.currentTimeMillis();
String statusReportUrl = "http://125.64.11.40/HttpReport/StatusReport";//状态上报地址
String timeStamp = null;
String apID = "00000000";//APID有应用工厂分配
String key = null;
String numb = "13660360426";//短信接收号码
Date nowTime = new Date(System.currentTimeMillis());
SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
timeStamp = sDateFormat.format(nowTime);//14位时间戳
String msg = "发财发财,大家发财!";
try {
DESCoder.strkey="NjMxMDE1ODQ1OTMyNTY4MjAxNzk0Njkw";//应用工厂分配的加密密钥
key= DESCoder.desEncrypt(timeStamp+apID);//3DES加密
} catch (Exception e1) {
}
smsArg.put("APID",apID);
smsArg.put("Key",key);//3DES加密TimeStamp+APID得到的密文
smsArg.put("Num", numb);//消息接收号码
smsArg.put("Msg", msg);//消息内容
smsArg.put("TimeStamp", timeStamp);//14位时间戳
smsArg.put("IsReport", "0");//是否需要上报短信发送状态,0需要,1不需要
smsArg.put("StatusReportUrl", statusReportUrl);//状态上报地址
smsArg.put("ProductID", "100000000000000000000");//产品ID,由应用工厂分配
smsArg.put("IsUse","0");//是否在短信回复中使用备用参数
smsArg.put("Parm1", "12");//备用参数1
smsArg.put("Parm2", "34");//备用参数2
smsArg.put("Parm3", "56");//备用参数3
input.put("serviceId", "00001020101130");//长短信业务的业务ID
input.put("params", smsArg);
}
namespace LongSMS
{
class Request
{
public string request()
{
string StatusReport = "http://125.64.11.42:8080/Servlet/ServletDemo";
string numb = "";
string msg = "群年度总结一年已经快过去了,元旦马上就要到了,
作为本群一员,现在把群里的工作情况做如下工作汇报:在一年里,
我们紧密扎根在群里,高举“有空必来,有来必言,
弘扬“一不怕手酸,二不怕加班”的大无畏精神,把“保持联系,
经常骚扰”作为振兴群的第一要务!从根本上改变了“几天来一趟,
想到才来上,来了不说话,逛逛就走人”的局面!留言有新思想,
灌水有新思路,吹牛有新突破,抬杠有新局面!";
Uri servletURL = new
Uri("http://125.64.11.43:8080/udt-see/StartServiceServlet");
WebClient client = new WebClient();
client.Headers.Add("Content-type", "text/html;charset=utf-8");
client.Encoding = Encoding.UTF8;
string timeStamp = DateTime.Now.ToString("yyyyMMddHHmmss");
key = Request.Encrypt3Des(timeStamp + apid, key);
JSON js = new JSON();
js.addItem("APID", apid);
js.addItem("Key", key);//3DES加密TimeStamp+APID得到的密文
js.addItem("Num", numb);//消息接收号码
js.addItem("Msg", msg);//消息内容
JSON json = new JSON();
json.addItem("serviceId", serviceId);
json.addItems("params", js.ToString());
//发送客户端请求到服务器,并获得返回值
return client.UploadString(
servletURL.ToString(), "POST", json.ToString());
}
}
}
sendLongSMS($apid, $TimeStamp, $Key, $Num,$Msg,$IsReport,$ReportURL,$IsUse,$UserID,$productID,$PIdType,$Parm1,$Parm2,$Parm3,$serviceID,$url);
$sessionid = $returnStr->returnParams->SessionID;
$result = $returnStr->returnParams->Result;
$returnCode = $returnStr->returnCode;
$returnMsg = $returnStr->returnMsg;
$msg = $returnStr->returnParams->Msg;
//print_r($returnStr);
echo "TimeStamp:".$TimeStamp."
";
echo "Key:".$Key."
";
if ($result == "0"){
echo "{\"returnCode\":\"".$returnCode."\", \"returnParams\":{\"Result\"".$result."\", \"SessionID\":\""
.$sessionid."\", \"Msg\":\"".$msg."\"}, \"returnMsg\":\"".$returnMsg."\"}>>>>>>>>>>>";
}else{
echo "{\"returnCode\":\"".$returnCode."\", \"returnParams\":{\"Result\"".$result."\", \"SessionID\":\""
.$sessionid."\", \"Msg\":\"".$msg."\"}, \"returnMsg\":\"".$returnMsg."\"}>>>>>>>>>>>";
}
?>