用c#开发微信 (16) 微活动 2 刮刮卡
生活随笔
收集整理的這篇文章主要介紹了
用c#开发微信 (16) 微活动 2 刮刮卡
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
微信營銷是一種新型的營銷模式,由于微信更重視用戶之間的互動(dòng),故而這種營銷推廣不不能盲目地套用微博營銷的單純大量廣告推送方式。這種方式在微信營銷中的效果非常差,會(huì)令用戶反感,繼而取消去企業(yè)或商家的微信公眾賬號(hào)關(guān)注。對(duì)于企業(yè)來說,做微信推廣重要的一個(gè)方面就是提高用戶和公眾賬號(hào)之間的黏度,而微信刮刮卡就是其中最為常見的活動(dòng)。
下面詳細(xì)介紹:
一、使用
1. 新建
?
2. 獎(jiǎng)項(xiàng)設(shè)置
?
3. 測(cè)試
保存后,給公眾號(hào)發(fā)一個(gè)“刮刮卡”的消息, 就會(huì)收到刮刮卡的內(nèi)容,進(jìn)入活動(dòng)后,就可以刮獎(jiǎng)了
?
?
?
????
?
二、實(shí)現(xiàn)
1. 頁面
1.1 前臺(tái)代碼
<head id="Head1" runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta content="微布斯、微信營銷、微信代運(yùn)營、微信定制開發(fā)、微信托管、微網(wǎng)站、微商城、微營銷" name="Keywords"> <meta content="微布斯,國內(nèi)最大的微信公眾智能服務(wù)平臺(tái),微布斯八大微體系:微菜單、微官網(wǎng)、微會(huì)員、微活動(dòng)、微商城、微推送、微服務(wù)、微統(tǒng)計(jì),企業(yè)微營銷必備。" name="Description"> <meta name="viewport" content=" initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="apple-mobile-web-app-capable" content="yes"> <meta name="apple-mobile-web-app-status-bar-style" content="black"> <meta name="format-detection" content="telephone=no"> <meta name="description" content="刮刮卡"> <title>刮刮卡</title> <link rel="stylesheet" type="text/css" href="css/activity_style.css" media="all" /> <script type="text/javascript" src="js/zepto.js"></script> <script type="text/javascript" src="js/alert.js"></script> <script type="text/javascript" src="../../scripts/jquery/jquery-1.10.2.min.js"></script> <script type="text/javascript" src="../../scripts/jquery/jquery.query.js"></script> <script src="js/wScratchPad.js"></script> </head> <body data-role="page" class="activity-scratch-card-winning"> <%if (ggkAction != null) { %> ? <script type="text/javascript"> function loading(canvas, options) { this.canvas = canvas; if (options) { this.radius = options.radius || 12; this.circleLineWidth = options.circleLineWidth || 4; this.circleColor = options.circleColor || 'lightgray'; this.moveArcColor = options.moveArcColor || 'gray'; } else { this.radius = 12; this.circelLineWidth = 4; this.circleColor = 'lightgray'; this.moveArcColor = 'gray'; } } loading.prototype = { show: function () { var canvas = this.canvas; if (!canvas.getContext) return; if (canvas.__loading) return; canvas.__loading = this; var ctx = canvas.getContext('2d'); var radius = this.radius; var me = this; var rotatorAngle = Math.PI * 1.5; var step = Math.PI / 6; canvas.loadingInterval = setInterval(function () { ctx.clearRect(0, 0, canvas.width, canvas.height); var lineWidth = me.circleLineWidth; var center = { x: canvas.width / 2, y: canvas.height / 2 }; ? ctx.beginPath(); ctx.lineWidth = lineWidth; ctx.strokeStyle = me.circleColor; ctx.arc(center.x, center.y + 20, radius, 0, Math.PI * 2); ctx.closePath(); ctx.stroke(); //在圓圈上面畫小圓 ctx.beginPath(); ctx.strokeStyle = me.moveArcColor; ctx.arc(center.x, center.y + 20, radius, rotatorAngle, rotatorAngle + Math.PI * .45); ctx.stroke(); rotatorAngle += step; ? }, 100); }, hide: function () { var canvas = this.canvas; canvas.__loading = false; if (canvas.loadingInterval) { window.clearInterval(canvas.loadingInterval); } var ctx = canvas.getContext('2d'); if (ctx) ctx.clearRect(0, 0, canvas.width, canvas.height); } }; </script> <form id="form1" runat="server"> <asp:HiddenField ID="hidStatus" runat="server" EnableViewState="false" /> <asp:HiddenField ID="hidErrInfo" runat="server" EnableViewState="false" /> <asp:HiddenField ID="hidAwardId" runat="server" EnableViewState="false" Value="0" /> <div class="main"> <div class="cover" id="jiangqu"> <img src="images/activity-scratch-card-bannerbg.png"> <div id="prize"> <asp:Literal ID="litPrize" runat="server" EnableViewState="false" Text="謝謝參與"></asp:Literal> </div> <div id="scratchpad"></div> </div> ? <div class="content"> ? <div id="zjl" style="display: none" class="boxcontent boxwhite"> <div class="box"> <div class="title-red"><span>恭喜你中獎(jiǎng)了</span></div> <div class="Detail"> <p>你中了:<span class="red"><asp:Literal ID="litJiangPing" runat="server" EnableViewState="false"></asp:Literal></span></p> <p>兌獎(jiǎng)SN碼:<span class="red" id="sncode"><asp:Literal ID="litSnCode" runat="server" EnableViewState="false"></asp:Literal></span></p> <p class="red"> <asp:Literal ID="litContentInfo" runat="server" EnableViewState="false"></asp:Literal> </p> <p> <input name="" class="px" id="tel" value="" type="text" autocomplete="off" placeholder="用戶請(qǐng)輸入您的手機(jī)號(hào)"> </p> <asp:Literal ID="litPwd" runat="server" EnableViewState="false" Text=""></asp:Literal> <%-- <p> <input name="" class="px" id="parssword" type="password" value="" placeholder="商家輸入兌獎(jiǎng)密碼"> </p>--%> <p> <input class="pxbtn" name="提 交" id="save-btn" type="button" value="用戶提交"> </p> </div> ? </div> ? </div> ? <div class="boxcontent boxwhite" id="result" style="display: none;"> <div class="box"> <div class="title-orange"><span>恭喜你中獎(jiǎng)了</span></div> <div class="Detail"> <p>你中了:<span class="red"><asp:Literal ID="litJp" runat="server" EnableViewState="false" Text=""></asp:Literal></span></p> <p>兌獎(jiǎng)sn碼為:<span class="red"><asp:Literal ID="litSNM" runat="server" EnableViewState="false"></asp:Literal></span></p> <p class="red"><asp:Literal ID="litLQStatus" runat="server" EnableViewState="false" Text=""></asp:Literal></p> </div> ? ? </div> </div> ? <div class="boxcontent boxwhite"> <div class="box"> <div class="title-red"><span>獎(jiǎng)項(xiàng)設(shè)置:</span></div> <div class="Detail"> <asp:Literal ID="litJiangXing" runat="server" EnableViewState="false"></asp:Literal> ? </div> </div> </div> <div class="boxcontent boxwhite"> <div class="box"> <div class="title-red">活動(dòng)說明:</div> <div class="Detail"> <p class="red"> 本次活動(dòng)總共可以刮<asp:Literal ID="litTTTimes" runat="server" EnableViewState="false"></asp:Literal> 次, 你已經(jīng)刮了 <asp:Literal ID="litRemainTimes" runat="server" EnableViewState="false" Text="0"></asp:Literal> 次,機(jī)會(huì)如果沒用完重新進(jìn)入本頁面可以再刮! </p> <p> <asp:Literal ID="litRemark" runat="server" EnableViewState="false"></asp:Literal> </p> ? </div> </div> </div> </div> <div style="clear: both;"></div> </div> ? ? <script type="text/javascript"> var wid = $.query.get("wid"); var aid = $.query.get("aid"); var thisurl = document.URL; var status = $("#hidStatus").val(); var showInfo = $("#hidErrInfo").val(); var openid = $.query.get("openid"); var zjl = false;//沒中獎(jiǎng)為false中獎(jiǎng)為true ? if (status == "-1") { window.location.href = "end.aspx?openid=" + openid + "&wid=" + wid + "&aid=" + aid; } else if (status == "0") { alert(showInfo); ? } else if (status == "2") { zjl = true; } else if (status == "100") { $("#zjl").show(); $("#jiangqu").hide(); } else if (status == "110") { $("#result").show(); $("#jiangqu").hide(); ? } ? var num = 0; var goon = true; $(function () { ? var useragent = window.navigator.userAgent.toLowerCase(); $("#scratchpad").wScratchPad({ width: 150, height: 40, color: "#a9a9a7", scratchMove: function () { num++; if (zjl && num > 30 && goon) { //$("#zjl").fadeIn(); goon = false; $("#zjl").slideToggle(500); //$("#outercont").slideUp(500) } ? if (useragent.indexOf("android 4") > 0) { if ($("#scratchpad").css("color").indexOf("51") > 0) { $("#scratchpad").css("color", "rgb(50,50,50)"); } else if ($("#scratchpad").css("color").indexOf("50") > 0) { $("#scratchpad").css("color", "rgb(51,51,51)"); } } ? } }); ? }); ? $("#save-btn").bind("click", function () { ? ? var btn = $(this); var tel = $("#tel").val(); var pwd = ""; var hidAwardId = $("#hidAwardId").val(); ? if ($("#parssword").length > 0 && $.trim($("#parssword").val()) == "") { alert("請(qǐng)輸入兌獎(jiǎng)密碼!"); return } if ($("#parssword").length > 0) { pwd = $("#parssword").val(); } ? ? if ($.trim(tel) == "") { alert("請(qǐng)輸入手機(jī)號(hào)!"); return } var rad = Math.random(); ? var submitData = { id: hidAwardId, aid: aid, pwd: pwd, snumber: $("#sncode").text(), tel: tel, rad: rad, openid: openid }; $.post('ggkAct.ashx?myact=update', submitData, function (data) { if (data.success == "1") { alert("提交成功!"); $("#result").slideToggle(500); $("#zjl").slideToggle(500); ? } else { alert(data.msg); } }, "json") }); ? ? document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() { window.shareData = { "imgUrl": thisurl, "timeLineLink": thisurl + "&is_share=1", "sendFriendLink": thisurl + "&is_share=1", "weiboLink": thisurl + "&is_share=1", "tTitle": "<%=ggkAction.actName%>", "tContent": "<%=ggkAction.actContent%>", "fTitle": "<%=ggkAction.actName%>", "fContent": "<%=ggkAction.actContent%>", "wContent": "<%=ggkAction.actContent%>" }; // 發(fā)送給好友 WeixinJSBridge.on('menu:share:appmessage', function (argv) { WeixinJSBridge.invoke('sendAppMessage', { "img_url": window.shareData.imgUrl, "img_width": "640", "img_height": "640", "link": window.shareData.sendFriendLink, "desc": window.shareData.fContent, "title": window.shareData.fTitle }, function (res) { _report('send_msg', res.err_msg); }) }); ? // 分享到朋友圈 WeixinJSBridge.on('menu:share:timeline', function (argv) { WeixinJSBridge.invoke('shareTimeline', { "img_url": window.shareData.imgUrl, "img_width": "640", "img_height": "640", "link": window.shareData.timeLineLink, "desc": window.shareData.tContent, "title": window.shareData.tTitle }, function (res) { _report('timeline', res.err_msg); }); }); ? // 分享到微博 WeixinJSBridge.on('menu:share:weibo', function (argv) { WeixinJSBridge.invoke('shareWeibo', { "content": window.shareData.wContent, "url": window.shareData.weiboLink, }, function (res) { _report('weibo', res.err_msg); }); }); }, false) </script> ? </form> <%} else {%> <div class="main"> <div class="content"> <div class="boxcontent boxwhite"> <div class="box"> <div class="title-red"><span>出現(xiàn)異常:</span></div> <div class="Detail"> <%=errorInfo %> ? </div> </div> </div> ? </div> </div> ? ? <%} %> ? <div style="display: none">?微布斯科技提供qq 121285904 www.webus.cn</div> </body> </html>?
這里用到了wScratchPad.js, wScratchPad是jQuery上的一個(gè)插件,它能模擬出刮的行為,使你能“擦去”一層覆蓋物,這層覆蓋物既可是一個(gè)圖片,也可以是某種顏色涂層。
官方網(wǎng)址為 http://wscratchpad.websanova.com/
?
1.2? 頁面加載
public Model.wx_ggkActionInfo ggkAction = new Model.wx_ggkActionInfo(); BLL.wx_ggkActionInfo actbll = new BLL.wx_ggkActionInfo(); BLL.wx_ggkAwardItem itemBll = new BLL.wx_ggkAwardItem(); BLL.wx_ggkAwardUser ubll = new BLL.wx_ggkAwardUser(); BLL.wx_ggkUsersTemp utbll = new BLL.wx_ggkUsersTemp(); string NoAward = "謝謝參與"; protected string errorInfo = ""; protected void Page_Load(object sender, EventArgs e) { OnlyWeiXinLook(); if (!IsPostBack) { int aid = MyCommFun.RequestInt("aid", 0); int wid = MyCommFun.RequestInt("wid", 0); string openid = MyCommFun.RequestOpenid(); if (aid == 0 || wid == 0 || openid.Trim() == "" | openid.Trim() == "loseopenid") { errorInfo="訪問的參數(shù)有問題!"; ggkAction = null; return; } ? bindData(aid, openid); } }?
1.3 綁定頁面上的基本信息
private void bindData(int id, string openid) { #region 活動(dòng)詳情 ggkAction = actbll.GetModel(id); if (ggkAction == null) { errorInfo = "該活動(dòng)不存在!"; return; } if (ggkAction.endDate <= DateTime.Now) { //說明活動(dòng)已經(jīng)結(jié)束 errorInfo = "活動(dòng)已結(jié)束!"; ggkAction = null; return; } else if (ggkAction.beginDate > DateTime.Now) { //活動(dòng)未開始 errorInfo = "活動(dòng)尚未開始!<br/>活動(dòng)時(shí)間為:" + ggkAction.beginDate.ToString() + "到" + ggkAction.endDate.ToString(); ggkAction = null; return; } this.Title = ggkAction.actName; List<Model.wx_ggkAwardItem> itemlist = itemBll.GetModelList("actId="+id); StringBuilder sb = new StringBuilder(""); Model.wx_ggkAwardItem item = new Model.wx_ggkAwardItem(); int ttJpNum = 0;//實(shí)際獎(jiǎng)品數(shù)量 for (int i = 0; i < itemlist.Count; i++) { item = itemlist[i]; sb.Append("<p>" +item.jxName + ":" + item.jpName + " 數(shù)量:" + item.jpNum + "</p>"); ttJpNum += item.jpRealNum.Value; } ? if (ggkAction.djPwd.Trim().Length > 0) { litPwd.Text = " <p> <input name=\"\" class=\"px\" id=\"parssword\" type=\"password\" value=\"\" placeholder=\"商家輸入兌獎(jiǎng)密碼\"></p>"; } ? litJiangXing.Text = sb.ToString(); ? litRemark.Text = ggkAction.brief; litContentInfo.Text = ggkAction.contractInfo; litTTTimes.Text = ggkAction.personMaxTimes == null ? "0" : ggkAction.personMaxTimes.Value.ToString(); ? #endregion ? lock (this) { ProcZJ(ttJpNum, id, openid, itemlist); } }?
1.4 處理中獎(jiǎng)信息
private void ProcZJ(int ttJpNum, int id, string openid, List<Model.wx_ggkAwardItem> itemlist) { BLL.ggkProc gproc = new BLL.ggkProc(); #region 判斷 Model.wx_ggkAwardUser awardUser = ubll.getZJinfoByOpenid(id, openid); litRemainTimes.Text = gproc.personCJTimes(openid, id).ToString(); if (awardUser != null && awardUser.id > 0) { //說明已經(jīng)中獎(jiǎng)了 ? litPrize.Text = awardUser.jxName; ? hidAwardId.Value = awardUser.id.ToString(); if (awardUser.uTel != null && awardUser.uTel.Trim() != "") { //說明已經(jīng)提交成功了 hidStatus.Value = "110"; hidErrInfo.Value = "您已中過獎(jiǎng)了,歡迎下次再來!"; litJp.Text = awardUser.jxName + " " + awardUser.jpName; litSNM.Text = awardUser.sn; if (awardUser.hasLingQu) { litLQStatus.Text = "你已經(jīng)兌獎(jiǎng)成功,本SN碼自定作廢!"; } else { litLQStatus.Text = ggkAction.contractInfo; } } else { //中獎(jiǎng)了,但是未提交 hidStatus.Value = "100"; hidErrInfo.Value = "您已中獎(jiǎng),請(qǐng)?zhí)峤?#xff01;"; litJiangPing.Text = awardUser.jpName; litSnCode.Text = awardUser.sn; ? litJp.Text = awardUser.jxName + " " + awardUser.jpName; litSNM.Text = awardUser.sn; ? } return; } ? ? int dayMaxTimes = ggkAction.dayMaxTimes == null ? 0 : ggkAction.dayMaxTimes.Value; int perMaxTimes = ggkAction.personMaxTimes == null ? 0 : ggkAction.personMaxTimes.Value; //判斷每人最大抽獎(jiǎng)次數(shù),是否超過了 if (gproc.personCJTimes(openid, id) >= ggkAction.personMaxTimes) { hidStatus.Value = "0"; hidErrInfo.Value = "您已抽過獎(jiǎng)了,歡迎下次再來!"; return; } int RemainTime = 0; if (gproc.isTodayOverSum(id, openid, dayMaxTimes, out RemainTime)) { hidStatus.Value = "0"; hidErrInfo.Value = "每人每天只有" + dayMaxTimes.ToString() + "次抽獎(jiǎng)機(jī)會(huì)。"; litRemainTimes.Text = RemainTime.ToString(); return; } litRemainTimes.Text = RemainTime.ToString(); ? #endregion ? #region 計(jì)算中獎(jiǎng)信息 ? /// 處理是否中獎(jiǎng) /// hidStatus 狀態(tài)為-1:不能抽獎(jiǎng),直接跳轉(zhuǎn)到end.aspx頁面; /// 0:抽獎(jiǎng)次數(shù)超過設(shè)置的最高次數(shù); /// 1:還可以繼續(xù)抽獎(jiǎng); /// 2:中獎(jiǎng)了; IList<Model.wx_ggkAwardUser> auserlist = ubll.getHasZJList(id);//已經(jīng)中獎(jiǎng)的人列表 int ZhongJiangNum = 0; if (auserlist != null) { ZhongJiangNum = auserlist.Count; //已經(jīng)中獎(jiǎng)的人數(shù) } int syZjNum = ttJpNum - ZhongJiangNum; //剩余的獎(jiǎng)品數(shù)量 if (syZjNum <= 0) { //說明已經(jīng)沒有獎(jiǎng)品了 hidStatus.Value = "1"; hidErrInfo.Value = ggkAction.cfcjhf; litPrize.Text = NoAward; return; } ggkAction.personNum = MyCommFun.Obj2Int(ggkAction.personNum, 1); ggkAction.personMaxTimes = MyCommFun.Obj2Int(ggkAction.personMaxTimes, 1); int fenmo = ggkAction.personNum.Value * ggkAction.personMaxTimes.Value; ? Random rd = new Random((int)DateTime.Now.Ticks); int radNum = rd.Next(0, fenmo);//從0到fenmo里隨機(jī)出一個(gè)值 if (radNum < syZjNum) { //中獎(jiǎng)了,再從剩余獎(jiǎng)品里抽取一個(gè)獎(jiǎng)品 Model.wx_ggkAwardItem dajiang = gproc.getZJItem(itemlist, auserlist); if (dajiang != null) { //這是中的中獎(jiǎng)了 string snumber = gproc.Get_snumber(id); int uId = ubll.Add(id, "", "", openid, dajiang.jxName, dajiang.jpName, snumber); hidStatus.Value = "2"; hidErrInfo.Value = "恭喜你中獎(jiǎng)了!"; litPrize.Text = dajiang.jxName; litJiangPing.Text = dajiang.jpName; hidAwardId.Value = uId.ToString(); litSnCode.Text = snumber; ? litJp.Text = dajiang.jxName + " " + dajiang.jpName; litSNM.Text = snumber; return; } else { //獎(jiǎng)品已經(jīng)全部中完了 hidStatus.Value = "1"; hidErrInfo.Value = ggkAction.cfcjhf; litPrize.Text = NoAward; return; } ? } else { //這個(gè)條件說明:未中獎(jiǎng) //拋出未中獎(jiǎng)的數(shù)據(jù) hidStatus.Value = "1"; hidErrInfo.Value = ggkAction.cfcjhf; litPrize.Text = NoAward; } ? ? ? ? #endregion }2. 實(shí)現(xiàn)提交手機(jī)的邏輯
public class ggkAct : IHttpHandler { ? public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/json"; string _action = MyCommFun.QueryString("myact"); string openid = MyCommFun.RequestOpenid(); //得到微信用戶的openid if (_action == "update") { try { #region 提交手機(jī) /// 提交手機(jī)號(hào)碼 string tel = MyCommFun.QueryString("tel"); string pwd = MyCommFun.QueryString("pwd"); string snumber = MyCommFun.QueryString("snumber"); int id = MyCommFun.RequestInt("id"); int aid = MyCommFun.RequestInt("aid"); if (aid==0 || id == 0 || snumber == "" || tel == "") { context.Response.Write("{\"msg\":\"提交出現(xiàn)異常!!\",\"success\":\"0\"}"); return; } BLL.wx_ggkActionInfo actBll = new BLL.wx_ggkActionInfo(); if (pwd.Trim().Length>0 &&(!actBll.ExistsPwd(aid, pwd))) { context.Response.Write("{\"msg\":\"商家兌換密碼錯(cuò)誤!!\",\"success\":\"0\"}"); return; } ? ? BLL.wx_ggkAwardUser ubll = new BLL.wx_ggkAwardUser(); Model.wx_ggkAwardUser model = ubll.GetModel(id); if (model == null) { context.Response.Write("{\"msg\":\"提交出現(xiàn)異常2!!\",\"success\":\"0\"}"); return; } model.uTel = tel; if (pwd.Trim().Length > 0) { model.hasLingQu = true; } else { model.hasLingQu = false; } ubll.Update(model); ? context.Response.Write("{\"msg\":\"提交成功!\",\"success\":\"1\"}"); return; #endregion ? } catch { context.Response.Write("{\"msg\":\"提交出現(xiàn)異常!!\",\"success\":\"0\"}"); ? return; } ? } } ? public bool IsReusable { get { return false; } } }?
?
用c#開發(fā)微信 系列匯總
轉(zhuǎn)載于:https://www.cnblogs.com/fengwenit/p/4568008.html
總結(jié)
以上是生活随笔為你收集整理的用c#开发微信 (16) 微活动 2 刮刮卡的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LeetCode:922. 按奇偶排序数
- 下一篇: C#学习笔记二(函数高级参数)