Пример #1
0
        /**
         * 调用统一下单,获得下单结果
         * @return 统一下单结果
         * @失败时抛异常WxPayException
         */
        public WxPayData GetUnifiedOrderResult(string pvContent, string pvTitle)
        {
            WxPayApi lvWxPayApi = new WxPayApi();
            //统一下单
            WxPayData data = new WxPayData();

            data.SetValue("body", pvTitle);
            data.SetValue("attach", pvContent);
            data.SetValue("out_trade_no", lvWxPayApi.GenerateOutTradeNo());
            data.SetValue("total_fee", total_fee);
            data.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));
            data.SetValue("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss"));
            data.SetValue("goods_tag", "test");
            data.SetValue("trade_type", "JSAPI");
            data.SetValue("openid", openid);

            WxPayData result = lvWxPayApi.UnifiedOrder(data);

            if (!result.IsSet("appid") || !result.IsSet("prepay_id") || result.GetValue("prepay_id").ToString() == "")
            {
                throw new Exception("UnifiedOrder response error!");
            }

            unifiedOrderResult = result;
            return(result);
        }
Пример #2
0
        /***
         * 申请退款完整业务流程逻辑
         * @param transaction_id 微信订单号(优先使用)
         * @param out_trade_no 商户订单号
         * @param total_fee 订单总金额
         * @param refund_fee 退款金额
         * @return 退款结果(xml格式)
         */
        public void Run(string transaction_id, string refund_fee, string pvOpenID, string pvPath)
        {
            if (string.IsNullOrEmpty(transaction_id) || string.IsNullOrEmpty(refund_fee) || string.IsNullOrEmpty(pvOpenID))
            {
                return;
            }
            double lvRefund = 0;

            double.TryParse(refund_fee, out lvRefund);
            if (lvRefund <= 0)
            {
                return;
            }
            int lvRefundFee = (int)(lvRefund * 100);

            try
            {
                WxPayData data = new WxPayData();
                ////微信订单号存在的条件下,则已微信订单号为准
                //data.SetValue("transaction_id", transaction_id);
                //微信订单号不存在,才根据商户订单号去退款
                data.SetValue("out_trade_no", transaction_id);
                WxPayApi lvWxPayApi = new WxPayApi();

                data.SetValue("total_fee", lvRefundFee);                         //订单总金额
                data.SetValue("refund_fee", lvRefundFee);                        //退款金额
                data.SetValue("out_refund_no", lvWxPayApi.GenerateOutTradeNo()); //随机生成商户退款单号
                data.SetValue("op_user_id", WxPayConfig.MCHID);                  //操作员,默认为商户号

                WxPayData result = lvWxPayApi.Refund(data, 6, pvPath);           //提交退款申请给API,接收返回数据
            }
            catch (Exception ex)
            {
            }
            return;
        }