Beispiel #1
0
        public void ProcessRequest(HttpContext context)
        {
            TravelAgent.Model.WebInfo webinfo = new TravelAgent.BLL.WebInfo().loadConfig(context.Server.MapPath(ConfigurationManager.AppSettings["WebInfoConfig"].ToString()));
            if (webinfo != null)
            {
                appid      = webinfo.AppID;
                mch_id     = webinfo.Mchid;
                key        = webinfo.Key;
                appsecret  = webinfo.AppSecret;
                notify_url = webinfo.WebDomain + "/wxpay/notify_url.aspx";
            }
            string action = JKRequest.GetQueryString("action");

            switch (action)
            {
            case "unifysign":
                GetUnifySign(context); break;

            case "nativestatic": GetStaticPayQr(context); break;

            case "GetOpenId": GetOpenId(context); break;

            case "GetOrderStatus": GetOrderStatus(context); break;

            case "ver": GetVersion(context); break;
            }
        }
Beispiel #2
0
        UnifyEntities GetUnifyEntities(HttpContext context)
        {
            string        msgid = JKRequest.GetQueryString("msgid");
            UnifyEntities unify = new UnifyEntities
            {
                appid            = appid,
                body             = JKRequest.GetQueryString("body"),
                mch_id           = mch_id,
                nonce_str        = TravelAgent.WxPay.Utils.GetRandom(),
                out_trade_no     = JKRequest.GetQueryString("out_trade_no"),
                notify_url       = notify_url,
                spbill_create_ip = JKRequest.GetIP(),
                trade_type       = JKRequest.GetQueryString("trade_type"),
                total_fee        = JKRequest.GetQueryString("total_fee")
            };

            if (unify.trade_type == "NATIVE")
            {
                unify.product_id = msgid;
            }
            else
            {
                unify.openid = msgid;
            }
            return(unify);
        }
Beispiel #3
0
        void GetOpenId(HttpContext context)
        {
            string code    = JKRequest.GetQueryString("code");
            string retdata = Utils.HttpGet(string.Format("https://api.weixin.qq.com/sns/oauth2/access_token?appid={0}&secret={1}&code={2}&grant_type=authorization_code", appid, appsecret, code));

            //context.Response.Write(retdata);
            JObject jobj   = (JObject)JsonConvert.DeserializeObject(retdata);
            string  openid = jobj.Value <string>("openid");

            //return openid;
            context.Response.Write(openid);
        }
Beispiel #4
0
        void GetStaticPayQr(HttpContext context)
        {
            //string url = GetPayUrl(context);
            //HttpContext.Current.Response.Write(url);

            NativeStatic ns = new NativeStatic()
            {
                appid      = appid,
                mch_id     = mch_id,
                nonce_str  = TravelAgent.WxPay.Utils.GetRandom(),
                product_id = JKRequest.GetQueryString("product_id"),
                time_stamp = Utils.ConvertDateTimeInt(DateTime.Now).ToString()
            };
            string url, sign;

            TravelAgent.WxPay.Utils.GetUnifyUrlXml <NativeStatic>(ns, key, out url, out sign);

            TravelAgent.WxPay.Utils.GetQrCode("weixin://wxpay/bizpayurl?" + url);
        }
Beispiel #5
0
        //从订单查询接口里查询订单支付状态

        void GetOrderStatus(HttpContext context)
        {
            string order_no = JKRequest.GetQueryString("order_no");

            QueryOrderEntities qo = new QueryOrderEntities()
            {
                appid        = appid,
                mch_id       = mch_id,
                out_trade_no = order_no,
                nonce_str    = TravelAgent.WxPay.Utils.GetRandom()
            };

            string   url, sign;
            string   xml         = TravelAgent.WxPay.Utils.GetUnifyUrlXml <QueryOrderEntities>(qo, key, out url, out sign);
            string   data        = Utils.HttpPost("https://api.mch.weixin.qq.com/pay/orderquery", xml);
            XElement doc         = XElement.Parse(data);
            string   result_code = doc.Element("result_code").Value;
            string   return_code = doc.Element("return_code").Value;

            if (result_code == "SUCCESS" && return_code == "SUCCESS")
            {
                string trade_state = doc.Element("trade_state").Value;
                if (trade_state == "SUCCESS")
                {
                    context.Response.Write("{\"flag\":\"true\",\"msg\":\"已支付\"}");
                }
                else
                {
                    context.Response.Write("{\"flag\":\"false\",\"msg\":\"未支付\"}");
                }
            }
            else
            {
                context.Response.Write("{\"flag\":\"false\",\"msg\":\"未支付\"}");
            }
        }
