微信分享

<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>

var shareTitle = $("#shareTitle").val();

var shareDetail = $("#shareDetail").val();
var shareImg = $("#shareImg").val();
$.ajax({
type: "GET",
url: "${basePath}/oneMoneyShop/WxShareConfig",
async: true,
dataType: "json",
data: {
"locationUrl": location.href
},
success: function(config) {
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: config.appId, // 必填,公众号的唯一标识
timestamp: config.timestamp, // 必填,生成签名的时间戳
nonceStr: config.nonceStr, // 必填,生成签名的随机串
signature: config.signature, // 必填,签名,见附录1
jsApiList: ['onMenuShareAppMessage', 'onMenuShareTimeline']
// 必填,需要使用的JS接口列表,所有JS接口列表见附录2
});
wx.ready(function() {
//分享朋友
wx.onMenuShareAppMessage({
title: shareTitle, // 分享标题
desc: shareDetail, // 分享描述
link: '${url}', // 分享链接
imgUrl: 'http://${systemHttp}${basePath}' + shareImg, // 分享图标
trigger: function(res) {


},
success: function() {
// 用户确认分享后执行的回调函数
$(".share").hide();
},
cancel: function() {
// 用户取消分享后执行的回调函数
//alert("分享失败");
$(".shibai").css({
"display": "block"
})
}
});
//分享朋友圈
wx.onMenuShareTimeline({
title: shareTitle, // 分享标题
link: '${url}', // 分享链接
imgUrl: 'http://${systemHttp}${basePath}' + shareImg, // 分享图标
success: function() {
//alert("分享成功");
$(".chnegg").css({
"display": "block"
})
},
cancel: function() {
// 用户取消分享后执行的回调函数
//alert("分享失败");
$(".shibai").css({
"display": "block"
})
}
});
});
}

});


//进入分享页面的时候需要将url传递给前端

/**
* 朋友帮砍价链接 配置文件中的系统名称 PropKit.use("system.properties").get("systemname")
* Jfinal获取项目名称不需要配置JFinal.me().getContextPath()
*/
String url = "http://" + PropKit.use("system.properties").get("http") + JFinal.me().getContextPath()
+ "/oneMoneyShop/goFriendRedirect?oneMoneyWxUserId=" + oneMoneyWxUserId +"&oneMoneyId=" + oneMoneyId

+ "&sellerNumberId=" + sellerNumberId+ "&qrcode=" + qrcode;


/**
* 重定向
*/
public void goFriendRedirect(){
String sellerPublicNumberId = getPara("sellerNumberId");
SellerPublicNumber spn = SellerPublicNumber.dao.findById(sellerPublicNumberId);
String url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + spn.getAppId()
+ "&redirect_uri=http%3a%2f%2f" + PropKit.use("system.properties").get("http")
+ JFinal.me().getContextPath() + "%2foneMoneyShop%2ffriendRedirect%3foneMoneyWxUserId%3d" + getPara("oneMoneyWxUserId")
+ "%26oneMoneyId%3d" + getPara("oneMoneyId") + "%26appid%3d" + spn.getAppId() + "%26qrcode%3d" + getPara("qrcode")
+ "&response_type=code&scope=snsapi_userinfo&state=wx&connect_redirect=1#wechat_redirect";
redirect(url);
}


