You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

358 lines
15 KiB

  1. <?php
  2. header("Content-type:text/html; charset=utf-8");
  3. require_once '../Common/Config.php';
  4. require_once '../Common/Function.php';
  5. require_once "jssdk.php";
  6. $pdo = new PDO("sqlsrv:Server=".HOST.";Database=".DB, USER, PASSWORD);//5.6版本pdo连接sqlsrv
  7. if ($_POST){
  8. $openid= htmlspecialchars($_POST['openid']);
  9. $fromOpenid=htmlspecialchars($_POST['fromOpenid']);
  10. $tel=htmlspecialchars($_POST['tel']);
  11. /* $openid="oCVcbv1udkL4iZm-t1h8YMrMDSyU2";
  12. $tel="13025822222";
  13. $fromOpenid=''; */
  14. $sql="SELECT id FROM lottery_user WHERE openId='".$openid."'";
  15. $result=$pdo->query($sql);
  16. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  17. $errinfo=$pdo->errorInfo();
  18. if (!$rowset){
  19. $sql="SELECT TOP 1 id,lotteryCode FROM lottery_code";
  20. $result=$pdo->query($sql);
  21. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  22. $errinfo=$pdo->errorInfo();
  23. if ($errinfo[0] =="00000"){
  24. $lotteryCode=$rowset[0]['lotteryCode'];
  25. $id=$rowset[0]['id'];
  26. //$id=2;
  27. $sql="INSERT INTO lottery_user(openId,tel,createtime) VALUES('".$openid."','".$tel."','".date("Y-m-d H:i:s",time())."')";
  28. $result=$pdo->exec($sql);
  29. $sql="INSERT INTO lottery_friends(openId,friendsOpenId,lotteryCode,createtime) VALUES('".$openid."','".$fromOpenid."',".$lotteryCode.",'".date("Y-m-d H:i:s",time())."')";
  30. $result=$pdo->exec($sql);
  31. $sql="DELETE FROM lottery_code WHERE id=".$id;
  32. $result1=$pdo->exec($sql);
  33. if ($result && $result1 !==false){
  34. echo json_encode(array("errorcode"=>0,"errorinfo"=>"报名成功"));
  35. if ($fromOpenid !=''){
  36. $fsql="SELECT id FROM lottery_user WHERE openId='".$fromOpenid."'";
  37. $fresult=$pdo->query($fsql);
  38. $frowset = $fresult->fetchAll(PDO::FETCH_ASSOC);
  39. $errinfo=$pdo->errorInfo();
  40. if ($frowset){
  41. $icodesql="SELECT TOP 1 id,lotteryCode FROM lottery_code";
  42. $icoderesult=$pdo->query($icodesql);
  43. $icoderowset = $icoderesult->fetchAll(PDO::FETCH_ASSOC);
  44. //$icodeerrinfo=$pdo->errorInfo();
  45. if ($icoderowset){
  46. $iid=$icoderowset[0]['id'];
  47. $icode=$icoderowset[0]['lotteryCode'];
  48. $isql="INSERT INTO lottery_friends(openId,lotteryCode,createtime) VALUES('".$fromOpenid."',".$icode.",'".date("Y-m-d H:i:s",time())."')";
  49. $iresult=$pdo->exec($isql);
  50. $dsql="DELETE FROM lottery_code WHERE id=".$iid;
  51. $iresult=$pdo->exec($dsql);
  52. }
  53. }
  54. }
  55. exit;
  56. }else{
  57. echo json_encode(array("errorcode"=>1,"errorinfo"=>"报名失败"));exit;
  58. }
  59. }else{
  60. echo json_encode(array("errorcode"=>2,"errorinfo"=>"抽奖码已发完"));exit;
  61. }
  62. }else{
  63. echo json_encode(array("errorcode"=>3,"errorinfo"=>"微信号已经报名"));exit;
  64. }
  65. }
  66. if (isset($_GET['openId'])){
  67. $openId=$_GET['openId'];
  68. //$openId="oCVcbv1udkL4iZm-t1h8YMrMDSyU";
  69. $sql="SELECT id,tel,sharTimeLine,lotteryCode FROM lottery_user WHERE openId='{$openId}'";
  70. //$pdo=new PDO("mysql:host=".HOST.";dbname=".DB,USER,PASSWORD); //7.0版本pdo连接mysql
  71. $result=$pdo->query($sql);
  72. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  73. $errinfo=$pdo->errorInfo();
  74. if($rowset){
  75. $htmlTel=$rowset[0]['tel'];
  76. $codeSql="SELECT lotteryCode FROM lottery_friends WHERE openId='{$openId}'";
  77. //$pdo=new PDO("mysql:host=".HOST.";dbname=".DB,USER,PASSWORD); //7.0版本pdo连接mysql
  78. $codeResult=$pdo->query($codeSql);
  79. $codeRowset = $codeResult->fetchAll(PDO::FETCH_ASSOC);
  80. if ($codeRowset){
  81. $htmlCode="";
  82. foreach ($codeRowset as $v){
  83. $htmlCode.=$v['lotteryCode'].",";
  84. }
  85. $htmlCode=rtrim($htmlCode,",");
  86. }
  87. //$htmlCode=$rowset[0]['lotteryCode'];
  88. $sharTimeLine=$rowset[0]['sharTimeLine'];
  89. $updateId=$rowset[0]['id'];
  90. $jssdk = new JSSDK(APPID, APPSECRET);
  91. $signPackage = $jssdk->GetSignPackage();
  92. $news = array(
  93. "Title" =>"【免费巴士自由行】千岛湖、普陀山共10名额 蜘蛛出行请你玩",
  94. "Description"=>"【蜘蛛出行微信上线啦~】千岛湖、普陀山巴士自由行各5个免单名额相送!关注我们预定安全舒适便捷的巴士出行 : D",
  95. "PicUrl" =>'https://mmbiz.qlogo.cn/mmbiz/xVqMASLIx1nE5XSsicXcM1znAqdS9rBA8W1GgS55lnu0fRR1AgsyzRiaTb5ANLVhrtdQ6FFEjFpypPVuylpH1kVQ/0?wx_fmt=jpeg',
  96. "Url" =>'http://xmwxc.zhizhuchuxing.cn/wechat/jssdk/activity.php');
  97. $sharfriendArr=array("url"=>'http://xmwxc.zhizhuchuxing.cn/wechat/jssdk/activity.php?fromOpenId='.$openId);
  98. }else {
  99. $infoUrl="http://".$_SERVER['HTTP_HOST']."/wechat/jssdk/activity.php?openId=".$openId;
  100. Header("Location: $infoUrl");
  101. exit();
  102. }
  103. }else if(!isset($_GET['code'])){
  104. $selfUrl=urlencode("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
  105. $getCodeUrl="https://open.weixin.qq.com/connect/oauth2/authorize?appid=".APPID."&redirect_uri=".$selfUrl."&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
  106. Header("Location: $getCodeUrl");
  107. exit();
  108. }else{
  109. $code=$_GET['code'];
  110. $getOpenidUrl="https://api.weixin.qq.com/sns/oauth2/access_token?appid=".APPID."&secret=".APPSECRET."&code=".$code."&grant_type=authorization_code";
  111. $response=http_request($getOpenidUrl);
  112. $openIdObj=json_decode($response);
  113. $openId=$openIdObj->openid;
  114. $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."&openId=".$openId;
  115. Header("Location: $url");
  116. exit;
  117. }
  118. ?>
  119. <!DOCTYPE html>
  120. <html>
  121. <head>
  122. <meta charset="UTF-8">
  123. <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
  124. <title></title>
  125. <style>
  126. *{margin:0px;padding: 0px;font-family: "黑体";}
  127. .tishi2{width:100%;text-align: center;font-size:18px;line-height: 30px;margin-bottom:20px;}
  128. .page2moblie,.page2choujiang{width:100%;text-align: center;margin-bottom:5px;}
  129. .page2moblie span,.page2choujiang span{font-size: 16px;}
  130. .kjtime{width:100%;text-align: center;font-size: 18px;margin-top:20px;}
  131. .kjtime2{width:100%;text-align: center;font-size: 18px;margin-top:5px;margin-bottom: 10px;}
  132. .anniu2{width:90%;margin:auto;text-align: center;height: 35px;line-height: 35px;font-size: 18px;color: #FFFFFF;background: #33d6b0;margin-bottom: 10px;margin-top:15px;}
  133. .tishi3{margin-left:5%;font-weight: bold;text-align: left;margin-top:17px;}
  134. .tishi4{width:90%;margin:auto;font-size: 14px;margin-top:10px;line-height: 22px;}
  135. .zhizhulogo{width:100%;height: 136px;}
  136. .black{position: absolute;top:0;left: 0;background: #000000;opacity: 0.4;width:100%;}
  137. .tishi5{position: absolute;top:175px;left: 0;right: 0;margin:auto;background: #FFFFFF;width:66%;border-radius:5px;padding: 10px;padding-top:30px;padding-bottom:30px;font-size:15px;display: none;}
  138. .x{position: absolute;top:5px;right:5px; height: 20px;width:20px;text-align: center;line-height: 21px;font-size: 21px;background:#FF7E00;color:#FFFFFF;border-radius:2px;}
  139. .erweima{width:180px;margin-top:10px;}
  140. </style>
  141. </head>
  142. <body id="body">
  143. <div style="position: relative;">
  144. <div class="page2" id="page2">
  145. <div class="tishi2">
  146. <div style="margin-bottom:5px;width:90%;margin:auto;padding-top:85px;">您已成功参与蜘蛛出行免单活动!</div>
  147. <div style="text-align: center; font-size:15px;"><a href="http://mp.weixin.qq.com/s?__biz=MzIwNjI0MDAwOQ==&mid=502857775&idx=2&sn=1d04e2f10383af14cdd1a8481353e9ef&scene=1&srcid=05187fCeBZFiQD8IUOgrRN1R#rd" style="color: #33d6b0;">点击选择奖品>></a></div>
  148. <!--<div>免费千岛湖巴士自由行共5名额</div>
  149. <div style="font-size: 14px;">上海出发 不含住宿及门票</div>
  150. <div>免费普陀山巴士自由行共5名额</div>
  151. <div style="font-size: 14px;">上海出发 不含住宿及门票</div>-->
  152. <!--<a href="http://mp.weixin.qq.com/s?__biz=MzIwNjI0MDAwOQ==&mid=502857775&idx=2&sn=1d04e2f10383af14cdd1a8481353e9ef&scene=0&previewkey=m65GKbcndwwmEE8v%2FfjGRcwqSljwj2bfCUaCyDofEow%3D#wechat_redirect">
  153. <img style="height: 277px;width:100%;" src="img/lotop.png"/>
  154. </a>-->
  155. </div>
  156. <div class="page2moblie" style="margin-bottom:63px;">
  157. <span>手机号:</span>
  158. <span id="moblienum2"><?php echo $htmlTel; ?></span>
  159. </div>
  160. <div id="cjm">
  161. <div class="page2choujiang">
  162. <div style="margin-bottom:20px;">你的抽奖码:</div>
  163. <div id="choujiangma" style="width:90%;margin-left:5%;padding-right:5%; word-wrap: break-word; word-break: break-all;"><?php echo $htmlCode;?></div>
  164. </div>
  165. <?php
  166. /* foreach ($codeRowset as $v){
  167. echo "<div class='page2choujiang'><span>抽奖码:</span><span>".$v['lotteryCode']."</span></div>";
  168. } */
  169. ?>
  170. </div>
  171. <div class="anniu2" id="anniu2">多要一个抽奖码</div>
  172. <!--<div class="anniu2" id="anniu3">再拿一个大红包</div>-->
  173. <div class="tishi3" style="margin-top:30px;">开奖时间:</div>
  174. <div class="tishi4" >2016年5月23日 周一 18:00</div>
  175. <div class="tishi3">温馨提示:</div>
  176. <div class="tishi4" >长按下方二维码关注我们,获取中奖提醒;若开奖时未关注蜘蛛出行,中奖视为无效。</div>
  177. <!-- <div class="tishi4" >2.点击上方[再拿一个大红包],成功邀请2位好友参与,奖励一个大红包!红包数量有限,先到先得哦!</div>-->
  178. <div style="margin:0 auto;text-align: center;">
  179. <img class="erweima" src="../Public/images/erweima.jpg" alt="" />
  180. <img class="zhizhulogo" style="width:300px;" src="../Public/images/zhizhulogo.png" alt="" />
  181. </div>
  182. </div>
  183. <div class="black" id="black"></div>
  184. <div class="tishi5" id="tishi5">
  185. <div class="x" id="x">×</div>
  186. <div id="content"></div>
  187. </div>
  188. </div>
  189. </body>
  190. <script>
  191. var anniu3=document.getElementById("anniu3");
  192. var anniu2=document.getElementById("anniu2");
  193. var tishi5=document.getElementById("tishi5");
  194. var black=document.getElementById("black");
  195. var body=document.getElementById("body");
  196. var x=document.getElementById("x");
  197. var content=document.getElementById("content");
  198. var H=document.documentElement.clientHeight;
  199. black.style.height=H+"px";
  200. black.style.display="none";
  201. var banmove=function(ev){ev.preventDefault();}
  202. anniu2.onclick=function(){
  203. window.scrollTo(0,0);
  204. body.addEventListener("touchmove",banmove);
  205. body.style.height=H+'px';
  206. body.style.overflow="hidden";
  207. black.style.display="block";
  208. tishi5.style.display="block";
  209. content.innerHTML="点击右上角【···】,选择【分享朋友圈】,分享成功,您即多获得一个抽奖码;<br>选择【发送给朋友】每邀请一位好友报名成功,再额外获得一个抽奖码!"
  210. }
  211. /* anniu3.onclick=function(){
  212. body.style.overflow="hidden";
  213. black.style.display="block";
  214. tishi5.style.display="block";
  215. content.innerHTML="点击右上角【···】,选择【发送给朋友】邀请两位好友报名成功,您即可领取红包!共190份红包,先到先得!"
  216. } */
  217. x.onclick=function(){
  218. body.removeEventListener("touchmove",banmove);
  219. tishi5.style.display="none";
  220. black.style.display="none";
  221. body.style.overflow="scroll";
  222. }
  223. </script>
  224. <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
  225. <script src="../Public/js/jquery-1.12.3.min.js"></script>
  226. <script>
  227. /*
  228. * 注意:
  229. * 1. 所有的JS接口只能在公众号绑定的域名下调用,公众号开发者需要先登录微信公众平台进入“公众号设置”的“功能设置”里填写“JS接口安全域名”。
  230. * 2. 如果发现在 Android 不能分享自定义内容,请到官网下载最新的包覆盖安装,Android 自定义分享接口需升级至 6.0.2.58 版本及以上。
  231. * 3. 常见问题及完整 JS-SDK 文档地址:http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html
  232. *
  233. * 开发中遇到问题详见文档“附录5-常见错误及解决办法”解决,如仍未能解决可通过以下渠道反馈:
  234. * 邮箱地址:weixin-open@qq.com
  235. * 邮件主题:【微信JS-SDK反馈】具体问题
  236. * 邮件内容说明:用简明的语言描述问题所在,并交代清楚遇到该问题的场景,可附上截屏图片,微信团队会尽快处理你的反馈。
  237. */
  238. wx.config({
  239. debug: false,
  240. appId: '<?php echo $signPackage["appId"];?>',
  241. timestamp: <?php echo $signPackage["timestamp"];?>,
  242. nonceStr: '<?php echo $signPackage["nonceStr"];?>',
  243. signature: '<?php echo $signPackage["signature"];?>',
  244. jsApiList: [
  245. // 所有要调用的 API 都要加到这个列表中
  246. //'checkJsApi',
  247. 'onMenuShareTimeline',
  248. 'onMenuShareAppMessage'
  249. ]
  250. });
  251. wx.ready(function () {
  252. //检查是否支持jsApi
  253. /* wx.checkJsApi({
  254. jsApiList: [
  255. 'onMenuShareTimeline',
  256. 'onMenuShareAppMessage'
  257. ],
  258. success: function (res) {
  259. //alert(1);
  260. alert(JSON.stringify(res));
  261. }
  262. }); */
  263. // 在这里调用 API
  264. wx.onMenuShareTimeline({ //分享到朋友圈
  265. title: '<?php echo $news['Title'];?>',
  266. link: '<?php echo $news['Url'];?>',
  267. imgUrl: '<?php echo $news['PicUrl'];?>',
  268. trigger: function (res) {
  269. // 不要尝试在trigger中使用ajax异步请求修改本次分享的内容,因为客户端分享操作是一个同步操作,这时候使用ajax的回包会还没有返回
  270. // alert('用户点击分享到朋友圈');
  271. },
  272. success: function (res) {
  273. alert("分享成功");
  274. var url="http://xmwxc.zhizhuchuxing.cn/wechat/jssdk/lottery.php";
  275. $.ajax({
  276. type:'post',
  277. async:false,
  278. cache:false,
  279. data:{
  280. method:"shareTimeLine",
  281. sharTimeLine:<?php echo $sharTimeLine;?>,
  282. updateId:<?php echo $updateId;?>,
  283. openId:'<?php echo $openId;?>'
  284. },
  285. url : url,
  286. success : function(data) {
  287. window.location.href = "http://xmwxc.zhizhuchuxing.cn/wechat/jssdk/lotteryinfo.php?openId=<?php echo $openId;?>";
  288. },
  289. error : function() {
  290. alert('fail');
  291. }
  292. });
  293. },
  294. cancel: function (res) {
  295. alert('已取消');
  296. },
  297. fail: function (res) {
  298. // alert(JSON.stringify(res));
  299. }
  300. });
  301. wx.onMenuShareAppMessage({ //分享给朋友
  302. title: '<?php echo $news['Title'];?>',
  303. desc: '<?php echo $news['Description'];?>',
  304. link: '<?php echo $sharfriendArr['url']?>',
  305. imgUrl: '<?php echo $news['PicUrl'];?>',
  306. trigger: function (res) {
  307. // 不要尝试在trigger中使用ajax异步请求修改本次分享的内容,因为客户端分享操作是一个同步操作,这时候使用ajax的回包会还没有返回
  308. // alert('用户点击发送给朋友');
  309. },
  310. success: function (res) {
  311. alert('已分享');
  312. //alert(JSON.stringify(res));
  313. },
  314. cancel: function (res) {
  315. // alert('已取消');
  316. },
  317. fail: function (res) {
  318. // alert(JSON.stringify(res));
  319. }
  320. });
  321. /* wx.hideMenuItems({
  322. menuList: [
  323. 'menuItem:share:appMessage',
  324. 'menuItem:share:timeline',
  325. 'menuItem:copyUrl'
  326. ] // 要隐藏的菜单项,只能隐藏“传播类”和“保护类”按钮,所有menu项见附录3
  327. }); */
  328. });
  329. </script>
  330. </html>