示例#1
0
        /// <summary>
        /// 申请退款订单
        /// </summary>
        /// <param name="out_trade_no">商户订单号</param>
        /// <param name="out_refund_no">商户退款单号</param>
        /// <param name="total_fee">订单金额,单位/分</param>
        /// <param name="refund_fee">申请退款金额,单位/分</param>
        /// <param name="notify_url">退款异步通知回调地址</param>
        /// <param name="refund_desc">退款原因</param>
        /// <returns>callback xml</returns>
        public string Refund(string out_trade_no, string out_refund_no, string total_fee, string refund_fee, string notify_url = null, string refund_desc = null)
        {
            #region 查询map
            SortedDictionary <string, string> sortedDictionary = new SortedDictionary <string, string>()
            {
                { "appid", WxConfig.AppId },            //微信分配的公众账号ID(企业号corpid即为此appId)
                { "mch_id", WxConfig.MCH_ID },          //商户号
                { "nonce_str", WxUtils.RandomStr(16) }, //随机16位字符串
                { "out_refund_no", out_refund_no },     //商户内部退款单号,同一单号退款多次申请只退一次
                { "out_trade_no", out_trade_no },       //商户订单号
                { "total_fee", total_fee },             //订单总金额
                { "refund_fee", refund_fee },           //申请退款金额,不能大于订单总金额
            };
            if (string.IsNullOrEmpty(notify_url))
            {
                sortedDictionary.Add("notify_url", notify_url);
            }
            if (string.IsNullOrEmpty(notify_url))
            {
                sortedDictionary.Add("refund_desc", refund_desc);
            }
            #endregion

            #region 生成sign
            string md5key = $@"{ sortedDictionary.SortedDictionaryToWxUrl()}&key={WxConfig.PARTNER_ID}";
            string sign   = WxUtils.GetSign(md5key, "utf-8");
            string xml    = sortedDictionary.SortedDictionaryToWxXml().Replace("</xml>", $@"<sign><![CDATA[{ sign }]]></sign></xml>");
            #endregion

            return(WxUtils.PostToWxOpenApi(refundUrl, xml));
        }
示例#2
0
        /// <summary>
        /// 申请支付
        /// </summary>
        public string Paying(string auth_code, string device_info, string body, string out_trade_no, string notify_url, string total_fee)
        {
            string ip = _contextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString();

            #region  单map
            SortedDictionary <string, string> sortedDictionary = new SortedDictionary <string, string>()
            {
                { "appid", WxConfig.AppId },            //微信分配的公众账号ID(企业号corpid即为此appId)
                { "attach", "wxpay" },                  //说明.
                { "auth_code", auth_code },             //扫码支付授权码
                { "body", body },                       //xxx店-收银机收款
                { "device_info", device_info },         //设备号
                { "mch_id", WxConfig.MCH_ID },          //商户号
                { "nonce_str", WxUtils.RandomStr(16) }, //随机16位字符串
                { "out_trade_no", out_trade_no },       //订单号
                { "notify_url", notify_url },
                { "spbill_create_ip", ip },             //用户IP
                { "total_fee", total_fee },             //金额
            };
            #endregion

            #region 生成sign
            string md5key = $@"{ sortedDictionary.SortedDictionaryToWxUrl()}&key={WxConfig.PARTNER_ID}";
            string sign   = WxUtils.GetSign(md5key, "utf-8");
            string xml    = sortedDictionary.SortedDictionaryToWxXml().Replace("</xml>", $@"<sign><![CDATA[{ sign }]]></sign></xml>");
            #endregion

            return(WxUtils.PostToWxOpenApi(payByCardUrl, xml));
        }
示例#3
0
        /// <summary>
        ///统一下单接口
        /// </summary>
        /// <param name="total_fee">订单金额</param>
        /// <param name="out_trade_no">订单号</param>
        /// <returns></returns>
        public MobilePayOutput Paying(string total_fee, string out_trade_no)
        {
            #region 统一下单map
            SortedDictionary <string, string> sortedDictionary = new SortedDictionary <string, string>()
            {
                { "appid", WxConfig.AppId },
                { "attach", "wxpay" },
                { "body", "订单支付" },
                { "mch_id", WxConfig.MCH_ID },
                { "nonce_str", WxUtils.RandomStr(16) },
                { "notify_url", WxConfig.AppPayNodifyUrl },
                { "spbill_create_ip", "" }, //用户IP
                { "total_fee", total_fee }, //金额
                { "trade_type", "APP" },
                { "out_trade_no", out_trade_no }//订单号
            };
            #endregion

            #region 生成sign
            string md5key = $@"{ sortedDictionary.SortedDictionaryToWxUrl()}&key={WxConfig.PARTNER_ID}";
            string sign   = WxUtils.GetSign(md5key, "utf-8");
            #endregion

            #region 请求微信统一下单接口 获取预支付订单号
            string xml         = sortedDictionary.SortedDictionaryToWxXml().Replace("</xml>", $@"<sign><![CDATA[{ sign }]]></sign></xml>");
            string callbackXml = WxUtils.PostToWxOpenApi(unifiedorderUrl, xml);//请求微信统一下单接口
            MobilePayCallbackDto callbackobj = (MobilePayCallbackDto)WxUtils.XmlDeserialize(typeof(MobilePayCallbackDto), callbackXml);
            #endregion

            #region 用户端sign
            MobilePayOutput output = new MobilePayOutput
            {
                appid     = WxConfig.AppId,
                noncestr  = WxUtils.RandomStr(16),
                package   = "Sign=WXPay",
                partnerid = WxConfig.PARTNER_ID,
                prepayid  = callbackobj.prepay_id,
                timestamp = DateTime.UtcNow.ToTimeStamp(),
                sign      = "",
            };
            var    appmap    = WxUtils.ObjToSortedDictionary(output);
            string appmd5key = $@"{ appmap.SortedDictionaryToWxUrl()}&key={WxConfig.PARTNER_ID}";
            output.sign = WxUtils.GetSign(appmd5key, "utf-8");
            #endregion
            return(output);
        }
示例#4
0
        /// <summary>
        /// 根据商户订单号查询微信支付状态
        /// </summary>
        /// <param name="out_trade_no">商户订单号</param>
        /// <returns></returns>
        public string OrderQueryByOrderNumber(string out_trade_no)
        {
            #region 查询map
            SortedDictionary <string, string> sortedDictionary = new SortedDictionary <string, string>()
            {
                { "appid", WxConfig.AppId },            //微信分配的公众账号ID(企业号corpid即为此appId)
                { "mch_id", WxConfig.MCH_ID },          //商户号
                { "nonce_str", WxUtils.RandomStr(16) }, //随机16位字符串
                { "out_trade_no", out_trade_no }//微信订单号
            };
            #endregion
            #region 生成sign
            string md5key = $@"{ sortedDictionary.SortedDictionaryToWxUrl()}&key={WxConfig.PARTNER_ID}";
            string sign   = WxUtils.GetSign(md5key, "utf-8");
            string xml    = sortedDictionary.SortedDictionaryToWxXml().Replace("</xml>", $@"<sign><![CDATA[{ sign }]]></sign></xml>");
            #endregion

            return(WxUtils.PostToWxOpenApi(orderQueryUrl, xml));
        }