📄 bulksmshttpgateway.java
字号:
// SMSLib for Java v3
// A Java API library for sending and receiving SMS via a GSM modem
// or other supported gateways.
// Web Site: http://www.smslib.org
//
// SMSLib is distributed under the terms of the Apache License version 2.0
//
// Copyright (C) 2002-2007, Thanasis Delenikas, Athens/GREECE
// Portions Copyright:
// Davide Bettoni, Clusone/ITALY, dbettoni@users.sourceforge.net
// Tomek Cejner, Polland, heretique@users.sourceforge.net
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.smslib.gateway;
import java.util.*;
import java.net.*;
import org.apache.log4j.*;
import org.smslib.*;
public class BulkSmsHTTPGateway extends AbstractGateway
{
private String username, password;
Object SYNC_Commander;
public BulkSmsHTTPGateway(String id, String username, String password, Logger logger)
{
super(id, logger);
started = false;
this.username = username;
this.password = password;
this.from = null;
SYNC_Commander = new Object();
attributes = AbstractGateway.Attributes.SEND |
AbstractGateway.Attributes.CUSTOMFROM |
AbstractGateway.Attributes.BIGMESSAGES |
AbstractGateway.Attributes.FLASHSMS;
}
public void startGateway() throws Exception
{
logger.info("Starting Gateway: " + gatewayId);
super.startGateway();
}
public void stopGateway() throws Exception
{
logger.info("Stopping Gateway: " + gatewayId);
super.stopGateway();
}
public void readMessages(LinkedList<InboundMessage> msgList, InboundMessage.MessageClass msgClass) throws Exception
{
throw new UnsupportedOperationException("Unsupported Gateway operation!");
}
public InboundMessage readMessage(String memLoc, int memIndex) throws Exception
{
throw new UnsupportedOperationException("Unsupported Gateway operation!");
}
public void deleteMessage(InboundMessage msg) throws Exception
{
throw new UnsupportedOperationException("Unsupported Gateway operation!");
}
public float queryBalance() throws Exception
{
throw new UnsupportedOperationException("Unsupported Gateway operation!");
}
public boolean queryCoverage(OutboundMessage msg) throws Exception
{
throw new UnsupportedOperationException("Unsupported Gateway operation!");
}
public void sendMessage(OutboundMessage msg) throws Exception
{
sendMessage(msg, Priority.NORMAL);
}
public void sendMessage(OutboundMessage msg, Priority priority) throws Exception
{
URL url;
LinkedList<HttpHeader> request = new LinkedList<HttpHeader>();
LinkedList<String> response;
String reqLine;
logger.debug("BulkSMS: sendMessage().");
request.add(new HttpHeader("username", username, false));
request.add(new HttpHeader("password", password, false));
request.add(new HttpHeader("message", msg.getText(), false));
request.add(new HttpHeader("msisdn", msg.getRecipient().substring(1), false));
request.add(new HttpHeader("allow_concat_text_sms", "1", false));
if (msg.getFlashSms()) request.add(new HttpHeader("msg_class", "0", false));
if (msg.getFrom() != null) request.add(new HttpHeader("source_id", msg.getFrom(), false));
else if (from != null) request.add(new HttpHeader("source_id", from, false));
reqLine = "";
for (int i = 0; i < request.size(); i ++)
{
if (i != 0) reqLine += "&";
reqLine += request.get(i).key + "=" + request.get(i).value;
}
url = new URL("http://bulksms.vsms.net:5567/eapi/submission/send_sms/2/2.0" + "?" + reqLine);
// Use the following URL for port 80 access.
// As per BULKSMS, port 80 access is the worst case alternative.
// url = new URL("http://bulksms.vsms.net/eapi/submission/send_sms/2/2.0" + "?" + reqLine);
synchronized (SYNC_Commander) { response = HttpDriver.HttpGet(url); }
if (response.get(0).charAt(0) == '0')
{
StringTokenizer tokens = new StringTokenizer(response.get(0), "|");
tokens.nextToken();
tokens.nextToken();
msg.setRefNo(tokens.nextToken());
msg.setDispatchDate(new Date());
msg.setGatewayId(gatewayId);
msg.setMessageStatus(OutboundMessage.MessageStatus.SENT);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -