Example #1
0
        public static OrderQueryResponse Query(string outTradeNo)
        {
            // 1固定参数
            PayData postmap = new PayData();    // 请求参数的map

            postmap.Put("version", PayConfig.Version);
            postmap.Put("reqtime", DateTime.Now.ToString("yyyyMMddHHmmss"));
            postmap.Put("rancode", Helper.GenerateRandom(5));
            postmap.Put("snNo", PayConfig.SnNo);
            postmap.Put("outTradeNo", outTradeNo);//外部接入系统订单号
            postmap.Put("systemCode", PayConfig.SystemCode);

            // 2签名
            string sign = Helper.MakeSign(postmap.ToUrl());

            postmap.Put("sign", sign);

            // 3请求、响应
            string rspStr = HttpService.Post(postmap.ToJson(), PayConfig.WebSite + "/merchantpay/trade/orderquery?" + postmap.ToUrl());

            var response = JsonSerializeHelper.ToObject <OrderQueryResponse>(rspStr);

            if (response.ReturnCode == ResultCode.Success)
            {
                //签名验证
                Helper.CheckSign(rspStr, response.Sign);
                response.QueryData = JsonSerializeHelper.ToObject <OrderQueryDataResponse>(response.Data);
            }
            return(response);
        }
Example #2
0
        public static void Run()
        {
            // 1固定参数
            PayData postmap = new PayData();    // 请求参数的map

            postmap.Put("rancode", Helper.GenerateRandom(5));
            postmap.Put("reqtime", DateTime.Now.ToString("yyyyMMddHHmmss"));
            postmap.Put("snNo", PayConfig.SnNo);
            postmap.Put("systemCode", PayConfig.SystemCode);
            postmap.Put("vender", "123456");
            postmap.Put("version", PayConfig.Version);

            // 2签名
            string sign = Helper.MakeSign(postmap.ToUrl(), PayConfig.DefaultKey);

            postmap.Put("sign", sign);
            //return;
            // 3请求、响应
            string rspStr = HttpService.Post(postmap.ToJson(), PayConfig.WebSite + "/merchantpay/trade/login?" + postmap.ToUrl());

            rspStr = rspStr.Replace("/", "");

            var response = JsonSerializeHelper.ToObject <ActivationResponse>(rspStr);

            if (response.ReturnCode == ResultCode.Success)
            {
                //var data = JsonSerializeHelper.ToObject<ActivationDataResponse>(response.Data);
                //var key = DesHelper.Decrypt(data.Key, PayConfig.DefaultKey);
            }
        }
Example #3
0
        public static OrderQueryResponse Run(string outTradeNo, string amount)
        {
            // 1固定参数
            PayData postmap = new PayData();    // 请求参数的map

            postmap.Put("version", PayConfig.Version);
            postmap.Put("reqtime", DateTime.Now.ToString("yyyyMMddHHmmss"));
            postmap.Put("rancode", Helper.GenerateRandom(5));
            postmap.Put("snNo", PayConfig.SnNo);

            postmap.Put("terminalType", "OTHER");
            postmap.Put("amount", amount);

            postmap.Put("refundNo", outTradeNo);//外部接入系统订单号
            postmap.Put("systemCode", PayConfig.SystemCode);

            // 2签名
            string sign = Helper.MakeSign(postmap.ToUrl());

            postmap.Put("sign", sign);

            // 3请求、响应
            string rspStr = HttpService.Post(postmap.ToJson(), PayConfig.WebSite + "/merchantpay/trade/refund?" + postmap.ToUrl());

            var response = JsonSerializeHelper.ToObject <OrderQueryResponse>(rspStr);

            if (response.ReturnCode == ResultCode.Success)
            {
                //签名验证
                Helper.CheckSign(rspStr, response.Sign);
                response.QueryData = JsonSerializeHelper.ToObject <OrderQueryDataResponse>(response.Data);

                //{ "bankOrderNo":"2018070517331227995415892","dateStr":"20180705173313","merchantNo":"0210a03fdd9c471d8682b584767bec4b","outChannelNo":"400012018070517331224222976","outTradeNo":"180705173311185002","returnCode":"userPaying","returnMessage":"需要用户输入支付密码","sign":"E43019AA329482DF381DD7C108A475F3","transTime":null}
            }
            return(response);
        }
Example #4
0
        /// <summary>
        /// 微信(支付宝)被扫下单接口
        /// </summary>
        /// <param name="totalFee">支付金额,单位:元,保留小数点后两位</param>
        /// <param name="authCode">支付码</param>
        /// <param name="outTradeNo">订单号</param>
        /// <returns></returns>
        public static PayResult Pay(string totalFee, string authCode, string outTradeNo)
        {
            var result = new PayResult
            {
                Success = false
            };

            if (string.IsNullOrEmpty(totalFee))
            {
                result.Message = "支付金额,不能为空";
                return(result);
            }
            if (string.IsNullOrEmpty(authCode))
            {
                result.Message = "支付码,不能为空";
                return(result);
            }
            if (string.IsNullOrEmpty(outTradeNo))
            {
                result.Message = "订单号,不能为空";
                return(result);
            }

            // 1固定参数
            PayData postmap = new PayData();

            postmap.Put("version", PayConfig.Version);
            postmap.Put("rancode", Helper.GenerateRandom(5));
            postmap.Put("reqtime", DateTime.Now.ToString("yyyyMMddHHmmss"));
            postmap.Put("snNo", PayConfig.SnNo);
            postmap.Put("terminalType", "OTHER");
            postmap.Put("outTradeNo", outTradeNo); //外部接入系统订单号
            postmap.Put("amount", totalFee);       //支付金额,单位:元,保留小数点后两位
            postmap.Put("authCode", authCode);     //支付码
            postmap.Put("casherNo", "T001");       //收银员编号
            postmap.Put("description", "OTHER");
            postmap.Put("orderTime", DateTime.Now.ToString("yyyyMMddHHmmss"));
            postmap.Put("systemCode", PayConfig.SystemCode);

            // 2签名
            string sign = Helper.MakeSign(postmap.ToUrl());

            postmap.Put("sign", sign);

            // 3请求、响应
            string rspStr = HttpService.Post(postmap.ToJson(), PayConfig.WebSite + "/merchantpay/trade/microorder?" + postmap.ToUrl());

            var response = JsonSerializeHelper.ToObject <MicroOrderResponse>(rspStr);

            result.Message = response.ReturnMessage;

            if (response.ReturnCode == ResultCode.Success)
            {
                //支付成功
                //签名验证
                Helper.CheckSign(rspStr, response.Sign);
                var queryResult = OrderQuery.Query(response.OutTradeNo);//用商户订单号去查单
                result.Success    = true;
                result.Message    = "支付成功";
                result.OutTradeNo = queryResult.QueryData.CustomerNo;
                return(result);
            }
            if (response.ReturnCode == ResultCode.UserPaying)
            {
                //签名验证
                Helper.CheckSign(rspStr, response.Sign);
                //等待用户支付,需查单
                //用商户订单号去查单

                //确认支付是否成功,每隔一段时间查询一次订单,共查询30次--订单有效时间1分钟
                int queryTimes = 30;//查询次数计数器
                while (queryTimes-- > 0)
                {
                    var queryResult = OrderQuery.Query(response.OutTradeNo);//用商户订单号去查单
                    //如果需要继续查询,则等待2s后继续
                    if (queryResult.ReturnCode == ResultCode.Success && (queryResult.QueryData.PayStatus == "I" || queryResult.QueryData.PayStatus == "O"))
                    {
                        Thread.Sleep(2000);
                        continue;
                    }
                    //查询成功,返回订单查询接口返回的数据,支付成功!
                    if (queryResult.ReturnCode == ResultCode.Success && queryResult.QueryData.PayStatus == "P")
                    {
                        result.Success    = true;
                        result.Message    = "支付成功";
                        result.OutTradeNo = queryResult.QueryData.CustomerNo;
                        return(result);
                    }
                    //订单交易失败,直接返回刷卡支付接口返回的结果,失败原因会在err_code中描述
                    result.Message = "支付失败";
                    return(result);
                }
            }

            //Refund.Run(response.BankOrderNo, totalFee);
            //支付失败
            return(result);
        }
Example #5
0
        public static string Run(string body, double total_fee, string authCode, string outTradeNo)
        {
            // 1固定参数
            PayData postmap = new PayData();    // 请求参数的map

            postmap.Put("rancode", Helper.GenerateRandom(5));
            postmap.Put("reqtime", DateTime.Now.ToString("yyyyMMddHHmmss"));
            postmap.Put("snNo", PayConfig.SnNo);
            //postmap.Put("merchantNo", PayConfig.MerchantNo);

            postmap.Put("terminalType", "OTHER");
            postmap.Put("outTradeNo ", outTradeNo);//外部接入系统订单号
            postmap.Put("amount ", total_fee);
            postmap.Put("authCode ", authCode);
            postmap.Put("casherNo ", "T001");//收银员编号
            postmap.Put("description", "OTHER");
            postmap.Put("orderTime", DateTime.Now.ToString("yyyyMMddHHmmss"));
            postmap.Put("systemCode", PayConfig.SystemCode);
            postmap.Put("version", PayConfig.Version);



            byte[] byteArray = System.Text.Encoding.Default.GetBytes(PayConfig.Key);


            byte[] bcdbyte = str2Bcd("B95EB858BAA4170731EDBB0D7661B39A34");
            byte[] keybyte = str2Bcd("1111222233334444");
            byte   ssss    = 0;

            byte[] ggg     = new byte[] { ssss };
            byte   borByte = 0;

            for (int i = 0; i < bcdbyte.Length - 1; i++)
            {
                if (i == 0)
                {
                    borByte = bcdbyte[i];
                }
                borByte ^= bcdbyte[i + 1];
            }
            byte[]        bor = new byte[] { borByte };
            StringBuilder sb  = new StringBuilder(bor.Length);
            String        sTemp;

            for (int i = 0; i < bor.Length; i++)
            {
                sTemp = String.Format("{0:X}", 0xFF & bor[i]);
                //sTemp = Integer.toHexString(0xFF & bor[i]);
                if (sTemp.Count() < 2)
                {
                    sb.Append(0);
                }
                sb.Append(sTemp.ToUpper());
            }
            var str = sb.ToString();

            var key = DesHelper.Decrypt(PayConfig.Key, str);



            // 2签名
            string sign = Helper.MakeSign(postmap.ToUrl(), key);

            postmap.Put("sign", sign);

            // 3请求、响应
            string rspStr = HttpService.Post(postmap.ToJson(), PayConfig.WebSite + "/merchantpay/trade/microorder?" + postmap.ToUrl());



            var response = JsonSerializeHelper.ToObject <ActivationResponse>(rspStr);

            if (response.ReturnCode == ResultCode.Success)
            {
                var data = JsonSerializeHelper.ToObject <ActivationDataResponse>(response.Data);
                //var key = DesHelper.Decrypt(data.Key, PayConfig.DefaultKey);
            }
            return(rspStr);
        }
