在线银联之实例操作_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > 在线银联之实例操作

在线银联之实例操作

 2014/12/8 14:50:28  乾坤袋  程序员俱乐部  我要评论(0)
  • 摘要:最了写了一个asp.net的在线银联支付的功能,看了网上的半天才弄出来自已的。希望能对大家有所用。1,先在线银联去申请,然后,他们那边会给你一个包,然后把包名字更改下key,放到你的Web项目的根目录中,跟其他的目录结构在同一级别上。2,如果你是asp.net的项目,可以去网上去找这几个文件,或者直接像我要也可以的哈,3,如下分别上传代码给大家展示下,1usingSystem;2usingSystem.Data;3usingSystem.Configuration;4usingSystem
  • 标签:实例 操作 在线

最了写了一个asp.net的在线银联支付的功能,看了网上的半天才弄出来自已的。希望能对大家有所用。

1,先在线银联去申请,然后,他们那边会给你一个包AWTR1JV8XVA5J+jiCnvxLY0YyjmRw3s9MmjkioIYSm7so/sheWWVG5NCXylh2xd3BFxRR1JX+DGUgrgTo2Saoru+gnBJfvsCwBWlJLsfJIqh5MazuRfhRTFs3E1E7QsAV5SSyBXhzboQV8hIgnBXpG4G5js+UoZz4wo1BwXhblTsI2+TaFdyHx8pQ+FdYWMf8RvBni38tS22WAl3Jf8xbzJo5IqCGEphjFJw3FxbTP4cFNW+4HtwRSnJ1raiGEoJV/yRJMwVQfsFio+UQSNXFMRQSrnChFkLhhC2/QLFR8qgkStJxhUgA3RxBdAfcAWQBVwBZAFXAFnAFUAWjVy5J2ZnZ2d7e3veHTzv6OWKMx47zngycSYT5+xscnY2cZzx2dlkd3e3Xq+DLvNFI1fu3r07Ho9YXc7OJg8ePOj1erdv397Z2Zl3N88vGrly586d0WjI1aXRaNTr9Xq93mg05t3NSAr7kKpGrmxvb4+Gg9FoOB6NnPGo1+u2D14ePPvOfvft539c+u+LF8+ePhW4wguLRGh64T3Gc+hS+SaJy/XuFkRVcEU9jUZjOOi7unSOj7/99ftPLr7x5OIbj9/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mIff6co3hHFejiyjyI6Uqu4h1VAK5IVc1dvKMKzrMrQDzAFUAWcAWQRSNXIA+l5ujlCuSh1BmNXIE8lJqjkSv65aEUnVSHn2wX9jqMRq4kzkPJyUKQrDK4QqCRK8nyUEbnj4xfGVwh0MiVZHko5dP0yVcGVwg0ciVZHkru4ffv/+K3f3mV+WEtoiBLUabJ8G8hD2V6JMtDKR9WwqssdoUfZMnJNIl3BvJQKiZhHkoqMFocrsarHDauEHsJgnapTJNkZyAPpVqS5aFkfr/DXGEqx3eFzjRJtgV5KNWSLA8leygk5iC8AWLYweYgTsQlL9Mk5KHMkmR5KAW/tlFrW7YuFjcZFmRJZ5qEPJRZojYPpa4nGrr2i4NGrqSdh9KuGLwnvLQiL0sVhJBWrqSfhxIb9jUUJXdxmRq5AmgOuALIAq4AsoArgCyZuuI/ROj/C+QIviu7u7vp7mZxcdFxnOFw5D6WPBgM020fyAC+K5cuXUqiCzV+4Ja4zyTHz/wmuBARHdkEpAbflYWFhcuXLyfRxR8/RCVme+DK/BG6YlnWzLr4KTBCSjrjCpAhQlcQQkl0yWhcATLk/+JPY8JBee96AAAAAElFTkSuQmCC" alt="" />,然后把包名字更改下key,放到你的Web项目的根目录中,跟其他的目录结构在同一级别上。

