Esempio n. 1
0
        /// <summary>
        /// 预授权控件获取tn交易请求
        /// </summary>
        public void AuthDealApp()
        {
            Dictionary<string, string> param = new Dictionary<string, string>();
            //TODO 订单号
            string orderId = "000";

            //版本号
            param["version"] = "5.0.0";
            //编码方式
            param["encoding"] = "UTF-8";
            //证书ID
            param["certId"] = CertUtil.GetSignCertId();
            //交易类型
            param["txnType"] = "02";
            //交易子类
            param["txnSubType"] = "01";
            //业务类型
            param["bizType"] = "000201";
            //前台通知地址 ,控件接入方式无作用
            param["frontUrl"] = "http://localhost:8080/demo/utf8/FrontRcvResponse.aspx";
            //后台通知地址
            param["backUrl"] = "http://222.222.222.222:8080/demo/utf8/BackRcvResponse.aspx";
            //签名方法
            param["signMethod"] = "01";
            //渠道类型,07-PC,08-手机
            param["channelType"] = "08";
            //接入类型
            param["accessType"] = "0";
            //商户号
            param["merId"] = MER_ID;
            //商户订单号
            param["orderId"] = orderId;
            //订单发送时间
            param["txnTime"] = DateTime.Now.ToString("yyyyMMddHHmmss");
            //交易金额,单位分
            param["txnAmt"] = "1";
            //交易币种
            param["currencyCode"] = "156";
            //订单描述,可不上送,上送时控件中会显示该信息
            param["orderDesc"] = "订单描述";
            //请求方保留域,透传字段,查询、通知、对账文件中均会原样出现
            param["reqReserved"] = "透传信息";

            //签名
            SDKUtil.Sign(param, Encoding.UTF8);
            Response.Write("\n" + "请求报文=[" + SDKUtil.PrintDictionaryToString(param) + "]\n");

            //初始化通信处理类
            HttpClient hc = new HttpClient(SDKConfig.AppRequestUrl);
            //发送请求获取通信应答
            int status = hc.Send(param, Encoding.UTF8);
            //返回结果
            string result = hc.Result;
            if (status == 200)
            {
                Response.Write("返回报文=[" + result + "]\n");
                Dictionary<string, string> resData = SDKUtil.CoverstringToDictionary(result);
                string respcode = resData["respCode"];

                if (SDKUtil.Validate(resData, Encoding.UTF8))
                {
                    Response.Write("商户端验证返回报文签名成功\n");
                }
                else
                {
                    Response.Write("商户端验证返回报文签名失败\n");
                }
            }
            else
            {
                Response.Write("请求失败\n");
                Response.Write("返回报文=[" + result + "]\n");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 退货
        /// </summary>
        public void Refund()
        {
            Dictionary<string, string> param = new Dictionary<string, string>();
            //TODO 订单号
            string orderId = "000";

            //版本号
            param["version"] = "5.0.0";
            //编码方式
            param["encoding"] = "UTF-8";
            //证书ID
            param["certId"] = CertUtil.GetSignCertId();
            //签名方法
            param["signMethod"] = "01";
            //交易类型
            param["txnType"] = "04";
            //交易子类
            param["txnSubType"] = "00";
            //业务类型
            param["bizType"] = "000201";
            //接入类型
            param["accessType"] = "0";
            //渠道类型
            param["channelType"] = "07";
            //商户订单号,重新产生,不同于原消费
            param["orderId"] = orderId;
            //商户号
            param["merId"] = MER_ID;
            //原消费的queryId,可以从查询接口或者通知接口中获取
            param["origQryId"] = "201303071540145467132";
            //订单发送时间,重新产生,不同于原消费
            param["txnTime"] = DateTime.Now.ToString("yyyyMMddHHmmss");
            //交易金额,消费撤销时需和原消费一致
            param["txnAmt"] = "1";
            //后台通知地址,改自己的外网地址
            param["backUrl"] = "http://222.222.222.222:8080/demo/utf8/BackRcvResponse.aspx";

            //返回结果
            string result = "";
            SDKUtil.Sign(param, Encoding.UTF8);

            HttpClient hc = new HttpClient(SDKConfig.BackTransUrl);

            int status = hc.Send(param, Encoding.UTF8);
            if (status == 200)
            {
                result = hc.Result;
                if (result != null && string.IsNullOrEmpty(result))
                {
                    Dictionary<string, string> resData = SDKUtil.CoverstringToDictionary(result);
                    string respcode = resData["respCode"];

                    if (SDKUtil.Validate(resData, Encoding.UTF8))
                    {
                        Response.Write("商户端验证返回报文签名成功");

                    }
                    else
                    {
                        Response.Write("商户端验证返回报文签名失败");
                    }
                }
                else
                {
                    result = hc.Result;
                }
            }
            else
            {
                Response.Write("退货失败");
                Response.Write("返回报文=[" + result + "]\n");
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 交易状态查询
        /// </summary>
        public void Query()
        {
            Dictionary<string, string> param = new Dictionary<string, string>();

            //版本号
            param["version"] = "5.0.0";
            //编码方式
            param["encoding"] = "UTF-8";
            //证书ID
            param["certId"] = CertUtil.GetSignCertId();
            //签名方法
            param["signMethod"] = "01";
            //交易类型
            param["txnType"] = "00";
            //交易子类
            param["txnSubType"] = "00";
            //业务类型
            param["bizType"] = "000000";
            //接入类型
            param["accessType"] = "0";
            //渠道类型
            param["channelType"] = "07";
            //请修改被查询的交易的订单号
            param["orderId"] = "20150211215817604";
            //商户号
            param["merId"] = MER_ID;
            //请修改被查询的交易的订单发送时间
            param["txnTime"] = "20150211215817";

            //签名
            SDKUtil.Sign(param, Encoding.UTF8);
            Response.Write("\n" + "请求报文=[" + SDKUtil.PrintDictionaryToString(param) + "]\n");

            //初始化通信处理类
            HttpClient hc = new HttpClient(SDKConfig.SingleQueryUrl);
            //发送请求获取通信应答
            int status = hc.Send(param, Encoding.UTF8);
            //返回结果
            string result = hc.Result;
            if (status == 200)
            {
                Response.Write("返回报文=[" + result + "]\n");
                Dictionary<string, string> resData = SDKUtil.CoverstringToDictionary(result);
                string respcode = resData["respCode"];

                if (SDKUtil.Validate(resData, Encoding.UTF8))
                {
                    Response.Write("商户端验证返回报文签名成功\n");
                }
                else
                {
                    Response.Write("商户端验证返回报文签名失败\n");
                }
            }
            else
            {
                Response.Write("请求失败\n");
                Response.Write("返回报文=[" + result + "]\n");
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 文件传输类交易请求
        /// </summary>
        public void FileTransfer()
        {
            Dictionary<string, string> param = new Dictionary<string, string>();
            //TODO 订单号
            string orderId = "000";

            //版本号
            param["version"] = "5.0.0";
            //编码方式
            param["encoding"] = "UTF-8";
            //证书ID
            param["certId"] = CertUtil.GetSignCertId();
            //交易类型
            param["txnType"] = "76";
            //签名方法
            param["signMethod"] = "01";
            //交易子类
            param["txnSubType"] = "01";
            //业务类型
            param["bizType"] = "000000";
            //接入类型
            param["accessType"] = "0";
            //商户号
            param["merId"] = MER_ID;
            //清算日期
            param["settleDate"] = "0119";
            //订单发送时间,重新产生,不同于原消费
            param["txnTime"] = DateTime.Now.ToString("yyyyMMddHHmmss");
            //交易金额,消费撤销时需和原消费一致
            param["fileType"] = "00";

            //签名
            SDKUtil.Sign(param, Encoding.UTF8);
            Response.Write("请求报文=[" + SDKUtil.PrintDictionaryToString(param) + "]\n");
            //初始化通信处理类
            HttpClient hc = new HttpClient(SDKConfig.FileTransUrl);
            //发送请求获取通信应答
            int status = hc.Send(param, Encoding.UTF8);
            //返回结果
            string result = hc.Result;
            if (status == 200)
            {
                Response.Write("返回报文=[" + result + "]\n");
                Dictionary<string, string> resData = SDKUtil.CoverstringToDictionary(result);
                string respcode = resData["respCode"];
                if (SDKUtil.Validate(resData, Encoding.UTF8))
                {
                    Response.Write("商户端验证返回报文签名成功\n");
                    //商户端根据返回报文内容处理自己的业务逻辑 TODO...

                    // 解析返回文件
                    string fileContent = resData["fileContent"];
                    if (!string.IsNullOrEmpty(fileContent))
                    {
                        //Base64解码
                        byte[] dBase64Byte = Convert.FromBase64String(fileContent);
                        //解压缩
                        byte[] fileByte = SecurityUtil.inflater(dBase64Byte);

                        string filePath = "d:\\FileDown";
                        string fileName = resData["fileName"];

                        //开始生成对账文件
                        string path = System.IO.Path.Combine(filePath, fileName);
                        System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Create);
                        fs.Write(fileByte, 0, fileByte.Length);
                        fs.Close();
                        fs.Dispose();

                        Response.Write("文件生成路径[" + path + "]<br/>");
                    }
                }
                else
                {
                    Response.Write("商户端验证返回报文签名失败\n");
                }
            }
            else
            {
                // 通信失败,获取返回报文
                Response.Write("通信失败\n");
                Response.Write("返回报文=[" + result + "]\n");
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 消费撤销
        /// </summary>
        public void ConsumeUndo()
        {
            Dictionary<string, string> param = new Dictionary<string, string>();
            //TODO 订单号
            string orderId = "000";

            //版本号
            param["version"] = "5.0.0";
            //编码方式
            param["encoding"] = "UTF-8";
            //证书ID
            param["certId"] = CertUtil.GetSignCertId();
            //签名方法
            param["signMethod"] = "01";
            //交易类型
            param["txnType"] = "31";
            //交易子类
            param["txnSubType"] = "00";
            //业务类型
            param["bizType"] = "000201";
            //接入类型
            param["accessType"] = "0";
            //渠道类型
            param["channelType"] = "07";
            //商户订单号,重新产生,不同于原消费
            param["orderId"] = orderId;
            //商户代码,请改成自己的测试商户号
            param["merId"] = MER_ID;
            //原消费的queryId,可以从查询接口或者通知接口中获取
            param["origQryId"] = "201502112158205063088";
            //订单发送时间,重新产生,不同于原消费
            param["txnTime"] = DateTime.Now.ToString("yyyyMMddHHmmss");
            //交易金额,消费撤销时需和原消费一致
            param["txnAmt"] = "1";
            //后台通知地址,改自己的外网地址
            param["backUrl"] = "http://222.222.222.222:8080/demo/utf8/BackRcvResponse.aspx";
            //请求方保留域,透传字段,查询、通知、对账文件中均会原样出现
            param["reqReserved"] = "透传信息";

            //签名
            SDKUtil.Sign(param, Encoding.UTF8);
            Response.Write("\n" + "请求报文=[" + SDKUtil.PrintDictionaryToString(param) + "]\n");

            //初始化通信处理类
            HttpClient hc = new HttpClient(SDKConfig.BackTransUrl);
            //发送请求获取通信应答
            int status = hc.Send(param, Encoding.UTF8);
            //返回结果
            string result = hc.Result;
            if (status == 200)
            {
                Response.Write("返回报文=[" + result + "]\n");
                Dictionary<string, string> resData = SDKUtil.CoverstringToDictionary(result);
                string respcode = resData["respCode"];

                if (SDKUtil.Validate(resData, Encoding.UTF8))
                {
                    Response.Write("商户端验证返回报文签名成功\n");
                }
                else
                {
                    Response.Write("商户端验证返回报文签名失败\n");
                }
            }
            else
            {
                Response.Write("请求失败\n");
                Response.Write("返回报文=[" + result + "]\n");
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 控件获取tn交易
        /// </summary>
        public void AppConsume()
        {
            Dictionary<string, string> param = new Dictionary<string, string>();
            //订单号
            string orderId = Request.QueryString["order_id"];
            long money = Convert.ToInt64(Convert.ToDecimal(Request.Form["money"]) * 100);

            //域名
            string domain = SDT.PAY.Controllers.APIController.GetHostDomain(this.Request);

            //版本号
            param["version"] = "5.0.0";
            //编码方式
            param["encoding"] = "UTF-8";
            //证书ID
            param["certId"] = CertUtil.GetSignCertId();
            //交易类型
            param["txnType"] = "01";
            //交易子类
            param["txnSubType"] = "01";
            //业务类型
            param["bizType"] = "000201";
            //前台通知地址 ,控件接入方式无作用
            param["frontUrl"] = domain + "/unionpay/FrontRcvResponse";
            //后台通知地址
            param["backUrl"] = domain + "/unionpay/BackRecvResponse";
            //签名方法
            param["signMethod"] = "01";
            //渠道类型,07-PC,08-手机
            param["channelType"] = "08";
            //接入类型
            param["accessType"] = "0";
            //商户号
            param["merId"] = MER_ID;
            //商户订单号
            param["orderId"] = orderId;
            //订单发送时间
            param["txnTime"] = DateTime.Now.ToString("yyyyMMddHHmmss");
            //交易金额
            param["txnAmt"] = money.ToString();
            //交易币种
            param["currencyCode"] = "156";
            //订单描述,可不上送,上送时控件中会显示该信息
            param["orderDesc"] = "SIMMA-PAY";
            //请求方保留域,透传字段,查询、通知、对账文件中均会原样出现
            param["reqReserved"] = "SIMMA";

            //签名
            SDKUtil.Sign(param, Encoding.UTF8);

            //初始化通信处理类
            HttpClient hc = new HttpClient(SDKConfig.AppRequestUrl);
            //发送请求获取通信应答
            int status = hc.Send(param, Encoding.UTF8);
            //返回结果
            string result = hc.Result;
            if (status == 200)
            {
                Dictionary<string, string> resData = SDKUtil.CoverstringToDictionary(result);
                string respcode = resData["respCode"];

                if (SDKUtil.Validate(resData, Encoding.UTF8) && resData.ContainsKey("tn"))
                {
                    Response.Write(resData["tn"]);
                }
            }
        }