📄 reverseorder.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Collections.Specialized;
using System.IO;
using System.Net;
using System.Xml;
using Provision;
namespace Provision
{
/// <summary>
/// ReverseOrder 的摘要说明。
/// </summary>
public class ReverseOrder : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
NameValueCollection qscoll = Request.QueryString;
this.FeeMsisdn = qscoll.Get("mobile");
this.SPServiceID = qscoll.Get("item");
this.ActionID = qscoll.Get("action");
if ( this.FeeMsisdn == null || this.SPServiceID == null || this.ActionID == null )
{
Response.Write("-1$Invalid parameter");
Response.End();
}
String inXml = GetReverseXml(this.ActionID);
this.AircomXml = inXml;
//WriteLog("log.txt",inXml);
String result = this.Process(inXml);
RecordLog();
Response.Write(result);
Response.End();
}
private String Process(String aircomXml)
{
String str = "";
try
{
//向移动dsmp发起反向请求,soap数据用utf8编码
Byte[] data = System.Text.Encoding.UTF8.GetBytes(aircomXml);
WebRequest pWeb = WebRequest.Create(XmlParams.GetConfigValue("PROVISION_ADDRESS"));
pWeb.Method = "POST";
pWeb.ContentType = "text/xml";
pWeb.ContentLength = data.Length ;
Stream pStream = pWeb.GetRequestStream();
pStream.Write(data,0,data.Length );
pStream.Close();
//分析dsmp处理结果
WebResponse wResp = pWeb.GetResponse();
StreamReader sr = new StreamReader(wResp.GetResponseStream(),System.Text.Encoding.UTF8);
this.DsmpXml = sr.ReadToEnd().Trim();
String hRet = GetRetFromDsmp(this.DsmpXml);
if ( hRet.Equals("0") )
str = "OK" ;
else
str = hRet;
//RecordLog(dsmpXml,aircomXml,0);
}
catch(Exception e){
str = e.Message ;
}
return str;
}
//req表示aircom请求,resp表示dsmp的响应
private void RecordLog()
{
XmlParams temp = new XmlParams(this.AircomXml );
String hRet = GetRetFromDsmp(this.DsmpXml);
temp.SetInResponse(hRet);
//temp.RecordLog(req,resp,0);
temp.SaveAsLog("aircom");
}
private String GetRetFromDsmp(String inXml)
{
try
{
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 "hRet":
return xmlReader.ReadString();
}
}
}
}
catch{}
//默认返回是0
return "-1";
}
private String GetReverseXml(String MsgType)
{
try
{
String filePath = "";
if ( MsgType.Equals("1") )//定制
filePath = Server.MapPath("") +"\\xml\\SubscribeServiceReq.xml";
else if ( MsgType.Equals("0") ) //取消
filePath = Server.MapPath("") +"\\xml\\UnSubscribeServiceReq.xml";
StreamReader sr = File.OpenText(filePath);
String reqStr = sr.ReadToEnd().Trim();
String trans_id = this.GetTransID();
//trans id
reqStr = reqStr.Replace("#TRANSID#" ,trans_id.Trim());
//需要操作的手机号码
reqStr = reqStr.Replace("#MOBILE#",this.FeeMsisdn);
//需要操作的业务
reqStr = reqStr.Replace("#ITEM#",this.SPServiceID );
//需要操作的类型
//reqStr = reqStr.Replace("#ACTION#",this.ActionID);
reqStr = reqStr.Replace("\n","");
reqStr = reqStr.Replace("\r","");
reqStr = reqStr.Replace("\t","");
sr.Close();
return reqStr;
}
catch{
return "";
}
}
private String GetTransID()
{
long transID = 110000027166;
try
{
StreamReader sr = new StreamReader(Server.MapPath("")+"\\transID.txt");
transID = Convert.ToInt64(sr.ReadLine().Trim());
sr.Close();
StreamWriter sw = new StreamWriter(Server.MapPath("")+"\\transID.txt",false);
sw.WriteLine(""+(transID+1));
sw.Close();
}
catch{}
return ""+transID;
}
private void WriteLog(String filePath,String cont)
{
try
{
filePath = Server.MapPath("")+"\\"+filePath;
StreamWriter sr = new StreamWriter(filePath,false);
sr.Write(cont);
sr.Close();
}
catch{}
}
//反向请求包
private String AircomXml = "";
//响应包
private String DsmpXml = "";
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 String DestUserIDType ;
//用户手机号
private String DestMsisdn;
//用户伪码
private String DestPseudoCode;
//计费手机类型
//同DestUserIDType
private String FeeUserIDType;
//计费手机号
private String FeeMsisdn;
//计费伪码
private String FeePseudoCode;
//临时订购关系的事务ID
private String LinkID;
/*
服务状态管理动作代码,具体值如下:
1: 开通服务;2: 停止服务;
*/
private String ActionID;
/*
* 产生服务状态管理动作原因的代码,具体值如下:
1:用户发起行为
2:Admin&1860发起行为
3:Boss停机
4:Boss开机
5:Boss过户
6:Boss销户
7:Boss改号
8:扣费失败导致的服务取消
9:其他
*/
private String ActionReasonID;
//sp 企业代码
private String SPID;
//SP中该服务的服务代码
private String SPServiceID;
//服务的访问方式
//1:WEB;2:WAP;3:SMS
private String AccessMode;
//服务订购参数(base64 encode )
private String FeatureStr;
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -