Пример #1
0
        /// <summary>
        /// 退款查询
        /// </summary>
        /// <param name="config"></param>
        /// <param name="body"></param>
        /// <param name="outTradeNo"></param>
        /// <param name="outRefundNo"></param>
        /// <param name="totalFee"></param>
        /// <returns></returns>
        public static Message PayRefundQuery(TenPayConfig config, string outRefundNo)
        {
            Message payMsg       = new Message();
            JObject paramJObject = new JObject
            {
                new JProperty("refund_out_no", outRefundNo)
            };
            string bizData  = PingAnPayHelp.MakeDataJson(paramJObject.ToString(), openKey);
            string postData = PingAnPayHelp.SignAndPostData(bizData, openId, openKey);
            //请求统一下单支付API
            string  requestUrl  = ConfigurationManager.AppSettings["pingan_interface"] + "payrefundquery";
            string  responseStr = PingAnPayHelp.Post(requestUrl, postData);//调用接口
            JObject jResult     = JObject.Parse(responseStr);

            //查看返回结果
            if (!jResult.SelectToken("errcode").ToString().Equals("0"))
            {
                payMsg.state = false;
                payMsg.data  = payMsg.error = jResult.SelectToken("msg").ToString();
                return(payMsg);
            }
            //验签
            if (!PingAnPayHelp.CheckSign(jResult.SelectToken("data").ToString(), jResult.SelectToken("errcode").ToString(),
                                         openKey, jResult.SelectToken("msg").ToString(),
                                         jResult.SelectToken("sign").ToString(), jResult.SelectToken("timestamp").ToString()))
            {
                payMsg.state = false;
                payMsg.data  = payMsg.error = "签名不一致!";
                return(payMsg);
            }



            string  dataStr = PingAnPayHelp.GetDataJson(jResult.SelectToken("data").ToString(), openKey);
            JObject jData   = JObject.Parse(dataStr);

            if ("1".Equals(jData.SelectToken("status").ToString()))
            {
                payMsg.state = true;
                payMsg.data  = PingAnPayHelp.MakeXmlRep(jResult.SelectToken("errcode").ToString(), jData.SelectToken("status").ToString(), "", jResult.SelectToken("msg").ToString(),
                                                        "");
                payMsg.error = "退款成功!";
                return(payMsg);
            }
            payMsg.state = false;
            payMsg.data  = payMsg.error = "退款失败!";
            return(payMsg);
        }
Пример #2
0
        /// <summary>
        /// 退款
        /// </summary>
        /// <param name="config"></param>
        /// <param name="body"></param>
        /// <param name="out_trade_no"></param>
        /// <param name="total_fee"></param>
        /// <returns></returns>
        public static Message PayRefund(TenPayConfig config, string out_trade_no, string out_refund_no, int total_fee, int refund_fee, string refund_desc)
        {
            Message payMsg       = new Message();
            string  refundPwd    = ConfigurationManager.AppSettings["pingan_refund_pwd"];
            JObject paramJObject = new JObject
            {
                new JProperty("out_no", out_trade_no),
                new JProperty("refund_out_no", out_refund_no),
                new JProperty("refund_ord_name", refund_desc),
                new JProperty("refund_amount", refund_fee),
                new JProperty("shop_pass", Utilities.SHA1(refundPwd).ToLower())
            };
            string bizData = PingAnPayHelp.MakeDataJson(paramJObject.ToString(), openKey);

            string postData = PingAnPayHelp.RefundSignAndPostData(bizData, openId, openKey);
            //请求统一下单支付API
            string  requestUrl  = ConfigurationManager.AppSettings["pingan_interface"] + "payrefund";
            string  responseStr = PingAnPayHelp.Post(requestUrl, postData);//调用接口
            JObject jResult     = JObject.Parse(responseStr);

            //查看返回结果
            if (!jResult.SelectToken("errcode").ToString().Equals("0"))
            {
                payMsg.state = false;
                payMsg.data  = payMsg.error = jResult.SelectToken("msg").ToString();
                return(payMsg);
            }
            //验签
            if (!PingAnPayHelp.CheckSign(jResult.SelectToken("data").ToString(), jResult.SelectToken("errcode").ToString(),
                                         openKey, jResult.SelectToken("msg").ToString(),
                                         jResult.SelectToken("sign").ToString(), jResult.SelectToken("timestamp").ToString()))
            {
                payMsg.state = false;
                payMsg.data  = payMsg.error = "签名不一致!";
                return(payMsg);
            }


            string  dataStr = PingAnPayHelp.GetDataJson(jResult.SelectToken("data").ToString(), openKey);
            JObject jData   = JObject.Parse(dataStr);

            //验证主要参数
            if (total_fee != (int)jData.SelectToken("trade_amount"))
            {
                payMsg.state = false;
                payMsg.data  = payMsg.error = "请求退款金额与实际退款金额不一致!";
                return(payMsg);
            }
            if ("1".Equals(jData.SelectToken("status").ToString()))
            {
                payMsg.state = true;
                payMsg.data  = PingAnPayHelp.MakeXmlRep(jResult.SelectToken("errcode").ToString(), jData.SelectToken("status").ToString(),
                                                        jData.SelectToken("ord_no").ToString(), jResult.SelectToken("msg").ToString(),
                                                        "");
                payMsg.error = "退款请求成功!";
                return(payMsg);
            }
            payMsg.state = false;
            payMsg.data  = payMsg.error = "退款失败!";
            return(payMsg);
        }