Example #1
0
        /// <summary>
        /// 发送普通红包到指定用户;
        /// https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3
        /// 现金红包需要对于结算周期为 T+1 的商户,需要满足一下2个条件:
        ///       1.入驻满90天,2.连续正常交易30天。其余结算周期的商户无限制
        /// https://pay.weixin.qq.com/index.php/public/product/detail?pid=4
        /// 噗通的是,发放红包需要
        /// </summary>
        /// <param name="userOpenId">用户的Id</param>
        /// <param name="redpacketMoney">红包金额,分为单位;</param>
        /// <param name="orderNo">订单号</param>
        /// <param name="outPaySign"></param>
        /// <param name="senderName">红包发送者名称,例如 全视物联</param>
        /// <param name="actionName">活动名称</param>
        /// <param name="wishstring">红包祝福语</param>
        /// <param name="remark">备注 remark 是 猜越多得越多,快来抢!</param>
        /// <param name="outScene">随机字符串,不长于32位, 由 senparc自动产生 并回传给外部调用方</param>
        /// <param name="outPaySign">签名, 由 senparc产生 并回传给外部调用方</param>
        /// <returns></returns>
        public NormalRedPackResult SendNormalRedPacket(string userOpenId, int redpacketMoney, string orderNo,
                                                       string senderName,
                                                       string actionName,
                                                       string wishstring,
                                                       string remark,
                                                       out string outScene,
                                                       out string outPaySign)
        {
            string tenpayCertPath = @"F:\files\weixinpay_cert\1488937502\api_cert\apiclient_cert.p12"; //微信支付的证书地址;

            return(RedPackApi.SendNormalRedPack(this.Config.AppId, this.Config.MchId,
                                                this.Config.TenPayKey,
                                                tenpayCertPath,
                                                userOpenId,
                                                senderName, //"全视物联",
                                                NetUtil.GetLocalIp(),
                                                redpacketMoney,
                                                wishstring,
                                                actionName,
                                                remark,
                                                out outScene,
                                                out outPaySign,
                                                orderNo,
                                                Senparc.Weixin.TenPay.RedPack_Scene.PRODUCT_2));
        }
Example #2
0
        public void SearchRedPackTest()
        {
            var result = RedPackApi.SearchRedPack(_appId, _mchId, _tenPayKey, _tenPayCertPath, "10000098201411111234567890");

            Console.Write(result);
            Assert.IsNotNull(result);
        }
        /// <summary>
        /// 目前支持向指定微信用户的openid发放指定金额红包
        /// 注意total_amount、min_value、max_value值相同
        /// total_num=1固定
        /// 单个红包金额介于[1.00元,200.00元]之间
        /// </summary>
        /// <returns></returns>
        public ActionResult SendRedPack()
        {
            string nonceStr; //随机字符串
            string paySign;  //签名
            var    sendNormalRedPackResult = RedPackApi.SendNormalRedPack(
                TenPayV3Info.AppId, TenPayV3Info.MchId, TenPayV3Info.Key,
                @"F:\apiclient_cert.p12", //证书物理地址
                "接受收红包的用户的openId",        //接受收红包的用户的openId
                "红包发送者名称",                //红包发送者名称
                Request.UserHostAddress,  //IP
                100,                      //付款金额,单位分
                "红包祝福语",                  //红包祝福语
                "活动名称",                   //活动名称
                "备注信息",                   //备注信息
                out nonceStr,
                out paySign,
                null,                         //场景id(非必填)
                null,                         //活动信息(非必填)
                null                          //资金授权商户号,服务商替特约商户发放时使用(非必填)
                );

            SerializerHelper serializerHelper = new SerializerHelper();

            return(Content(serializerHelper.GetJsonString(sendNormalRedPackResult)));
        }
Example #4
0
        public void SendNormalRedPackTest()
        {
            string nonceStr = "";
            string paySign  = "";
            var    result   = RedPackApi.SendNormalRedPack(_appId, _mchId, _tenPayKey, _tenPayCertPath, _testOpenId, "测试红包发送者", "127.0.0.1",
                                                           100, "祝福", "活动", "备注", out nonceStr, out paySign);

            Console.Write(result);
            Assert.IsNotNull(result);
            Assert.IsNotNull(nonceStr);
            Assert.IsNotNull(paySign);
        }
        public ActionResult SendRedPack(string code)
        {
            var record = SqlFactory.GetSqlhelper().CreateWhere <VoteBonusRecord>()
                         .Where(o => o.AddInfo == code)
                         .Where(o => o.UseDate == null)
                         .FirstOrDefault();

            if (record == null)
            {
                return(Redirect("/MPage/Info.aspx?info=未找到红包信息"));
            }

            var openid = "oI6q_t7v86pILbZKUoFrB-TkovB4";

            openid = Request.Cookies["payopenid"].Value;
            string nonceStr; //随机字符串
            string paySign;  //签名
            var    sendNormalRedPackResult = RedPackApi.SendNormalRedPack(
                appId, mchId, key,
                @"c:\certjsq\apiclient_cert.p12", //证书物理地址
                openid,                           //接受收红包的用户的openId
                "新路桥人家园",                         //红包发送者名称
                Request.UserHostAddress,          //IP
                100,                              //付款金额,单位分
                "感谢投票",                           //红包祝福语
                "新路桥人创业之星评选",                     //活动名称
                "",                               //备注信息
                out nonceStr,
                out paySign,
                null,                         //场景id(非必填)
                null,                         //活动信息(非必填)
                null                          //资金授权商户号,服务商替特约商户发放时使用(非必填)
                );

            if (sendNormalRedPackResult.result_code == "SUCCESS")
            {
                record.UseDate = DateTime.Now;
                SqlFactory.GetSqlhelper().Update(record);
                return(Redirect("/MPage/Info.aspx?icon_type=success&info=您已成功领取红包"));
            }
            else
            {
                return(Redirect("/MPage/Info.aspx?info=" + sendNormalRedPackResult.err_code_des));
            }
            //SerializerHelper serializerHelper = new SerializerHelper();
            //return Content(serializerHelper.GetJsonString(sendNormalRedPackResult));
        }
Example #6
0
        public ActionResult SendBag()
        {
            if (WorkContext.UserLevel <= 0)
            {
                return(PromptView("请先提升您的等级!"));
            }
            Core.BLL.SendBag sendBll = new Core.BLL.SendBag();

            if (WebHelper.IsGet())
            {
                int type  = WebHelper.GetQueryInt("Sendtype", 1);
                int page  = WebHelper.GetQueryInt("page");
                int count = 0;

                List <Core.Model.SendBag> list = sendBll.GetModelList(20, page, " Receiverid=" + WorkContext.Uid + " and status=0 and Sendtype=" + type, "id", out count);
                PageModel    pageModel         = new PageModel(20, page, count);
                SendBagModel model             = new SendBagModel
                {
                    PageModel   = pageModel,
                    SendBagList = list,
                    Sendtype    = type
                };
                return(View(model));
            }
            else
            {
                try
                {
                    lock (this)
                    {
                        WeiXinConfig wxconfig = BMAConfig.WeiXinConfig;
                        int          sendid   = WebHelper.GetFormInt("sendid");
                        List <Core.Model.SendBag> listsendbag = sendBll.GetModelList(" status=0 and id=" + sendid);
                        if (listsendbag.Count > 0 && listsendbag[0].ReceiverID == WorkContext.Uid)
                        {
                            string Noncestr = "";
                            string paysign  = "";
                            try
                            {
                                int bcount = sendBll.GetRecordCount(" status=1 and ReceiverID=" + WorkContext.Uid + " and sendtype=" + WorkContext.UserLevel);
                                if (WorkContext.UserLevel == 1)
                                {
                                    if (bcount >= 3)
                                    {
                                        return(AjaxResult("error", "您领取的红包已达到上限,请先提升您的等级!"));
                                    }
                                }
                                if (WorkContext.UserLevel == 2)
                                {
                                    if (bcount >= 9)
                                    {
                                        return(AjaxResult("error", "您领取的红包已达到上限,请先提升您的等级!"));
                                    }
                                }

                                if (listsendbag[0].IsNotSend == 0)
                                {
                                    NormalRedPackResult nop = RedPackApi.SendNormalRedPack(listsendbag[0].Mchbillno, wxconfig.AppID, wxconfig.Mch_id, wxconfig.PartnerKey, Server.MapPath(wxconfig.SSLCERT_PATH), WorkContext.Openid, "创梦星火", wxconfig.Spbill_create_ip, listsendbag[0].Pice.Value * 100,
                                                                                           "更上一层楼", "创梦帮扶活动", "祝您更上一层楼", out Noncestr, out paysign);

                                    if (nop.err_code_des == "")
                                    {
                                        listsendbag[0].Status   = 1;
                                        listsendbag[0].SendTime = DateTime.Now;
                                        sendBll.Update(listsendbag[0]);
                                        return(AjaxResult("success", "发送成功"));
                                    }
                                    else
                                    {
                                        return(AjaxResult("error", nop.err_code_des));
                                    }
                                }
                                else
                                {
                                    return(AjaxResult("error", "该红包处于冻结状态,暂时无法领取."));
                                }
                            }
                            catch (Exception ex)
                            {
                                return(AjaxResult("error", ex.ToString()));
                            }
                        }
                        else
                        {
                            return(AjaxResult("error", "红包不存在或已发送"));
                        }
                    }
                }
                catch (Exception ex)
                {
                    return(AjaxResult("error", ex.ToString()));
                }
            }
        }