Beispiel #1
0
        public ActionResult sendredpack()
        {
            // 当前用户的openid
            string strWeixin_OpenID = Request.QueryString["openId"] == null ? "" : Request.QueryString["openId"];

            if (string.IsNullOrEmpty(strWeixin_OpenID))
            {
                return(Content(""));
            }

            PayForWeiXinHelp PayHelp = new PayForWeiXinHelp();
            wxRedPackPackage model   = new wxRedPackPackage();

            //接叐收红包的用户 用户在wxappid下的openid
            model.re_openid = strWeixin_OpenID;
            //付款金额,单位分
            int amount = 20000;

            model.total_amount = amount;
            //最小红包金额,单位分
            model.min_value = amount;
            //最大红包金额,单位分
            model.max_value = amount;
            //调用接口的机器 Ip 地址
            model.client_ip = Request.UserHostAddress;
            //调用方法得到POST到发放红包借口的数据
            string postData = PayHelp.DoDataForPayWeiXin(model);
            string result   = "";

            try
            {
                result = PayHelp.SendRedPack(postData);
            }
            catch (Exception ex)
            {
                //写日志
            }
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(result);
            string jsonResult = JsonConvert.SerializeXmlNode(doc);

            //Response.ContentType = "application/json";
            //Response.Write(jsonResult);

            return(Content(jsonResult));
        }
Beispiel #2
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            PayWeiXin        model   = new PayWeiXin();
            PayForWeiXinHelp PayHelp = new PayForWeiXinHelp();
            string           result  = string.Empty;
            //传入OpenId
            string openId = context.Request.Form["openId"].ToString();
            //传入红包金额(单位分)
            string amount = context.Request.Form["amount"] == null ? "" : context.Request.Form["amount"].ToString();

            //接叐收红包的用户 用户在wxappid下的openid
            model.re_openid = openId;//"oFIYdszuDXVqVCtwZ-yIcbIS262k";
            //付款金额,单位分
            model.total_amount = int.Parse(amount);
            //最小红包金额,单位分
            model.min_value = int.Parse(amount);
            //最大红包金额,单位分
            model.max_value = int.Parse(amount);
            //调用方法
            string postData = PayHelp.DoDataForPayWeiXin(model);

            try
            {
                result = PayHelp.PayForWeiXin(postData);
            }
            catch (Exception ex)
            {
                //写日志
            }
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(result);
            string jsonResult = JsonConvert.SerializeXmlNode(doc);

            context.Response.ContentType = "application/json";
            context.Response.Write(jsonResult);
            context.Response.End();
        }