Esempio n. 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;
            }
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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\":\"未支付\"}");
            }
        }