2,如果你是asp.net的项目,可以去网上去找这几个文件,或者直接像我要也可以的哈,JS6oDQbmjoli0WwWXR3MLEGc+csceesWfG5/8UIeLEjtn9PBk7588ZiUBkWeZlO/sU0+nUy8bBwBiFeuEPHz54MT73++npubjVGT+fjCbzFq+0nI1H49nSZWdBYILpvrW1tbe35268SXez8dCdLyF1n8/n7sYvFovFYvHy8iIbX0hPrdFWd5A+IXUXQrQ2/u7h8eBiNTq9zW8HF6vVz9/Pz/9Bd1BBYN2FEJ8/f97b2/v165f9uncPj+++fj++uh+d3j49PY9Ob4+v7t99/b76+buh7vPJqEA+Borl49ls8jaFWc7Gb8+ZT/Llb8/Q5jfL2VjbqLYs39xmBzZL1yvNJyMcmH4JrHuWZXt7e/N5s//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4bbi63lHQXbjE8JXdnumF0HzDp6d46lOSme4effYDeSE930TaGR35tBgm1NnQfAknqLlrF8Bx0l8pL3gqsLPNsfsN1wJUkdW8XTfI3utvn2XyH64Ab6eneOobnTXf7PFs34TrQmvR0bx3D86m7ZZ6tw3AdaENiurvE8LxOZizzbF7DdcCZxHR3ieG56b6ee6gxtOo8m+dwHXAkMd1dcNS9FYMM1yUMI91D4BKuA/6B7p0yyHBdwkB3wAjoDhgB3QEjoDtgRLy65xcE5Z8AOOJBd++Buv39/T9//sjtMfxuH7DFg+6Ofe2UUVwWPf/QBwkj4AsPurv3tatNGFWurX8frPxFtuWKlei+DxH0ih/dXfra7Vtk6qpG9+VsPB5r340vV2AV5Sv6QsALP7oLh752wm10zy0uV4iXGrysq1DIhYAX3nQXrQJ1wnV0JzulQHdA40331iEj4TK6b7Q19JPAZAZI+NHdxXWX0V12XI1MKMlpeiHghbcrMy7Bi7ajuxYa3USjyQ62sJw7HnR3CdQJl9Fd7Z0st6aF7oDAg+4urue0G931TuHrJdAd0ISvmdFrY0w/AXAkvO4A9AZ0B4yA7oAR0B0wAroDRvwPNsFawJE3lUcAAAAASUVORK5CYII=" alt="" />

