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.
 
 
 
 
 

183 lines
6.4 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. if (isset($_GET['openId'])){
  6. $openId=$_GET['openId'];
  7. //$openId="oCVcbv1udkL4iZm-t1h8YMrMDSyU";
  8. $sql="SELECT tel,lotteryCode FROM lottery_user WHERE openId='{$openId}'";
  9. $pdo = new PDO("sqlsrv:Server=".HOST.";Database=".DB, USER, PASSWORD);//5.6版本pdo连接sqlsrv
  10. //$pdo=new PDO("mysql:host=".HOST.";dbname=".DB,USER,PASSWORD); //7.0版本pdo连接mysql
  11. $result=$pdo->query($sql);
  12. $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
  13. $errinfo=$pdo->errorInfo();
  14. if (isset($_GET['fromOpenId'])){
  15. $fromOpenId=$_GET['fromOpenId'];
  16. }else {
  17. $fromOpenId="";
  18. }
  19. if($rowset){
  20. $infoUrl="http://".$_SERVER['HTTP_HOST']."/wechat/jssdk/lotteryinfo.php?openId=".$openId;
  21. Header("Location: $infoUrl");
  22. exit();
  23. }
  24. }else if(!isset($_GET['code'])){
  25. $selfUrl=urlencode("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
  26. $getCodeUrl="https://open.weixin.qq.com/connect/oauth2/authorize?appid=".APPID."&redirect_uri=".$selfUrl."&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
  27. Header("Location: $getCodeUrl");
  28. exit();
  29. }else{
  30. $code=$_GET['code'];
  31. $getOpenidUrl="https://api.weixin.qq.com/sns/oauth2/access_token?appid=".APPID."&secret=".APPSECRET."&code=".$code."&grant_type=authorization_code";
  32. $response=http_request($getOpenidUrl);
  33. $openIdObj=json_decode($response);
  34. $openId=$openIdObj->openid;
  35. $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."&openId=".$openId;
  36. Header("Location: $url");
  37. exit;
  38. }
  39. ?>
  40. <!DOCTYPE html>
  41. <html>
  42. <head>
  43. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  44. <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
  45. <title>免费巴士自由行 | 蜘蛛免单 VOL.1</title>
  46. <style type="text/css">
  47. *{margin:0px;padding: 0px;font-family: "黑体";}
  48. .main{width:100%;overflow: hidden;}
  49. .jiangpin{width:100%;height: 183px;margin-bottom: 5px;}
  50. .shuoming{width:100%;text-align: center;font-size: 14px;margin-bottom: 5px;}
  51. .tishi{width: 100%;text-align: center;font-size: 16px;margin-top:10px;}
  52. .xianleft{position:absolute;height: 2px;background: #E2E2E2;width:60px;left:3.5%;top:9px;}
  53. .xianright{position:absolute;height: 2px;background: #E2E2E2;width:60px;right:3.5%;top:9px;}
  54. .moblie{width:100%;text-align: center;margin-top:20px;}
  55. .moblie span{font-size: 16px;}
  56. #moblienum{-webkit-appearance: none;width: 38%;height: 20px;border:2px solid #CCCCCC;border-radius: 5px;padding-left: 1em;font-size:15px;}
  57. .ps{margin-left:3.5%;margin-right: 3.5%;text-align: center;color:#9d9d9d;margin-top:13px;line-height: 22px;margin-bottom:50px;}
  58. .anniu{width: 100%;margin:auto;height: 40px;color: #FFFFFF;background: #33d6b0;text-align: center;line-height: 40px;font-size: 18px;position: fixed;bottom:0px;}
  59. </style>
  60. </head>
  61. <body id="body">
  62. <div class="main" id="main" >
  63. <img class="jiangpin" src="../Public/images/qiandaohu.jpg"/>
  64. <div class="shuoming">千岛湖</div>
  65. <img class="jiangpin" src="../Public/images/fo3.jpg"/>
  66. <div class="shuoming">普陀山</div>
  67. <div style="position: relative;">
  68. <div class="xianleft"></div>
  69. <div class="tishi">请输入手机号参与报名</div>
  70. <div class="xianright"></div>
  71. </div>
  72. <input type="hidden" id="yonghuid" value="<?php echo $openId; ?>"/>
  73. <input type="hidden" id="xfromOpenid" value="<?php echo $fromOpenId; ?>"/>
  74. <div class="moblie">
  75. <span>手机号</span>
  76. <input id="moblienum" type="tel" />
  77. </div>
  78. <div class="ps">中奖信息将发至手机,请如实填写!</div>
  79. <div class="anniu" id="anniu" >参加抽奖</div>
  80. </div>
  81. </body>
  82. <script>
  83. var moblienum=document.getElementById("moblienum");
  84. var yonghuid=document.getElementById("yonghuid");
  85. var xfromOpenid=document.getElementById("xfromOpenid");
  86. var myform=document.getElementById("myform");
  87. var anniu=document.getElementById("anniu");
  88. var regtel=/(13\d|14[57]|15[^4,\D]|17[678]|18\d)\d{8}|170[059]\d{7}/;
  89. anniu.onclick=function(){
  90. if(regtel.test(moblienum.value)&&moblienum.value.length==11){
  91. var str = moblienum.value;
  92. var openid = yonghuid.value;
  93. var fromOpenid=xfromOpenid.value;
  94. ajax({
  95. method:'post',
  96. url : 'http://xmwxc.zhizhuchuxing.cn/wechat/jssdk/lotteryinfo.php',
  97. //data : str+openid,
  98. data : {openid:openid,tel:str,fromOpenid:fromOpenid},
  99. success : function (text) {
  100. var jieguo=JSON.parse(text);
  101. if(jieguo.errorcode==0){
  102. alert(jieguo.errorinfo);
  103. window.location.href = "http://xmwxc.zhizhuchuxing.cn/wechat/jssdk/lotteryinfo.php?openId="+openid;
  104. }else{
  105. alert(jieguo.errorinfo);
  106. }
  107. },
  108. async : true
  109. });
  110. }
  111. else{
  112. alert("请输入正确手机号!");
  113. return false;
  114. }
  115. }
  116. function createXHR() {
  117. if (typeof XMLHttpRequest != 'undefined') {
  118. return new XMLHttpRequest();
  119. } else if (typeof ActiveXObject != 'undefined') {
  120. var version = [
  121. 'MSXML2.XMLHttp.6.0',
  122. 'MSXML2.XMLHttp.3.0',
  123. 'MSXML2.XMLHttp'
  124. ];
  125. for (var i = 0; version.length; i ++) {
  126. try {
  127. return new ActiveXObject(version[i]);
  128. } catch (e) {
  129. //跳过
  130. }
  131. }
  132. } else {
  133. throw new Error('您的系统或浏览器不支持XHR对象!');
  134. }
  135. }
  136. function ajax(obj) {
  137. var xhr = createXHR();
  138. obj.url = obj.url + '?rand=' + Math.random();
  139. obj.data=params(obj.data);
  140. //console.log(obj.data)
  141. if (obj.method === 'get') obj.url += obj.url.indexOf('?') == -1 ? '?' + obj.data : '&' + obj.data;
  142. if (obj.async === true) {
  143. xhr.onreadystatechange = function () {
  144. if (xhr.readyState == 4) {
  145. callback();
  146. }
  147. };
  148. }
  149. xhr.open(obj.method, obj.url, obj.async);
  150. if (obj.method === 'post') {
  151. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  152. xhr.send(obj.data);
  153. } else {
  154. xhr.send(null);
  155. }
  156. if (obj.async === false) {
  157. callback();
  158. }
  159. function callback() {
  160. if (xhr.status == 200) {
  161. obj.success(xhr.responseText); //回调传递参数
  162. } else {
  163. alert('获取数据错误!错误代号:' + xhr.status + ',错误信息:' + xhr.statusText);
  164. }
  165. }
  166. }
  167. //名值对转换为字符串
  168. function params(data) {
  169. var arr = [];
  170. for (var i in data) {
  171. arr.push(encodeURIComponent(i) + '=' + encodeURIComponent(data[i]));
  172. }
  173. return arr.join('&');
  174. }
  175. </script>
  176. </html>