Beispiel #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                TravelAgent.Model.WebInfo webinfo = new TravelAgent.BLL.WebInfo().loadConfig(Server.MapPath(ConfigurationManager.AppSettings["WebInfoConfig"].ToString()));
                if (webinfo != null)
                {
                    appid      = webinfo.AppID;
                    mch_id     = webinfo.Mchid;
                    key        = webinfo.Key;
                    notify_url = webinfo.WebDomain + "/wxpay/notify_url.aspx";
                }
                //Utils.WriteTxt(appid+"-"+mch_id+"-"+key+"-"+notify_url);
                var  nr    = new NativeReceive();
                var  ns    = new NativeSend();
                bool valid = nr.ValidSign(nr, key);
                //Utils.WriteTxt("验证"+valid.ToString());
                if (valid)
                {
                    TravelAgent.Model.Order order = orderBll.GetModelByCode(nr.product_id);
                    if (order == null)
                    {
                        return;
                    }

                    //object r = TravelAgent.WxPay.AccessDbHelper.GetOScalar("select [order_price] from   [wx_order]   where [order_no]='" + nr.product_id + "'");

                    //if (r == null)
                    //{
                    //   // Response.Write("用户名或密码错误");
                    //  //  Response.End();
                    //    return;
                    //}
                    float order_price;
                    order_price = wxpay.Utils.StrToFloat(((order.orderPrice + order.attachPrice + order.subPrice - order.usePoints)).ToString(), 0) * 100;//积分1分兑换1元

                    UnifyEntities ue = new UnifyEntities
                    {
                        appid            = appid,
                        body             = getOrderName(order.lineId, order.orderType),
                        mch_id           = mch_id,
                        nonce_str        = TravelAgent.WxPay.Utils.GetRandom(),
                        notify_url       = notify_url,
                        out_trade_no     = nr.product_id,
                        product_id       = nr.product_id,
                        spbill_create_ip = JKRequest.GetIP(),
                        trade_type       = "NATIVE",
                        total_fee        = order_price.ToString()
                    };
                    string url, sign;
                    string xml = TravelAgent.WxPay.Utils.GetUnifyUrlXml <UnifyEntities>(ue, key, out url, out sign);

                    //Utils.WriteTxt(xml);

                    string       data         = Utils.HttpPost("https://api.mch.weixin.qq.com/pay/unifiedorder", xml);
                    UnifyReceive unifyReceive = new UnifyReceive(data);


                    NativeSend nc = new NativeSend()
                    {
                        appid       = appid,
                        mch_id      = mch_id,
                        nonce_str   = TravelAgent.WxPay.Utils.GetRandom(),
                        prepay_id   = unifyReceive.prepay_id,
                        result_code = "SUCCESS",
                        return_code = "SUCCESS",
                    };
                    string url1, sign1;
                    string xml1 = TravelAgent.WxPay.Utils.GetUnifyUrlXml <NativeSend>(nc, key, out url1, out sign1);
                    Utils.WriteTxt(xml1);
                    Response.Write(xml1);
                }
                else
                {
                    Utils.WriteTxt("签名验证失败");
                    NativeSend nc = new NativeSend()
                    {
                        return_code = "FAIL",
                        return_msg  = "签名验证失败"
                    };
                }
            }
            catch (Exception ee)
            {
                Utils.WriteTxt(ee.ToString());
            }
        }