首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

华为网关短信发送跟接收

2012-07-19 
华为网关短信发送和接收package com.skywin.simpass.sysinterface.sms.utilimport java.util.Dateimport

华为网关短信发送和接收

package com.skywin.simpass.sysinterface.sms.util;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import com.huawei.insa2.comm.cmpp.message.CMPPDeliverMessage;
import com.huawei.insa2.comm.cmpp.message.CMPPMessage;
import com.huawei.insa2.comm.cmpp.message.CMPPSubmitMessage;
import com.huawei.insa2.comm.cmpp.message.CMPPSubmitRepMessage;
import com.huawei.insa2.util.Args;
import com.huawei.smproxy.SMProxy;
import com.skywin.simpass.sysinterface.sms.entity.SMSEntity;

public class SMSClient extends SMProxy {

??? private static SMSClient ins;

??? private SMSClient(Args args) {
??? ??? super(args);
??? }

??? public static SMSClient getInstance() {
??? ??? if (ins == null) {
??? ??? ??? Map<String, String> m = new HashMap<String, String>();
??? ??? ??? // 系统参数配置
??? ??? ??? m.put("host", "host");
??? ??? ??? m.put("port", "port");
??? ??? ??? m.put("source-addr", "source-addr");
??? ??? ??? m.put("shared-secret", "shared-secret");
??? ??? ??? m.put("heartbeat-interval", "30");
??? ??? ??? m.put("reconnect-interval", "30");
??? ??? ??? m.put("heartbeat-noresponseout", "5");
??? ??? ??? m.put("transaction-timeout", "10");
??? ??? ??? m.put("version", "0");
??? ??? ??? m.put("debug", "true");
??? ??? ??? ins = new SMSClient(new Args(m));
??? ??? }
??? ??? return ins;
??? }

??? public CMPPMessage onDeliver(CMPPDeliverMessage msg) {
??? ??? String message = null;
??? ??? try {
??? ??? ??? String receivedMsg = new String(msg.getMsgContent(), "UTF-8");
??? ??? ??? // System.out.println("接收到的消息:"+receivedMsg);
??? ??? ??? String receivedTelephone = msg.getSrcterminalId();
??? ??? ??? // System.out.println("接收的手机号码:"+receivedTelephone);
??? ??? ??? if ((receivedMsg.subSequence(0, 5)).equals("CSize")) {
??? ??? ??? ??? System.out.println(receivedMsg);
??? ??? ??? } else {
??? ??? ??? ??? message = "充值请求信息格式不对";
??? ??? ??? ??? CMPPSubmitMessage submitMsg = new CMPPSubmitMessage(1, 1, 0, 1,
??? ??? ??? ??? ??? ??? "0010", 0, "", 0, 0, 15, "950338", "02", Integer
??? ??? ??? ??? ??? ??? ??? ??? .toString(0),
??? ??? ??? ??? ??? ??? new Date(System.currentTimeMillis() + (long) 50000), // 存活期
??? ??? ??? ??? ??? ??? null, "10658672", new String[] { receivedTelephone },
??? ??? ??? ??? ??? ??? message.getBytes(), "");
??? ??? ??? ??? // 发送错误信息给用户
??? ??? ??? ??? SMSClient.getInstance().send(submitMsg);
??? ??? ??? }
??? ??? } catch (Exception e) {
??? ??? }
??? ??? return super.onDeliver(msg);
??? }

??? public void send(CMPPSubmitMessage msg) throws Exception {
??? ??? CMPPSubmitRepMessage rep = (CMPPSubmitRepMessage) super.send(msg);
??? ??? // System.out.println(rep.toString());
??? }

??? /**
??? ?* @param args
??? ?*/
??? public static void main(String[] args) throws Exception {
??? ??? SMSClient client = SMSClient.getInstance();
??? ??? System.in.read();
??? }

}

?

?

热点排行