Example #6
0
        public static string Pay(string body, double totalFee, string authCode, string outTradeNo)
        {
            // 1固定参数
            PayData postmap = new PayData();    // 请求参数的map

            postmap.Put("version", PayConfig.Version);
            postmap.Put("rancode", Helper.GenerateRandom(5));
            postmap.Put("reqtime", DateTime.Now.ToString("yyyyMMddHHmmss"));
            postmap.Put("snNo", PayConfig.SnNo);
            //postmap.Put("merchantNo", PayConfig.MerchantNo);

            postmap.Put("terminalType", "OTHER");
            postmap.Put("outTradeNo", outTradeNo);//外部接入系统订单号
            postmap.Put("amount", totalFee);
            postmap.Put("authCode", authCode);
            postmap.Put("casherNo", "T001");//收银员编号
            postmap.Put("description", "OTHER");
            postmap.Put("orderTime", DateTime.Now.ToString("yyyyMMddHHmmss"));
            postmap.Put("systemCode", PayConfig.SystemCode);



            //byte[] byteArray = System.Text.Encoding.Default.GetBytes(PayConfig.PartnerKey);


            //byte[] bcdbyte = str2Bcd("B95EB858BAA4170731EDBB0D7661B39A34");
            //byte[] keybyte = str2Bcd("1111222233334444");
            //byte ssss = 0;
            //byte[] ggg = new byte[] { ssss };
            //byte borByte = 0;
            //for (int i = 0; i < bcdbyte.Length - 1; i++)
            //{
            //    if (i == 0)
            //    {
            //        borByte = bcdbyte[i];
            //    }
            //    borByte ^= bcdbyte[i + 1];
            //}
            //byte[] bor = new byte[] { borByte };
            //StringBuilder sb = new StringBuilder(bor.Length);
            //String sTemp;
            //for (int i = 0; i < bor.Length; i++)
            //{
            //    sTemp = String.Format("{0:X}", 0xFF & bor[i]);
            //    //sTemp = Integer.toHexString(0xFF & bor[i]);
            //    if (sTemp.Count() < 2)
            //        sb.Append(0);
            //    sb.Append(sTemp.ToUpper());
            //}
            //var str = sb.ToString();


            byte[] byteArray1 = Encoding.UTF8.GetBytes("F8F4221780C0BB9BD605DE12C5008A25C7");



            var sta = "";

            for (var i = 0; i < 32; i++)
            {
                sta += byteArray1[i];
            }

            var dddd = Hex_16To2(sta);



            //var key = SecretUtilTools.DecryptForDes(sta, PayConfig.DefaultKey);

            //var key = "7F7C2C4B5EE403F17D60C6BBACF6A808756060E3B923361F9177630F20164850";

            // 2签名
            string sign = Helper.MakeSign(postmap.ToUrl());

            postmap.Put("sign", sign);

            // 3请求、响应
            string rspStr = HttpService.Post(postmap.ToJson(), PayConfig.WebSite + "/merchantpay/trade/microorder?" + postmap.ToUrl());



            var response = JsonSerializeHelper.ToObject <ActivationResponse>(rspStr);

            if (response.ReturnCode == ResultCode.Success)
            {
                var data = JsonSerializeHelper.ToObject <ActivationDataResponse>(response.Data);
                //var key = DesHelper.Decrypt(data.PartnerKey, PayConfig.DefaultKey);

                //{ "bankOrderNo":"2018070517331227995415892","dateStr":"20180705173313","merchantNo":"0210a03fdd9c471d8682b584767bec4b","outChannelNo":"400012018070517331224222976","outTradeNo":"180705173311185002","returnCode":"userPaying","returnMessage":"需要用户输入支付密码","sign":"E43019AA329482DF381DD7C108A475F3","transTime":null}
            }
            return(rspStr);
        }