예제 #1
0
        public static async Task <decimal> PostOrderQueryAsync(long orderid)
        {
            XElem x = new XElem("xml");

            x.AddChild("appid", appid);
            x.AddChild("mch_id", mchid);
            x.AddChild("nonce_str", noncestr);
            x.AddChild("out_trade_no", orderid.ToString());
            string sign = Sign(x);

            x.AddChild("sign", sign);

            XElem xe = (await WCPay.PostAsync <XElem>(null, "/pay/orderquery", x.Dump())).B;

            sign = xe.Child(nameof(sign));
            xe.Sort();
            if (sign != Sign(xe, "sign"))
            {
                return(0);
            }

            string return_code = xe.Child(nameof(return_code));

            if (return_code != "SUCCESS")
            {
                return(0);
            }

            decimal cash_fee = xe.Child(nameof(cash_fee));

            return(cash_fee);
        }
예제 #2
0
        public static bool Notified(XElem xe, out long out_trade_no, out decimal cash)
        {
            cash         = 0;
            out_trade_no = 0;

            string appid     = xe.Child(nameof(appid));
            string mch_id    = xe.Child(nameof(mch_id));
            string nonce_str = xe.Child(nameof(nonce_str));

            if (appid != WeiXinUtility.appid || mch_id != mchid || nonce_str != noncestr)
            {
                return(false);
            }

            string result_code = xe.Child(nameof(result_code));

            if (result_code != "SUCCESS")
            {
                return(false);
            }

            string sign = xe.Child(nameof(sign));

            xe.Sort();
            if (sign != Sign(xe, "sign"))
            {
                return(false);
            }

            int cash_fee = xe.Child(nameof(cash_fee)); // in cent

            cash         = ((decimal)cash_fee) / 100;
            out_trade_no = xe.Child(nameof(out_trade_no)); // 商户订单号
            return(true);
        }
예제 #3
0
        public static async Task <string> PostRefundQueryAsync(long orderid)
        {
            XElem xo = new XElem("xml");

            xo.AddChild("appid", appid);
            xo.AddChild("mch_id", mchid);
            xo.AddChild("nonce_str", noncestr);
            xo.AddChild("out_trade_no", orderid.ToString());
            string sign = Sign(xo);

            xo.AddChild("sign", sign);

            XElem xi = (await WCPay.PostAsync <XElem>(null, "/pay/refundquery", xo.Dump())).B;

            sign = xi.Child(nameof(sign));
            xi.Sort();
            if (sign != Sign(xi, "sign"))
            {
                return("返回结果签名错误");
            }

            string return_code = xi.Child(nameof(return_code));

            if (return_code != "SUCCESS")
            {
                string return_msg = xi.Child(nameof(return_msg));
                return(return_msg);
            }

            string result_code = xi.Child(nameof(result_code));

            if (result_code != "SUCCESS")
            {
                return("退款订单查询失败");
            }

            string refund_status_0 = xi.Child(nameof(refund_status_0));

            if (refund_status_0 != "SUCCESS")
            {
                return(refund_status_0 == "PROCESSING" ? "退款处理中" : refund_status_0 == "REFUNDCLOSE" ? "退款关闭" : "退款异常");
            }

            return(null);
        }