Ejemplo n.º 1
0
        /**
         * 调用统一下单,获得下单结果
         * @return 统一下单结果
         * @失败时抛异常WxPayException
         */

        public WxPayData GetUnifiedOrderResult(Enroll enroll, Course course)
        {
            //统一下单
            WxPayData data = new WxPayData();

            data.SetValue("body", "优杰学车-在线报名");
            data.SetValue("detail", $"客户于{enroll.UpdateTime.ToString("yyyy-MM-dd HH:mm:ss")}在线报名{course.Name}{enroll.Amount}元."); //商品详情
            data.SetValue("out_trade_no", enroll.OrderNo);
            data.SetValue("total_fee", (Math.Round(enroll.Amount * 100, 0)).ToString());                                          //微信支付提交的金额是不能带小数点的,且是以分为单位,所以我们系统如果是以元为单位要处理下金额,即先乘以100,再去小数点
            data.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));
            data.SetValue("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss"));
            data.SetValue("trade_type", "JSAPI");
            data.SetValue("openid", openid);

            WxPayData result = WxPayApi.UnifiedOrder(data);

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

            unifiedOrderResult = result;
            return(result);
        }