微信HTML5抽奖活动的现实

11 篇文章 0 订阅

从微信跳过来的入口方法

public static void redbag(String code,String state){

if(code!=null){//微信登录
String wxApi = "https://api.weixin.qq.com/sns/oauth2/access_token";
Map<String, String> args = new HashMap<String, String>();
args.put("appid", Constants.APPID);
args.put("secret", Constants.APPSECRET);
args.put("code", code);
args.put("grant_type", "authorization_code");
String wxJson = WS.url(wxApi).setParameters(args).post().getString();
JSONObject jsonObj = JSONObject.fromObject(wxJson);
if(jsonObj!=null&&jsonObj.get("openid")!=null)
{
String openid = jsonObj.getString("openid");
User user = new User();
user.setWxOpenid(openid);
ErrorInfo error = new ErrorInfo();
user.wxlogin(openid, true, error);
render(openid);
}
}
render();

}


/**
* 抢红包算法,返回根据红包活动规则生成的金额JSON格式。 
*/
public static void getredbag(){

int[] moneys = {18,28,38,48,58};
JSONObject obj = new JSONObject();
ErrorInfo error = new ErrorInfo();
User user = User.currUser();
UserBonusInfo userBonusInfo = new UserBonusInfo();
userBonusInfo.userId = user.id;

if(userBonusInfo.queryUserBonusWx()>0)
{
obj.put("money", -1);
obj.put("retMsg", "温馨提示:每人只能抢一个开业红包!");
renderJSON(obj);
}

int bonusID = getRndMoney();
userBonusInfo.bonusId = bonusID;
userBonusInfo.status = UserBonusInfo.STATUS_ENABLE;
Date currentDate = new Date();
userBonusInfo.createTime = currentDate;
userBonusInfo.auditSupervisorId = 1; //超级管理员
userBonusInfo.auditTime = currentDate;
userBonusInfo.isUse = UserBonusInfo.IS_USE_APPROVED;
userBonusInfo.commentMark = "wxhb";
userBonusInfo.suggestion = moneys[bonusID-1]+"";

int ret = userBonusInfo.addUserBonus(7, error);


obj.put("money", 0);
if(ret==0){
String retMsg = "恭喜您:抢到红包"+moneys[bonusID-1]+"元!";
obj.put("money", moneys[bonusID-1]);
obj.put("retMsg", retMsg);
}
renderJSON(obj);
}

/**
* 获取随机出来的红包金额  
* 1、开业现场抢红包活动18元
* 2、开业现场抢红包活动28元
* 3、开业现场抢红包活动38元
* 4、开业现场抢红包活动48元
* 5、开业现场抢红包活动58元
* @return
*/
public static int getRndMoney()
{
Random random = new Random();
int rnd  = Math.abs(random.nextInt())%99+1;
int[] moneys = {18,28,38,48,58};
int i = 0;
if(rnd >97)
i = 4;
else if(rnd>92)
i = 3;
else if(rnd>88)
i = 2;
else if(rnd>70)
i = 1;
else
i = 0 ;
// return moneys[i];
return i+1;
}



VIEW层HTML5



<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
%{
business.User currUser = business.User.currUser();
}%

<title>某网:国内知名银行级投资理财平台</title> 
<meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">
<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 content="-1" http-equiv="Expires">
<meta content="no-cache" http-equiv="Cache-Control">
<meta content="no-cache" http-equiv="Pragma">
<meta content="no" name="wap-font-scale">
<meta content="IE=edge" http-equiv="X-UA-Compatible">
<meta content="webkit|ie-comp|ie-stand" name="renderer">
<script type="text/javascript" src="@{'/public/javascripts/jquery-2.0.js'}"></script>
<script type="text/javascript" src="@{'/public/javascripts/jquery.json-2.4.min.js'}"></script>
<link rel="stylesheet" href="@{'/public/stylesheets/jquery.mobile-1.4.5.min.css'}">
<link rel="stylesheet" type="text/css" href="@{'/public/stylesheets/bootstrap.min.css'}">
<script type="text/javascript" src="@{'/public/javascripts/common.js'}"></script>
<script src="@{'/public/javascripts/jquery.mobile-1.4.5.min.js'}"></script>
<script type="text/javascript" src="@{'/public/javascripts/bootstrap.min.js'}"></script>

</head>
<body>




<!-- 抢红包 -->
<div data-role="page" id="h5index">
 <div data-role="header">
  <h1>某网红包活动</h1>
 </div>

 <div data-role="content">
    #{doLayout /} 
 </div>

 <div data-role="footer" data-position="fixed">
   <div data-role="navbar" >
     <ul>
     #{if currUser == null}
       <li><a href="#reg"  data-transition="slideup" data-icon="plus">注册</a></li>
       <li><a href="#login"  data-transition="slidedown" data-icon="user">登录</a></li>
     #{/if}
     #{else}
      <li><a href="/myredbag" data-icon="shop">我的红包</a></li>
      <li><a href="/active/investInfo" data-icon="heart">投资</a></li>
     #{/else}
     <li><a  href="#redbagrule" data-transition="slide" data-icon="info">活动规则</a></li>
     </ul>
   </div>
 </div>
</div> 

<!-- 活动规则 -->
<div  data-role="popup"  id="redbagrule" data-dismissible=false>
 <div data-role="header">
    <h1>抢红包活动规则</h1>
 </div>

 <div data-role="main" class="ui-content">
 
<p><b>活动规则:</b></p>
<p>1、红包需注册登录某网银账号后方能领取</p>
<p>2、红包适用于某网银平台指定理财产品购买;</p>
<p>3、红包不能转让,每个理财产品仅限使用一个红包;</p>
<p>4、红包可用于再投资,未使用前不可直接提现;</p>
<p>5、红包期限为7天,7天后仍未使用则自动作废。</p>
<p>本活动最终解释权归某网银平台所有。</p>
 </div>

 <div data-role="footer">
   <h1><a href="#" data-rel="back" >我知道了</a></h1>
 </div>
</div> 

<div   data-role="popup"  id="login" >   
 <div data-role="header" style="height: 46px;">
    <h1>用户登录</h1>
    <a href="#h5index" data-icon="back" data-role="button">返回抢红包</a>
 </div>
 <div data-role="main" class="ui-content">
   <form method="post" action="/active/userLogin">
   <div>
     <input type="text" name="userName" id="userName" placeholder="用户名">
     <input type="password" name="password" id="password" placeholder="密码">
     <input type="hidden" name="openid" value="${openid}">
     <button type="submit" data-theme="b">登录</button>
   </div>
</form>  
 </div>
 <div data-role="footer">
   <h1><a href="#reg"  data-transition="slideup" >快速注册</a></h1>
 </div>
</div> 

<div  data-role="popup"  id="reg" >   
 <div data-role="header" style="height: 46px;">
    <h1>快速注册</h1>
    <a href="#h5index" data-icon="back" data-role="button">返回抢红包</a>
 </div>
 <div data-role="main" class="ui-content">
   <form method="post" action="/active/userRegSave">
   <div>
     <input type="text" name="userName" id="userName" placeholder="用户名">
     <input type="password" name="password" id="password" placeholder="密码">
     <input type="password" name="confirmPassword" id="confirmPassword" placeholder="确认密码">
     <input type="hidden" name="openid" value="${openid}">
     <button type="submit" data-theme="b">注册</button>
   </div>
</form>  
 </div>
</div> 


  </body> 
</html>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
2018最新微信微信上墙婚庆会议大屏幕3D签到抽奖摇一摇微信上墙源码。这是我在淘宝上面花了200大洋买的,php版本5.4以上,亲测可用,上墙,抽奖,摇一摇。都可以使用。绝对没有问题。之前在网上花了2天时间也找了一些类似的,有免费下载的,也有包括在csdn上面用5个资源分下载类似的,发现都不能用,至少我在本地或有服务器上都没有调试成功,看了一下他们的代码,发现代码用的是公众号帐号和密码,来模拟微信登陆来获取用户信息。微信已经在2016年就已经停止模似登陆了,登陆微信公众号,必须要扫描后,管理员确认后才可登陆。所以,那些代码都不能用。有些有csdn上传的这些代码基本上不能用(可能2015年前可以用,但是现在不能用),感觉太不负责任了,都是骗积分的。当时因为公司年会要弄个微信上墙及现在抽奖活动,找这个代码也很辛苦,相信大家也一样辛苦,所以,把代码放出来,供大家下载学习使用。这个代码,我是在淘宝上买的,本身内置了第三方的微信公众号授权,所以,如果你的公众号没有微信认证也可以用,直接扫码就可以发送微信上墙弹幕,不会出现第三方公众号信息。如果你的微信公众号认证了,就用自己的,后台可以配置,填写你的公众号appid和appsecret即可。好了,不多说了,大家下 载使用,如果不能用,我退积分。不清楚的,大家可以在评论区留言。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值