/**
* 重定向 1.下一步需要获取openid,此处从新进入页面,需要授权
*/
public void friendRedirect() {
String oneMoneyWxUserId = getPara("oneMoneyWxUserId");
log.error("oneMoneyWxUserId***>"+oneMoneyWxUserId);
String oneMoneyId = getPara("oneMoneyId");
String getOneMoneyShop = PropKit.use("database.properties").get("getOneMoneyShop");
OneMoneyShop oneMoneyShop = OneMoneyShop.dao.findFirst(getOneMoneyShop,oneMoneyId);
OneMoneyWxUser oneMoneyWxUser = OneMoneyWxUser.dao.findById(oneMoneyWxUserId);
String belongPublicNumberId = oneMoneyWxUser.getBelongPublicNumberId();
String sq="select * from TB_ONE_MONEY_PRIZE where ONE_MONEY_ID = ? ";
OneMoneyPrize oneMoneyPrize = OneMoneyPrize.dao.findFirst(sq,oneMoneyId);
SellerPublicNumber spn = SellerPublicNumber.dao.findById(belongPublicNumberId);
ApiConfigKit.putApiConfig(WxConfigUitils.getApiConfig(spn.getToKen(), spn.getAppId(), spn.getAppSecret()));
String openid = getOpenid(spn);
String qrcode = getPara("qrcode");
String sql="select * from TB_ONE_MONEY_GROUP_WXUSER where ONEMONEY_WXUSER_ID = ? and CREATER != ? ";
List<OneMoneyGroupWxUser> groupWxUserList = OneMoneyGroupWxUser.dao.find(sql,oneMoneyWxUserId,"1");
String sql1="select * from TB_ONE_MONEY_GROUP_WXUSER where ONEMONEY_WXUSER_ID = ? and CREATER = ? ";
OneMoneyGroupWxUser oneMoneyGroupWxUser = OneMoneyGroupWxUser.dao.findFirst(sql1,oneMoneyWxUserId,"1");
//查询group整个组团的人数
int joinNum= groupWxUserList.size()+1;
//查询中奖人
String sq1="select * from TB_ONE_MONEY_GROUP_WXUSER where ONEMONEY_WXUSER_ID = ? and STATE = ? ";
OneMoneyGroupWxUser winGroupWxUser = OneMoneyGroupWxUser.dao.findFirst(sq1,oneMoneyWxUserId,"1");
//WxUserInfo wxuser = WxConfigUitils.getWxConfigUitils().getPublicUser(getAccessToken(), openid);
//这是自己进自己分享出去的页面
if(oneMoneyWxUser.getOpenId().equals(openid)){
String url = "http://" + PropKit.use("system.properties").get("http") + JFinal.me().getContextPath()
+ "/oneMoneyShop/goFriendRedirect?oneMoneyWxUserId=" + oneMoneyWxUserId +"&oneMoneyId=" + oneMoneyId
+ "&sellerNumberId=" + belongPublicNumberId+ "&qrcode=" + qrcode;
String mywin="";
OneMoneyWxUserWinning oneMoneyWxUserWinning=null;
if(winGroupWxUser!=null){
//中奖人的openID 
String openId2 = winGroupWxUser.getOpenId();
//查询出中奖记录
String s3="select * from TB_ONEMONEY_WXUSER_WINNING where ONEMONEY_WXUSER_ID = ? and OPENID = ? ";
oneMoneyWxUserWinning = OneMoneyWxUserWinning.dao.findFirst(s3,oneMoneyWxUserId,openid);
if(oneMoneyWxUser.getOpenId().equals(openId2)){
//自己中奖
mywin="1";
}else{
//别人中奖
mywin="0";
}
}
int allPay=0;
boolean result=false;
log.error("groupWxUserList****>"+groupWxUserList);
//0未支付 1支付
for (OneMoneyGroupWxUser o : groupWxUserList) {
if(o.getPayState().equals("1")){
allPay+=1;
}
}
if(allPay==groupWxUserList.size()){
result=true;
}
log.error("allPay****>"+allPay+"***groupWxUserList.size()>"+groupWxUserList.size());
setAttr("allPay", result);
setAttr("mywin", mywin);
setAttr("oneMoneyWxUserWinning", oneMoneyWxUserWinning);
setAttr("url", url);
// 如果是自己点击进来不需要操作
setAttr("joinNum", joinNum);
setAttr("winGroupWxUser", winGroupWxUser);
setAttr("qrcode", qrcode);
setAttr("sellerPublicNumber", spn);
setAttr("sellerNumberId", belongPublicNumberId);
setAttr("sellerPublicNumber", spn);
setAttr("oneMoneyGroupWxUser", oneMoneyGroupWxUser);
setAttr("groupWxUserList", groupWxUserList);
setAttr("oneMoneyShop", oneMoneyShop);
setAttr("oneMoneyPrize", oneMoneyPrize);
setAttr("oneMoneyWxUser", oneMoneyWxUser);
// 判断是否属于活动时间内
Date endDate = DateUitils.strToDateYMD(oneMoneyShop.getEndTime());
// 判断当前时间是否大于活动结束时间 返回true表示大于当前时间,代表活动未结束
boolean isEnd = DateUitils.isDateBefore(endDate);
setAttr("isEnd", isEnd);
render("/oneMoneyShop/oneMoneyShop-Invitation.html");
}
//这是别人进来帮忙一元购的页面
else{
//别人进来
//根据openID和ONEMONEY_WXUSER_ID判断该用户是否已经加入到了该一元购活动
//0 没有满 1满了
String fulled="0";
//0 代表 该用户还没有参加该活动的组团   1 代表已经参加了
String joined="0";
//支付状态 0未支付 1支付 2支付中
String payState="0";
String s="select * from TB_ONE_MONEY_GROUP_WXUSER where ONEMONEY_WXUSER_ID = ? and OPENID = ? ";
OneMoneyGroupWxUser groupWxUser = OneMoneyGroupWxUser.dao.findFirst(s,oneMoneyWxUserId,openid);
log.error("查找支付状态  ********groupWxUser>"+groupWxUser);
String s5="select * from TB_ONE_MONEY_GROUP_WXUSER where ONEMONEY_WXUSER_ID = ?";
List<OneMoneyGroupWxUser> list = OneMoneyGroupWxUser.dao.find(s5,oneMoneyWxUserId);
//开奖人数
String openPrizeNumber = oneMoneyShop.getOpenPrizeNumber();
int parseInt = Integer.parseInt(openPrizeNumber);
if(list.size()<parseInt){
log.error("没有满");
//没有满
fulled="0";
if(groupWxUser==null){
//0 代表 该用户还没有参加该活动的组团
joined="0";
//没有参加肯定没有支付了
payState="0";
}else{
//1 代表已经参加了
joined="1";
log.error("没有满  代表已经参加了");
//判断支付没有  0未支付 1支付
String state = groupWxUser.getPayState();
if(state.equals("0")||state.equals("2")){
payState="0";
}else{
payState="1";
}
}
}else{
//满了
fulled="1";
log.error("满了 ");
if(groupWxUser==null){
//0 代表 该用户还没有参加该活动的组团
joined="0";
payState="0";
}else{
//1 代表已经参加了
joined="1";
log.error("满了 1 代表已经参加了  ");
//判断支付没有  0未支付 1支付
String state = groupWxUser.getPayState();
log.error("满了 1 代表已经参加了  state>"+state);
if(state.equals("0")||state.equals("2")){
payState="0";
}else{
payState="1";
}
}
}
// 0未支付 1支付
setAttr("payState", payState);
log.error("支付状态  ********0未支付 1支付payState>"+payState);
//0 没有满 1满了
setAttr("fulled", fulled);
//0 代表 该用户还没有参加该活动的组团   1 代表已经参加了
setAttr("joined", joined);
setAttr("openid", openid);
setAttr("qrcode", qrcode);
setAttr("sellerNumberId", belongPublicNumberId);
setAttr("sellerPublicNumber", spn);
setAttr("oneMoneyGroupWxUser", oneMoneyGroupWxUser);
log.error("参与用户  ********oneMoneyGroupWxUser>"+oneMoneyGroupWxUser);
setAttr("oneMoneyWxUser", oneMoneyWxUser);
log.error("参与用户  ********oneMoneyWxUser>"+oneMoneyWxUser);
setAttr("oneMoneyShop", oneMoneyShop);
setAttr("oneMoneyPrize", oneMoneyPrize);
// 判断是否属于活动时间内
Date endDate = DateUitils.strToDateYMD(oneMoneyShop.getEndTime());
// 判断当前时间是否大于活动结束时间 返回true表示大于当前时间,代表活动未结束
boolean isEnd = DateUitils.isDateBefore(endDate);
setAttr("isEnd", isEnd);
render("/oneMoneyShop/oneMoneyShop-group.html");
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值