3,如下分别上传代码给大家展示下,

  1 using System;
  2 using System.Data;
  3 using System.Configuration;
  4 using System.Web;
  5 using System.Web.Security;
  6 using System.Web.UI;
  7 using System.Web.UI.HtmlControls;
  8 using System.Web.UI.WebControls;
  9 using System.Web.UI.WebControls.WebParts;
 10 using ChinaPay_JY;
 11 
 12 namespace DTcms.Web.api.payment.chinapay
 13 {
 14     /// <summary>
 15     ///Chinapay 的摘要说明
 16     /// </summary>
 17     public partial class Chinapay :System.Web.UI.Page
 18     {
 19         string strUrl = HttpContext.Current.Request.PhysicalApplicationPath; //获取网站根目录物理路径
 20         public Chinapay()
 21         {
 22         }
 23         /////////////////////////////////////////////////////////////////////////////////////////
 24         //                        二次开发 Eric Chen 2014.12.05
 25         /////////////////////////////////////////////////////////////////////////////////////////        
 26 
 27         /// <summary>
 28         /// 订单签名函数sign
 29         /// </summary>
 30         /// <param name="MerId">商户号,长度为15个字节的数字串,由ChinaPay或清算银行分配</param>
 31         /// <param name="OrdId">订单号,长度为16个字节的数字串,由用户系统/网站生成,失败的订单号允许重复支付</param>
 32         /// <param name="TransAmt">交易金额,长度为12个字节的数字串,例如:数字串"000000001234"表示12.34元</param>
 33         /// <param name="CuryId">货币代码, 长度为3个字节的数字串,目前只支持人民币,取值为"156"</param>
 34         /// <param name="TransDate">交易日期,长度为8个字节的数字串,表示格式为:YYYYMMDD</param>
 35         /// <param name="TransType">交易类型,长度为4个字节的数字串,取值范围为:"0001"和"0002", 其中"0001"表示消费交易,"0002"表示退货交易</param>
 36         /// <returns>string CheckValue[256]  即NetPayClient根据上述输入参数生成的商户数字签名,长度为256字节的字符串</returns>
 37         public string getSign(string MerId, string OrdId, string TransAmt, string CuryId, string TransDate, string TransType)
 38         {
 39             NetPayClientClass npc = new NetPayClientClass(); //实例NetPay签名
 40             //npc.setMerKeyFile("Bin/MerPrK.key");          //设置商户密钥文件地址 d:\\MerPrK.key
 41             npc.setMerKeyFile(strUrl + "\\key\\MerPrK.key");
 42             string strChkValue = "";                         //chinapay返回的商户数字签名
 43             strChkValue = npc.sign(MerId, OrdId, TransAmt, CuryId, TransDate, TransType);
 44             return strChkValue.Trim();
 45         }
 46         /// <summary>
 47         /// 对一段字符进行签名 signData
 48         /// </summary>
 49         /// <param name="MerId">商户号,长度为15个字节的数字串,由ChinaPay分配</param>
 50         /// <param name="SignMsg">用于要签名的字符串</param>
 51         /// <returns>String CheckValue[256]即NetPayClient根据上述输入参数生成的商户数字签名,长度为256字节的字符串</returns>
 52         public string signData(string MerId, string SignMsg)
 53         {
 54             NetPayClientClass npc = new NetPayClientClass(); //实例NetPay签名
 55             //npc.setMerKeyFile("Bin/MerPrK.key");          //设置商户密钥文件地址 d:\\MerPrK.key
 56             npc.setMerKeyFile(strUrl + "\\key\\MerPrK.key");
 57             string strChkValueData = "";
 58             strChkValueData = npc.signData(MerId, SignMsg);
 59             return strChkValueData.Trim();
 60         }
 61 
 62         /// <summary>
 63         /// 验证交易应答函数check
 64         /// </summary>
 65         /// <param name="MerId">商户号,长度为15个字节的数字串,由ChinaPay分配</param>
 66         /// <param name="OrdId">订单号,长度为16个字节的数字串,由商户系统生成,失败的订单号允许重复支付</param>
 67         /// <param name="TransAmt">交易金额,长度为12个字节的数字串,例如:数字串"000000001234"表示12.34元</param>
 68         /// <param name="CuryId">货币代码, 长度为3个字节的数字串,目前只支持人民币,取值为"156"</param>
 69         /// <param name="TransDate">交易日期,长度为8个字节的数字串,表示格式为: YYYYMMDD</param>
 70         /// <param name="TransType">交易类型,长度为4个字节的数字串,取值范围为:"0001"和"0002", 其中"0001"表示消费交易,"0002"表示退货交易</param>
 71         /// <param name="OrderStatus">交易状态,长度为4个字节的数字串。详见交易状态码说明</param>
 72         /// <param name="CheckValue">校验值,即ChinaPay对交易应答的数字签名,长度为256字节的字符串</param>
 73         /// <returns>true 表示成功,即该交易应答为ChinaPay所发送,商户根据“交易状态”进行后续处理;否则表示失败,即无效应答,商户可忽略该应答</returns>
 74         public bool getCheck(string MerId, string OrdId, string TransAmt, string CuryId, string TransDate, string TransType, string OrderStatus, string CheckValue)
 75         {
 76             NetPayClientClass npc = new NetPayClientClass(); //实例NetPay签名
 77             //npc.setPubKeyFile("Bin/PgPubk.key");          //设置chinapay公共密钥文件地址 d:\\PgPubk.key
 78             npc.setPubKeyFile(strUrl + "\\key\\PgPubk.key");
 79             string strFlag = "";
 80             bool bolFlag = false;
 81             strFlag = npc.check(MerId, OrdId, TransAmt, CuryId, TransDate, TransType, OrderStatus, CheckValue); // ChkValue 为ChinaPay返回给商户的域段内容
 82             if (strFlag == "0") //“0”表示验签成功
 83                 bolFlag = true;
 84             return bolFlag;
 85         }
 86         /// <summary>
 87         /// 对一段字符串进行签名验证 checkData
 88         /// </summary>
 89         /// <param name="PlainData">用于数字签名的字符串</param>
 90         /// <param name="CheckValue">校验值,要验证的字符串的数字签名,长度为256字节的字符串</param>
 91         /// <returns>true 表示验证通过成功;否则表示失败</returns>
 92         public bool checkData(string PlainData, string CheckValue)
 93         {
 94             NetPayClientClass npc = new NetPayClientClass(); //实例NetPay签名
 95             //npc.setPubKeyFile("Bin/PgPubk.key");          //设置chinapay公共密钥文件地址 d:\\PgPubk.key
 96             npc.setPubKeyFile(strUrl + "\\key\\PgPubk.key");
 97             string strFlagData = "";
 98             bool bolFlagData = false;
 99             strFlagData = npc.checkData(PlainData, CheckValue);
100             if (strFlagData == "true")
101                 bolFlagData = true;
102             return bolFlagData;
103         }
104     }
105 }

如需要更改的话,需要跟你的业务和代码来改写里面的部分代码即可,Ok,continue......

Chinapay_Send.cs

logs_code_hide('c45ea88e-88e9-45fa-84b4-b67e94e40459',event)" src="/Upload/Images/2014120814/2B1B950FA3DF188F.gif" alt="" />
  1 using System;
  2 using System.Collections;
  3 using System.Configuration;
  4 using System.Data;
  5 using System.Web;
  6 using System.Web.Security;
  7 using System.Web.UI;
  8 using System.Web.UI.HtmlControls;
  9 using System.Web.UI.WebControls;
 10 using System.Web.UI.WebControls.WebParts;
 11 using ChinaPay_JY;
 12 using System.Data.SqlClient;
 13 using DTcms.Web.api.payment.chinapay;  //这里引用app_code的chinapay命名空间
 14 using DTcms.Common;
 15 using DTcms.Model;
 16 public partial class payonline_chinapay_Chinapay_send : System.Web.UI.Page
 17 {
 18 
 19 
 20     public int userid; //登录用户id
 21     protected void Page_Load(object sender, EventArgs e)
 22     {
 23 
 24         //读取站点配置信息
 25         DTcms.Model.siteconfig siteConfig = new DTcms.BLL.siteconfig().loadConfig();
 26         //获取订单信息
 27         string order_no = DTRequest.GetFormString("pay_order_no").ToUpper();//订单号
 28         decimal order_amount = DTRequest.GetFormDecimal("pay_order_amount", 0);//订单金额
 29         string user_name = DTRequest.GetFormString("pay_user_name");//付款用户名
 30         string subject = DTRequest.GetFormString("pay_user_message");//备注说明或者是留言
 31         string trans_type = string.Empty;//交易类型1实物2虚拟
 32         if (order_no == "" || order_amount == 0)
 33         {
 34             Response.Redirect(new DTcms.Web.UI.BasePage().linkurl("error","?msg="+Utils.UrlEncode("对不起,你提交的参数有误")));
 35             return;
 36         }
 37         if (order_no.StartsWith("R"))//R开头为在线充值订单
 38         {
 39             DTcms.Model.user_amount_log model = new DTcms.BLL.user_amount_log().GetModel(order_no);
 40             if (model == null)
 41             {
 42                 Response.Redirect(new DTcms.Web.UI.BasePage().linkurl("errro", "?msg=" + Utils.UrlEncode("对不起,你充值的订单号不存在或已删除")));
 43                 return;
 44             }
 45             if (model.value != order_amount)
 46             {
 47                 Response.Redirect(new DTcms.Web.UI.BasePage().linkurl("error", "?msg=" + Utils.UrlEncode("对不起,你充值的订单金额与实际金额不一致!")));
 48                 return;
 49             }
 50             trans_type = "2";
 51         }
 52         else//B开头为商品订单
 53         {
 54             DTcms.Model.orders model = new DTcms.BLL.orders().GetModel(order_no);
 55             if (model == null)
 56             {
 57                 Response.Redirect(new DTcms.Web.UI.BasePage().linkurl("error","?msg="+Utils.UrlEncode("对不起,你支付的订单号不存在或已删除!")));
 58                 return;
 59             }
 60             if (model.order_amount != order_amount)
 61             {
 62                 Response.Redirect(new DTcms.Web.UI.BasePage().linkurl("error","?msg="+Utils.UrlEncode("对不起,你支付的订单金额与实际金额不一致!")));
 63                 return;
 64             }
 65             trans_type = "1";
 66 
 67         }
 68         if (user_name != "")
 69         {
 70             user_name = "支付会员:" + user_name;
 71         }
 72         else {
 73             user_name = "匿名用户";
 74         }
 75 
 76 
 77 
 78         //if (Request.Cookies[ProductCMS.GetCookieName()] == null)
 79         //{
 80         //    ChangeHope_fc.Show_Msg("请先登录", "../index.html");
 81         //    Response.End();
 82         //}
 83         //else
 84         //    userid = Convert.ToInt32(Request.Cookies[ProductCMS.GetCookieName()].Values["CH_userid"]);
 85 
 86         //int intOrderid = 0, intProid = 0; //订单id,商品id        
 87         //if (Request["oid"] != null && Request["oid"] != "")
 88         //    intOrderid = Convert.ToInt32(Request["oid"]);
 89         //else
 90         //    //ChangeHope_fc.Show_Msg("参数错误,请稍后再试!");
 91         //if (Request["pid"] != null && Request["pid"] != "")
 92         //    intProid = Convert.ToInt32(Request["pid"]);
 93         //else
 94             //ChangeHope_fc.Show_Msg("参数错误,请稍后再试!");
 95 
 96         //YX_sql Exsql = new YX_sql();
 97         //ChangeHope_CMS cms = new ChangeHope_CMS();
 98         Chinapay cpy = new Chinapay();
 99         //获取传递给银联chinapay的各个参数-----------------------------------------------
100         //string cpyUrl = "http://payment-test.chinapay.com/pay/TransGet"; //测试地址,测试的时候用这个地址,应用到网站时用下面那个地址
101         string cpyUrl = "https://payment.ChinaPay.com/pay/TransGet";   //支付地址            
102         string cpyMerId = "808080201303248"; //ChinaPay统一分配给商户的商户号,15位长度,必填   
103         string cpyOrdId = "03248" + order_no.Substring(8);           //商户提交给ChinaPay的交易订单号,订单号的第五至第九位必须是商户号的最后五位,即“12345”;16位长度,必填 20141208TU33BK 201412080919280460802  .PadRight(11, '0')
104         string cpyTransAmt = (Convert.ToDouble((order_amount)*100).ToString());  //订单交易金额,12位长度,左补0,必填,单位为分,000000001234 表示 12.34 元
105         string cpyCuryId = "156";            //订单交易币种,3位长度,固定为人民币156,必填
106         string cpyTransDate = DateTime.Now.ToString("yyyyMMdd");            //订单交易日期,8位长度,必填,格式yyyyMMdd
107         string cpyTransType = "0001";        //交易类型,4位长度,必填,0001表示消费交易,0002表示退货交易
108         string cpyVersion = "20040916";      //支付接入版本号,808080开头的商户用此版本,必填,另一版本为"20070129" 20040916
109         string cpyBgRetUrl = "/chinapay/Chinapay_Bgreturn.aspx";//cms.Hope_Sitwww + "/chinapay/Chinapay_Bgreturn.aspx";   //后台交易接收URL,为后台接受应答地址,用于商户记录交易信息和处理,对于使用者是不可见的,长度不要超过80个字节,必填
110         string cpyPageRetUrl = "/chinapay/Chinapay_Pgreturn.aspx";// cms.Hope_Sitwww + "/chinapay/Chinapay_Pgreturn.aspx"; //页面交易接收URL,为页面接受应答地址,用于引导使用者返回支付后的商户网站页面,长度不要超过80个字节,必填
111         string cpyGateId = ""; //支付网关号,可选,参看银联网关类型,如填写GateId(支付网关号),则消费者将直接进入支付页面,否则进入网关选择页面
112         string cpyPriv1 = "Memo";  //"" 商户私有域,长度不要超过60个字节,商户通过此字段向Chinapay发送的信息,Chinapay依原样填充返回给商户
113 
114         string sql = "", strCountMoney = cpyTransAmt, strOrdid = ""; //sql语句,实付款,订单自增id
115         //sql = "select * from yx_orderform where yx_id=" + intOrderid;   //查询用户订单
116         //SqlDataReader sdr = Exsql.Re_dr(sql);
117         //if (sdr.Read())
118         //{
119         //    cpyPriv1 = strOrdid = sdr["YX_ID"].ToString().Trim();
120         //    strCountMoney = Convert.ToDecimal(Convert.ToDecimal(sdr["YX_SumPrice"]) + Convert.ToDecimal(sdr["YX_DGoodsPrice"]) * Convert.ToDecimal(sdr["YX_Sumcount"]) - Convert.ToDecimal(sdr["YX_SumVouchers"])).ToString("f2");
121         //}
122         ///订单时间必须为当前时间,且格式必须为yyyyMMdd
123         //cpyTransDate = Convert.ToDateTime(DateTime.Now).GetDateTimeFormats('D')[1].ToString().Trim().Replace("-", "");
124         ///订单号,16位长度,左补0,0000 02449 0000000
125 
126         int intO = strOrdid.Length;
127         for (int i = 0; i < 7 - intO; i++)
128         {
129             strOrdid = "0" + strOrdid;
130         }
131         //0000 B14 12 05 1559294 00000000
132         //201412051721046647112
133         //0000000000000064
134 
135         cpyOrdId = "0000" + cpyOrdId;  //银联支付id="0000"+银联商户后五位+补0后的订单自增id   + strOrdid;
136         ///订单交易金额,12位长度,左补0
137         strCountMoney = strCountMoney.Replace(".", "");
138         int intM = strCountMoney.Length;
139         for (int i = 0; i < 12 - intM; i++)
140         {
141             strCountMoney = "0" + strCountMoney;
142         }
143         cpyTransAmt = strCountMoney; //获取传递的实付款
144 
145         //////////////////////////////////////////////////////////////////////
146         string strChkValue = ""; //256字节长的ASCII码,此次交易所提交的关键数据的数字签名,必填
147         strChkValue = cpy.getSign(cpyMerId, cpyOrdId, cpyTransAmt, cpyCuryId, cpyTransDate, cpyTransType);
148 
149         if (strChkValue != "")
150         {
151             Response.Write("<form name='chinapayForm' method='post' action='" + cpyUrl + "'>");         //支付地址
152             Response.Write("<input type='hidden' name='MerId' value='" + cpyMerId + "' />");            //商户号
153             Response.Write("<input type='hidden' name='OrdId' value='" + cpyOrdId + "' />");            //订单号
154             Response.Write("<input type='hidden' name='TransAmt' value='" + cpyTransAmt + "' />");      //支付金额
155             Response.Write("<input type='hidden' name='CuryId' value='" + cpyCuryId + "' />");          //交易币种
156             Response.Write("<input type='hidden' name='TransDate' value='" + cpyTransDate + "' />");    //交易日期
157             Response.Write("<input type='hidden' name='TransType' value='" + cpyTransType + "' />");    //交易类型
158             Response.Write("<input type='hidden' name='Version' value='" + cpyVersion + "' />");        //支付接入版本号
159             Response.Write("<input type='hidden' name='BgRetUrl' value='" + cpyBgRetUrl + "' />");      //后台接受应答地址
160             Response.Write("<input type='hidden' name='PageRetUrl' value='" + cpyPageRetUrl + "' />");  //为页面接受应答地址
161             Response.Write("<input type='hidden' name='GateId' value='" + cpyGateId + "' />");          //支付网关号
162             Response.Write("<input type='hidden' name='Priv1' value='" + cpyPriv1 + "' />");            //商户私有域,这里将订单自增编号放进去了
163             Response.Write("<input type='hidden' name='ChkValue' value='" + strChkValue + "' />");      //此次交易所提交的关键数据的数字签名
164             Response.Write("<script>");
165             Response.Write("document.chinapayForm.submit();");
166             Response.Write("</script></form>");
167         }
168         //else
169         //    ChangeHope_fc.Show_Msg("参数错误,请稍后再试!");
170     }
171 }
View Code Chinapay_Bgreturn.cs
 1 using System;
 2 using System.Collections;
 3 using System.Configuration;
 4 using System.Data;
 5 using System.Web;
 6 using System.Web.Security;
 7 using System.Web.UI;
 8 using System.Web.UI.HtmlControls;
 9 using System.Web.UI.WebControls;
10 using System.Web.UI.WebControls.WebParts;
11 
12 using DTcms.Web.api.payment.chinapay;
13 
14 public partial class payonline_chinapay_Chinapay_Bgreturn : System.Web.UI.Page
15 {
16     protected void Page_Load(object sender, EventArgs e)
17     {
18         Chinapay cpy = new Chinapay(); 
19         string TransDate = "",MerId = "",OrdId = "",TransType = "",TransAmt = "",CuryId = "",ChkValue = "",OrderStatus = "",GateId = "",Priv1 = "";
20         bool bolCheck=false;
21 
22         TransDate = Request["transdate"].Trim();
23         MerId = Request["merid"].Trim();
24         OrdId = Request["orderno"].Trim();
25         TransType = Request["transtype"].Trim();
26         TransAmt = Request["amount"].Trim();
27         CuryId = Request["currencycode"].Trim(); //交易币种
28         ChkValue = Request["checkvalue"].Trim();
29         OrderStatus = Request["status"].Trim();
30         GateId = Request["GateId"].Trim();       //支付网关号
31         Priv1 = Request["Priv1"].Trim();         //商户私有域
32         ///检验是否是银联chinapay返回的交易数据
33         bolCheck = cpy.getCheck(MerId,OrdId,TransAmt,CuryId,TransDate,TransType,OrderStatus,ChkValue);
34         if (bolCheck)
35             Response.Write("<script>alert('后台接收到应答');</script>");
36         else
37             Response.Write("<script>alert('后台没有接收到应答');</script>");
38     }
39 }
View Code Chinapay_Pgreturn
 1 using System;
 2 using System.Collections;
 3 using System.Configuration;
 4 using System.Data;
 5 using System.Web;
 6 using System.Web.Security;
 7 using System.Web.UI;
 8 using System.Web.UI.HtmlControls;
 9 using System.Web.UI.WebControls;
10 using System.Web.UI.WebControls.WebParts;
11 
12 using System.Data.SqlClient;
13 using DTcms.Web.api.payment.chinapay;
14 namespace DTcms.Web.api.payment.balance
15 {
16     public partial class payonline_chinapay_Chinapay_Pgreturn : System.Web.UI.Page
17     {
18         protected void Page_Load(object sender, EventArgs e)
19         {
20             //YX_sql Exsql = new YX_sql();
21             //ChangHope_DB db = new ChangHope_DB();
22             Chinapay cpy = new Chinapay();
23             string TransDate = "", MerId = "", OrdId = "", TransType = "", TransAmt = "", CuryId = "", ChkValue = "", OrderStatus = "", GateId = "", Priv1 = "";
24             bool bolCheck = false;
25 
26             TransDate = Request["transdate"].Trim();
27             MerId = Request["merid"].Trim();
28             OrdId = Request["orderno"].Trim();
29             TransType = Request["transtype"].Trim();
30             TransAmt = Request["amount"].Trim();
31             CuryId = Request["currencycode"].Trim(); //交易币种
32             ChkValue = Request["checkvalue"].Trim();
33             OrderStatus = Request["status"].Trim();
34             GateId = Request["GateId"].Trim();       //支付网关号
35             Priv1 = Request["Priv1"].Trim();         //商户私有域,内容是订单自增编号
36             ///检验是否是银联chinapay返回的交易数据
37             bolCheck = cpy.getCheck(MerId, OrdId, TransAmt, CuryId, TransDate, TransType, OrderStatus, ChkValue);
38             if (bolCheck) //bolCheck=true,检测返回参数是银联发送的,进入处理流程
39             {
40                 try
41                 {
42                     ///********************************
43                     ///这里写成功接收到银联支付成功后你自己要处理的流程,比如修改买、卖家金额等,订单状态等
44                     ///********************************
45 
46                 }
47                 catch (Exception)
48                 {
49                     //ChangeHope_fc.Show_Msg("参数错误,请稍后再试!", db.System_Http() + "/vipuser/default_vip.aspx");
50                 }
51             }
52             //else
53                 //ChangeHope_fc.Show_Msg("参数错误,请稍后再试!", db.System_Http() + "/vipuser/default_vip.aspx");
54         }
55     }
56 
57 }
View Code

代码中有很多注释啦,我就不再熬熟啦。

 

发表评论
用户名: 匿名