⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlparams.cs

📁 本程序实现中国移动短信MISC平台的PROVISION接口.
💻 CS
字号:
using System;
using System.IO;
using System.Xml;
using System.Data.SqlClient;
using System.Web;
using System.Data;
using System.Text ;
using System.Net;
namespace Provision
{
	/// <summary>
	/// XmlParams 的摘要说明。
	/// </summary>
	public class XmlParams
	{
		public XmlParams(String xml)
		{
			Parse(xml);
		}
		public XmlParams()
		{}
		public String GetTransID()
		{
			return this.TransactionID ;
		}
		/*
		 * 动态分析provision的请求,然后拆分里面的参数
		 */
		private void Parse(String inXml)
		{
			StringReader sr = new StringReader(inXml);
			XmlTextReader xmlReader = new XmlTextReader(sr);
			xmlReader.WhitespaceHandling = WhitespaceHandling.None ;
			while(xmlReader.Read())
			{
				if ( xmlReader.NodeType == XmlNodeType.Element )
				{
						switch(xmlReader.LocalName)
						{
							case "Version":
								this.Version = xmlReader.ReadString();
								break;
							case "MsgType":
								this.MsgType = xmlReader.ReadString();
								break;
							case "Send_Address":
								xmlReader.MoveToContent();
								this.SendDeviceType =	xmlReader.ReadElementString();
								this.SendDeviceID	=	xmlReader.ReadElementString();
								break;
							case "Dest_Address":
								xmlReader.MoveToContent();
								this.SendDeviceType	=	xmlReader.ReadElementString();
								this.SendDeviceID	=	xmlReader.ReadElementString();
								break;
							case "FeeUser_ID":
								xmlReader.MoveToContent();
								this.FeeUserIDType	=	Convert.ToInt32(xmlReader.ReadElementString());
								this.FeeMsisdn		=	xmlReader.ReadElementString();
								this.FeePseudoCode	=	xmlReader.ReadElementString();
								break;
							case "DestUser_ID":
								xmlReader.MoveToContent();
								this.DestUserIDType	=	Convert.ToInt32(xmlReader.ReadElementString());
								this.DestMsisdn		=	xmlReader.ReadElementString();
								this.DestPseudoCode	=	xmlReader.ReadElementString();
								break;
							case "LinkID":
								this.LinkID = xmlReader.ReadString();
								break;
							case "ActionID":
								this.ActionID = Convert.ToInt32(xmlReader.ReadString());
								break;
							case "ActionReasonID":
								this.ActionReasonID = Convert.ToInt32(xmlReader.ReadString());
								break;
							case "SPID":
								this.SPID = xmlReader.ReadString();
								break;
							case "SPServiceID":
								this.SPServiceID = xmlReader.ReadString();
								break;
							case "AccessMode":
								this.AccessMode = Convert.ToInt32(xmlReader.ReadString());
								break;
							case "FeatureStr":
								this.FeatureStr = xmlReader.ReadString();
								//base64解码
								this.FeatureStr = System.Text.UTF8Encoding.UTF8.GetString(System.Convert.FromBase64String(this.FeatureStr)); 
								break;
							case "TransactionID":
								this.TransactionID = xmlReader.ReadString();
								break;
						}
				}	
			}
			xmlReader.Close();
		}
		/*
		 * 调用存储过程记录provision访问日志
		 * 该日志以数据库形式存储,存储在211.157.2.106/service/PrvSyncLog中
		 * 
		 * 该方法没有使用
		 */ 
		public int RecordLog(String inXml,String outXml,int type)
		{
			SqlConnection conn = null;
			int rst;
			try
			{
				inXml = inXml.Replace("\n","");
				inXml = inXml.Replace("\r","");
				outXml = outXml.Replace("\n","");
				outXml = outXml.Replace("\r","");
				conn = new SqlConnection(GetConfigValue("AIRCOM_ConnectString"));
				conn.Open();
				SqlCommand comm = new SqlCommand("sp_insert_prvn_log",conn);			
				comm.CommandType = CommandType.StoredProcedure;
				//参数
				comm.Parameters.Add("@dsmpXml",inXml);
				comm.Parameters.Add("@aircomXml",outXml);
				comm.Parameters.Add("@type",type);
				//comm.Parameters("retur
				rst =  comm.ExecuteNonQuery();
			}
			catch
			{
				rst = -1;
			}
			finally
			{
				if ( conn != null )
					conn.Close();
			}
			return rst;

//			dsResult = new DataSet();
//			SqlDataAdapter executeDataAdapter = new SqlDataAdapter(comm);
//			executeDataAdapter.Fill(dsResult);		
		}
		/*
		 * 记录日志,包括正向请求和反向请求.origin=aircom表示反向日志.origin=misc表示正向日志
		 * 
		 * sp_insert_sync_log  '13910119556',1,'-TYZCTS','8000 800',0,0,0,'misc'
		 * */
		public void SaveAsLog(String origin)
		{
			SqlConnection conn = null;
			int rst;
			try
			{
				conn = new SqlConnection(GetConfigValue("AIRCOM_ConnectString"));
				conn.Open();
				SqlCommand comm = new SqlCommand("sp_insert_sync_log",conn);			
				comm.CommandType = CommandType.StoredProcedure;
				//参数
				comm.Parameters.Add("@mobile",this.FeeMsisdn );
				comm.Parameters.Add("@actionID",this.ActionID );
				comm.Parameters.Add("@svc",this.SPServiceID );
				comm.Parameters.Add("@fstr",this.FeatureStr );
				comm.Parameters.Add("@mt_port",this.mt_port);
				comm.Parameters.Add("@rs",this.inResponse );
				int iTmp =0					;
				//正向请求表示和简g直接的请求日志
				//反向请求表示dsmp返回的结果
				//请求成简g接口成功
				if ( this.inResponse.Equals("0") )
					iTmp = 0;
				//请求成简g接口没有返回正确的代码,但是给misc的返回仍然是0
				if ( ! this.inResponse.Equals ("-1") )
					iTmp = 0;
				//请求成简g接口异常
				if ( this.inResponse.Equals("Exception") )
					iTmp = 1;
				//表示反向取消的日志.
				if ( this.inResponse.Equals("") )
					iTmp = 2;
				comm.Parameters.Add("@response",iTmp);
				comm.Parameters.Add("@origin",origin);
				//comm.Parameters("retur
				rst = comm.ExecuteNonQuery();
			}
			catch(Exception e)
			{
				String abc=e.Message;
			}
			finally
			{
				if ( conn != null )
					conn.Close();
			}
		}

		/*
		 * 请求简工正向通知接口,它会修改定制库,返回对provison的响应值
		 * */
		public String Proceed()
		{
			int mt_port;
			try
			{
				mt_port = Convert.ToInt32(GetConfigValue("AIRCOM_MT_PORT"));
			}
			catch
			{	
				mt_port = 0;
			}
			String url = GetConfigValue("AIRCOM_PROCESS_SYNC");
			url = url + "?DestUserIDtype="+this.DestUserIDType +"&DestMsisdn=" + this.DestMsisdn ;
			url = url + "&DestPseudoCode=" + this.DestPseudoCode + "&FeeUserIDType="+this.FeeUserIDType ;
			url = url + "&FeeMsisdn=" + this.FeeMsisdn +"&FeePseudoCode=" + this.FeePseudoCode ;
			url = url + "&LinkID=" + this.LinkID + "&ActionID=" + this.ActionID ;
			url = url + "&ActionReasonID=" + this.ActionReasonID + "&SPServiceID=" + this.SPServiceID ;
			url = url + "&AccessMode=" + this.AccessMode + "&FeatureStr=" + this.FeatureStr +"&mt_port=" + mt_port;
			String FileName = Provision.CurrentPath + "\\logs\\"+ "aircom.txt";
			WriteLog(FileName,url );
			this.inResponse =  getURL(url);


			//0:成功,-1:黑名单用户,Exception:异常
			//-1就返回-1,其它返回0可以获取到正确的返回包.
			if ( this.inResponse.Equals("-1") )
				return  "-1";
			return "0";
		}
		/*
		 * 请求url并读取返回值.可能产生异常.异常写入文件
		 * 
		 */ 
		private String getURL(String url)
		{
			try
			{
				WebRequest myRequest = WebRequest.Create(url);
				WebResponse myResponse = myRequest.GetResponse();
				Encoding encode = Encoding.GetEncoding("GB2312");
				StreamReader sr = new StreamReader( myResponse.GetResponseStream(), encode );
				String ts = sr.ReadLine().Trim();
				return ts;
			}
			catch(Exception e)
			{
				String FileName = Provision.CurrentPath + "\\logs\\"+ DateTime.Now.ToString("yy_MM_dd")+"_aircom.txt";
				WriteLog(FileName,"请求"+url+"异常,原因:"+e.Message );
				//String m = e.Message ;
				return "Exception";
			}
		}
		public static void WriteLog(String FileName ,String content)
		{
			StreamWriter swFile = null;
			try
			{
				swFile =  new StreamWriter(FileName,true);
				swFile.WriteLine(DateTime.Now.ToString()+" "+content);
			}
			catch{}
			finally
			{
				if ( swFile != null )
					swFile.Close();
			}

		}
		public static String GetConfigValue(String name)
		{
			try
			{
				return System.Configuration.ConfigurationSettings.AppSettings[name];
			}
			catch
			{ return "";}

		}
		public void SetInResponse(String s)
		{
			this.inResponse = s;
		}

		private int mt_port = Convert.ToInt32(GetConfigValue("AIRCOM_MT_PORT"));
		//内部平台处理结果.简g
		private String inResponse = "";

		private String MsgType = null;
		//该消息编号
		private String TransactionID = null;
		//该接口消息的版本号,本次所有的接口消息的版本都为“1.5.0”
		private String Version = null;
		
		//发送方地址信息
		private String SendDeviceType = null;
		private String SendDeviceID   = null;
		
		//接收方地址信息
		private String DestDeviceType = null;
		private String DestDeviceID   = null;

		//目的手机标识类型
		//	1:用手机号标识;
		//	2:用伪码标识;
		//	3:两者同时标识
		private int DestUserIDType ;

		//用户手机号
		private String DestMsisdn;

		//用户伪码
		private String DestPseudoCode;


		//计费手机类型
		//同DestUserIDType
		private int FeeUserIDType;

		//计费手机号
		private String FeeMsisdn;

		//计费伪码
		private String FeePseudoCode;

		//临时订购关系的事务ID
		private String LinkID;
		/*
			 服务状态管理动作代码,具体值如下:
			1: 开通服务;2: 停止服务;
			3: 激活服务;4: 暂停服务;
		*/
		private int ActionID = 2;
		/*
		 *	产生服务状态管理动作原因的代码,具体值如下:
			1:用户发起行为
			2:Admin&1860发起行为
			3:Boss停机
			4:Boss开机
			5:Boss过户
			6:Boss销户
			7:Boss改号
			8:扣费失败导致的服务取消
			9:其他
		 */
		private int ActionReasonID;

		//sp 企业代码
		private String SPID;
		//SP中该服务的服务代码
		private String SPServiceID;

		//服务的访问方式
		//1:WEB;2:WAP;3:SMS
		private int AccessMode;
		
		//服务订购参数(base64 encode )
		private String FeatureStr;

	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -