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));
        }