<?php
define('IN_ECS', true);
require('../includes/init.php');
require(ROOT_PATH . '/1111/wx_api.php');
$u=urlencode(get_url()); //获取网址编码
if( empty($_COOKIE['wx_id']) ){ //如果还没有获取微信id 去获取id
header("location:https://open.weixin.qq.com/connect/oauth2/authorize?appid=".APPID."&redirect_uri=http://shop.nongpingou.cn/1111/oauth2.php?a=hb&response_type=code&scope=snsapi_base&state=1#wechat_redirect");
exit;
}
die("404");
$wxid=$_COOKIE['wx_id']; //如果获取到
$key=access_token(APPID,SECRET,0); //获取基础key
$ticket=jsapi_ticket($key,0); //获取转发jskey
$udata=access_user_info($key,$wxid,0); //获取用户信息
if(empty($udata->nickname)){
die('<h1>你还没有关注农品购无法领取红包.</h1><img src=258.jpg>'); //其他处理
}else{
$info['nickname']=urlencode($udata->nickname);
$info['sex']=$udata->sex;
$info['city']=urlencode($udata->city);
$info['province']=urlencode($udata->province);
$info['country']=urlencode($udata->country);
$info['headimgurl']=$udata->headimgurl;
$info['subscribe']=$udata->subscribe;
$info=json_encode($info); //获取用户信息保存
//查询用户是否存在
$user=$db->getRow("select * from `ecs_hongbao` where wxid='".$wxid."'") ;
if(empty($user['id'])){
$db->query("insert into ecs_hongbao (wxid,zf,lq,sj,xml,j,info) values ('$wxid','0','0','','','','$info')") ;
}
}
//转发的秘钥拼接
$no="56565m3WZYTP56565W";
$t=time();
$m=sha1("jsapi_ticket=$ticket&noncestr=$no×tamp=".$t."&url=".get_url());
//获取该用户是否转发信息
$rs=$db->getRow("select * from `ecs_hongbao` where wxid='".$wxid."' ") ;
$haha="转发有奖,真给钱。"; //转发的标题
?><!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no, -ms-touch-action: none">
<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">
<title></title>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script src="js/jquery-1.4.4.min.js"></script>
<link rel="stylesheet" href="fenxiang/css/main.css?1">
<style> * { box-sizing: border-box; }</style>
</head>
<script>
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: '<?=APPID?>', // 必填,公众号的唯一标识
timestamp:<?=$t?> , // 必填,生成签名的时间戳
nonceStr: '<?=$no?>', // 必填,生成签名的随机串
signature: '<?=$m?>',// 必填,签名,见附录1
jsApiList: ['onMenuShareTimeline'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
});
wx.ready(function(){
wx.onMenuShareTimeline({
title: '<?=$haha?>', // 分享标题
link: '<?=get_url()?>', // 分享链接
imgUrl: 'http://www.zg.com/images/p.jpg', // 分享图标
success: function () {
$.get("hongbao_list.php",function(data,status){
$("#list").html(data);
});
},
cancel: function () {
alert('别走啊,给现金阿!!.');
},
fail: function () {
alert('分享失败,QQ 15261870.');
}
});
});
wx.error(function(res){
alert('出现错误了,是测试么在所难免啊 QQ
15261870先谢谢 希望你能联系我.'+res);
});
</script>
<body>
<div id="bod">
<div style="text-align:left;border-bottom:3px solid #fff; background-color:#FFF;padding-top: 2px;padding-bottom: 7px;font-size: 30px;line-height:1.5em;"><?=$haha?><? //get_url()?></div>
<div class="container main-container">
<br>
<legend>点击右上角 "..." 分享到朋友圈可得现金 </legend>
<div style="font-size: 14px;" id="list">
<? if (empty($rs['lq']) and empty($rs['zf']) ) {
echo '<h1>你已经关注农品购,我已经获取到你的信息。</h1>';
echo "<h1>姓名:".$udata->nickname."</h1>";
echo "<h1>性别:".$udata->sex."</h1>";
echo "<h1>城市:".$udata->city."</h1>";
echo "<h1>省:".$udata->province."</h1>";
echo "<h1>国:".$udata->country."</h1>";
echo "<h1>头像 <img src='".$udata->headimgurl."' width='50'></h1>";
echo "<h1>是否关注:".($udata->subscribe==1?"是":"否")."</h1>";
}elseif($rs['lq']==1) {
echo "好运榜.<br>已经领奖显示界面<br>";
$list=$db->getAll("select * from ecs_hongbao where lq=1 order by id desc");
for($i=0;$i<count($list);$i++){
$user=json_decode(urldecode($list[$i]['info']));
?>
<?=$user->nickname?>在<?=$list[$i]['sj']?>领取了现金<?=$list[$i]['j']?>.<br>
<? }
}elseif($rs['zf']=='1' and empty($rs['lq'])){
echo "<a href='hongbao.php'> 领红包</a>";//已经转发了 当时没领。。
} ?>
</div>
</div>
</div>
</body></html>
------------------------------------------------------------------
转发后的ajax 处理
<?php
define('IN_ECS', true);
require('../includes/init.php');
require(ROOT_PATH . '/1111/wx_api.php');
$wxid= $_COOKIE['wx_id'];
if(empty($wxid)){
header("location:https://open.weixin.qq.com/connect/oauth2/authorize?appid=".APPID."&redirect_uri=http://shop.nongpingou.cn/1111/oauth2.php?a=hb&response_type=code&scope=snsapi_base&state=1#wechat_redirect");
exit;
}
//查询用户是否存在
$user=$db->getRow("select * from `ecs_hongbao` where wxid='".$wxid."'") ;
if(empty($user['id'])){
exit;
}
$db->query("update `ecs_hongbao` set zf=1 where wxid='".$wxid."'");
$list=$db->getAll("select * from ecs_hongbao where lq=1 order by id desc");
echo "<a href='hongbao.php'> 领红包</a><br><br><br>";//去领红包处理
for($i=0;$i<count($list);$i++){
$user=json_decode(urldecode($list[$i]['info']));
?>
<?=$user->nickname?>在<?=$list[$i]['sj']?>领取了现金<?=$list[$i]['j']?>.<br>
<? } ?><br>
抽奖结果