Пример #1
0
        static string Sign(XElem xe, string exclude = null)
        {
            StringBuilder sb = new StringBuilder(1024);

            for (int i = 0; i < xe.Count; i++)
            {
                XElem child = xe.Child(i);

                // not include the sign field
                if (exclude != null && child.Tag == exclude)
                {
                    continue;
                }

                if (sb.Length > 0)
                {
                    sb.Append('&');
                }
                sb.Append(child.Tag).Append('=').Append(child.Text);
            }

            sb.Append("&key=").Append(key);

            return(StrUtility.MD5(sb.ToString()));
        }
Пример #2
0
        public static async Task <string> PostRefundAsync(long orderid, decimal total, decimal cash)
        {
            string orderno = orderid.ToString();

            XElem xo = new XElem("xml");

            xo.AddChild("appid", appid);
            xo.AddChild("mch_id", mchid);
            xo.AddChild("nonce_str", noncestr);
            xo.AddChild("op_user_id", mchid);
            xo.AddChild("out_refund_no", orderno);
            xo.AddChild("out_trade_no", orderno);
            xo.AddChild("refund_fee", ((int)(cash * 100)).ToString());
            xo.AddChild("total_fee", ((int)(total * 100)).ToString());
            string sign = Sign(xo);

            xo.AddChild("sign", sign);

            XElem  xi          = (await WCPay.PostAsync <XElem>(null, "/secapi/pay/refund", xo.Dump())).B;
            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")
            {
                string err_code_des = xi.Child(nameof(err_code_des));
                return(err_code_des);
            }
            return(null);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
0
        public static async Task <string> PostUnifiedOrderAsync(long orderid, decimal total, string openid, string ip, string notifyurl)
        {
            XElem x = new XElem("xml");

            x.AddChild("appid", appid);
            x.AddChild("body", BODY_DESC);
            x.AddChild("mch_id", mchid);
            x.AddChild("nonce_str", noncestr);
            x.AddChild("notify_url", notifyurl);
            x.AddChild("openid", openid);
            x.AddChild("out_trade_no", orderid.ToString());
            x.AddChild("spbill_create_ip", ip);
            x.AddChild("total_fee", ((int)(total * 100)).ToString());
            x.AddChild("trade_type", "JSAPI");
            string sign = Sign(x);

            x.AddChild("sign", sign);

            XElem  xe        = (await WCPay.PostAsync <XElem>(null, "/pay/unifiedorder", x.Dump())).B;
            string prepay_id = xe.Child(nameof(prepay_id));

            if (prepay_id == null)
            {
                prepay_id = xe.Child("err_code");
            }

            return(prepay_id);
        }
Пример #6
0
 public void Put(string name, XElem v)
 {
     if (name != null)
     {
         Build(name);
     }
     else
     {
         throw new NotImplementedException();
     }
 }
Пример #7
0
        //针对新建案件文件;
        public CaseEvidence(string[] typeGuids, string name, string interLabel) :
            this(CreateXElemByInfoes(typeGuids, name, interLabel))
        {
            if (typeGuids == null)
            {
                throw new ArgumentNullException(nameof(typeGuids));
            }

            var newGuid = Guid.NewGuid().ToString("N").ToUpper();

            //首次创建需摇号;
            XElem.SetXElemValue(newGuid, Contracts.Common.Constants.EvidenceGUID);

            SetInstance(EvidenceGUID, Contracts.Common.Constants.EvidenceGUID);
        }
Пример #8
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);
        }
Пример #9
0
        /// <summary>
        /// WCPay notify, placed here due to non-authentic context.
        /// </summary>
        public async Task notify(ActionContext ac)
        {
            XElem xe = await ac.ReadAsync <XElem>();

            long    orderid;
            decimal cash;

            if (Notified(xe, out orderid, out cash))
            {
                string mgrwx = null;
                using (var dc = NewDbContext())
                {
                    var shopid = (string)dc.Scalar("UPDATE orders SET cash = @1, accepted = localtimestamp, status = @2 WHERE id = @3 AND status <= @2 RETURNING shopid", (p) => p.Set(cash).Set(Order.ACCEPTED).Set(orderid));
                    if (shopid != null)
                    {
                        mgrwx = (string)dc.Scalar("SELECT mgrwx FROM shops WHERE id = @1", p => p.Set(shopid));
                    }
                }
                // return xml
                XmlContent cont = new XmlContent(true, 1024);
                cont.ELEM("xml", null, () =>
                {
                    cont.ELEM("return_code", "SUCCESS");
                    cont.ELEM("return_msg", "OK");
                });

                if (mgrwx != null)
                {
                    await PostSendAsync(mgrwx, "【买家付款】订单编号:" + orderid + ",金额:" + cash + "元");
                }

                ac.Give(200, cont);
            }
            else
            {
                ac.Give(400);
            }
        }
Пример #10
0
        public static async Task <string> PostTransferAsync(int id, string openid, string username, decimal cash, string desc)
        {
            XElem x = new XElem("xml");

            x.AddChild("amount", ((int)(cash * 100)).ToString());
            x.AddChild("check_name", "FORCE_CHECK");
            x.AddChild("desc", desc);
            x.AddChild("mch_appid", appid);
            x.AddChild("mchid", mchid);
            x.AddChild("nonce_str", noncestr);
            x.AddChild("openid", openid);
            x.AddChild("partner_trade_no", id.ToString());
            x.AddChild("re_user_name", username);
            x.AddChild("spbill_create_ip", spbillcreateip);

            string sign = Sign(x);

            x.AddChild("sign", sign);

            XElem  xe          = (await WCPay.PostAsync <XElem>(null, "/mmpaymkttransfers/promotion/transfers", x.Dump())).B;
            string return_code = xe.Child(nameof(return_code));

            if ("SUCCESS" == return_code)
            {
                string result_code = xe.Child(nameof(result_code));
                if ("SUCCESS" != result_code)
                {
                    string err_code_des = xe.Child(nameof(err_code_des));
                    return(err_code_des);
                }
            }
            else
            {
                string return_msg = xe.Child(nameof(return_msg));
                return(return_msg);
            }
            return(null);
        }