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.
 
 
 
 
 

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