Esempio n. 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);
        }
Esempio n. 2
0
        /// <summary>
        /// 凭证码、身份证核销
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static TVMResult <bool> VerifyTicket(VerifyTicket_Object obj)
        {
            var data   = JsonSerializeHelper.ToJson(obj);
            var result = HttpHelper.Post(urlTvm + "VerifyTicket", data, 180);

            return(JsonSerializeHelper.ToObject <TVMResult <bool> >(result));
        }
Esempio n. 3
0
        /// <summary>
        /// 查询支付
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static TVMResult <TVMPayInfo> QueryPay(QuickPayment_Object obj)
        {
            var data   = JsonSerializeHelper.ToJson(obj);
            var result = HttpHelper.Post(urlTvm + "QueryPay", data, 60);

            return(JsonSerializeHelper.ToObject <TVMResult <TVMPayInfo> >(result));
        }
Esempio n. 4
0
        /// <summary>
        /// 门票售卖
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static TVMResult <List <SaleTicket_Result> > SaleTicket(QuickPayment_Object obj)
        {
            var data   = JsonSerializeHelper.ToJson(obj);
            var result = HttpHelper.Post(urlTvm + "SaleTicket", data, 60);

            return(JsonSerializeHelper.ToObject <TVMResult <List <SaleTicket_Result> > >(result));
        }
Esempio n. 5
0
        /// <summary>
        /// 消费通知接口
        /// </summary>
        /// <param name="noticeOrderConsumedRequest"></param>
        /// <returns></returns>
        public static bool Run(ConsumeNoticeRequest consumeNoticeRequest)
        {
            string requestBody = JsonSerializeHelper.ToJson(consumeNoticeRequest);

            requestBody = DesHelper.Encrypt(requestBody, TongChengConfig.UserKey);
            var         sign    = Helper.MakeSign("ConsumeNotice", requestBody);
            RequestData request = new RequestData
            {
                RequestHead = new RequestHead
                {
                    user_id   = TongChengConfig.UserId,
                    Method    = "ConsumeNotice",
                    Timestamp = Helper.GenerateTimeStamp(),
                    Version   = TongChengConfig.Version,
                    Sign      = sign
                },
                RequestBody = requestBody
            };
            string body = JsonSerializeHelper.ToJson(request);

            body = Helper.Base64Encode(body);
            var contnt = HttpService.Post(body, TongChengConfig.Website);

            if (!string.IsNullOrEmpty(contnt))
            {
                contnt = Helper.Base64Decode(contnt);
                var response = JsonSerializeHelper.ToObject <ResponseData>(contnt);
                if (response != null && response.responseHead.res_code == ResultCode.Success)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 6
0
        /// <summary>
        /// 获取产品信息
        /// </summary>
        /// <param name="device"></param>
        /// <returns></returns>
        public static TVMResult <GUITikcetConfig> DeviceIni(TVMDevice device)
        {
            var data   = JsonSerializeHelper.ToJson(device);
            var result = HttpHelper.Post(urlTvm + "DeviceIni", data, 60);

            return(JsonSerializeHelper.ToObject <TVMResult <GUITikcetConfig> >(result));
        }
Esempio n. 7
0
        /// <summary>
        /// 凭证码、身份证取票
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static TVMResult <TVMTicketInfo[]> GetTicketOrder(TicketOrder_Object obj)
        {
            var data   = JsonSerializeHelper.ToJson(obj);
            var result = HttpHelper.Post(urlTvm + "GetTicketOrder", data, 180);

            return(JsonSerializeHelper.ToObject <TVMResult <TVMTicketInfo[]> >(result));
        }
Esempio n. 8
0
        public static Result <TicketResult> Ticket_CheckTicket(CheckTicket_Object checkTicketObject)
        {
            var data   = JsonSerializeHelper.ToJson(checkTicketObject);
            var result = HttpHelper.Post(url + "Ticket_CheckTicket", data, 60);

            return(JsonSerializeHelper.ToObject <Result <TicketResult> >(result));
        }
Esempio n. 9
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);
            }
        }
Esempio n. 10
0
        public static Result <TicketResult> Ticket_SubmitWalkPast(SubmitWalkPast_Object submitWalkPastObject)
        {
            var data   = JsonSerializeHelper.ToJson(submitWalkPastObject);
            var result = HttpHelper.Post(url + "Ticket_SubmitWalkPast", data, 60);

            return(JsonSerializeHelper.ToObject <Result <TicketResult> >(result));
        }
Esempio n. 11
0
        ///// <summary>
        ///// 验证数据是否被篡改(签名等)
        ///// </summary>
        ///// <param name="request"></param>
        ///// <returns></returns>
        //public static Result<HeaderRequest> CheckHeader(string request)
        //{
        //    var requestData = CheckHeaderFormat(request);
        //    if (requestData == null)
        //    {
        //        return Result<HeaderRequest>.FailResult(ErrorResult(ResultCode.XmlParsingFailure, "XML解析失败"));
        //    }
        //    if (requestData.accountId != CtripConfig.MyAccountId)
        //    {
        //        return Result<HeaderRequest>.FailResult(ErrorResult(ResultCode.IncorrectAccountInformation, "OTA账户信息不正确"));
        //    }
        //    var isSign = CheckSign(request, requestData);
        //    if (!isSign)
        //    {
        //        return Result<HeaderRequest>.FailResult(ErrorResult(ResultCode.SignatureError, "签名错误"));
        //    }

        //    return Result<HeaderRequest>.SuccessResult(requestData);
        //}

        /// <summary>
        /// 验证数据结构
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="request"></param>
        /// <returns></returns>
        public static Result <T> CheckBodyData <T>(string request)
        {
            var requestBodyData = JsonSerializeHelper.ToObject <T>(request);

            if (requestBodyData == null)
            {
                return(null);
            }
            return(Result <T> .SuccessResult(requestBodyData));
        }
Esempio n. 12
0
 /// <summary>
 /// 验证请求内容(json数据是否正确)
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="data"></param>
 /// <returns></returns>
 public static T CheckRequestBody <T>(string data)
 {
     try
     {
         var request = JsonSerializeHelper.ToObject <T>(data);
         if (request == null)
         {
             return(default(T));
         }
         return(request);
     }
     catch
     {
         return(default(T));
     }
 }
Esempio n. 13
0
 /// <summary>
 /// 验证格式是否正确
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 private static RequestData CheckFormat(string data)
 {
     try
     {
         var request = JsonSerializeHelper.ToObject <RequestData>(data);
         if (request.Header == null || string.IsNullOrEmpty(request.Body))
         {
             return(null);
         }
         return(request);
     }
     catch
     {
         return(null);
     }
 }
Esempio n. 14
0
 /// <summary>
 /// 验证格式是否正确
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 public static RequestData CheckFormat(string data)
 {
     try
     {
         data = Helper.Base64Decode(data);
         var request = JsonSerializeHelper.ToObject <RequestData>(data);
         if (request.RequestHead == null || string.IsNullOrEmpty(request.RequestBody))
         {
             return(null);
         }
         return(request);
     }
     catch
     {
         return(null);
     }
 }
Esempio n. 15
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);
        }
Esempio n. 16
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);
        }
Esempio n. 17
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);
        }
Esempio n. 18
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);
        }