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.
 
 
 
 
 

185 lines
6.6 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>蜘蛛出行免单活动</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:1px solid black;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. <img class="jiangpin" src="../Public/images/show_153731111571_1464751138730.jpg" style="width:100%; height:auto;display:block; margin:0 auto;"/>
  63. <div class="main" id="main" >
  64. <!-- <img class="jiangpin" src="../Public/images/qiandaohu.jpg"/>
  65. <div class="shuoming">热门目的地:千岛湖</div>
  66. <img class="jiangpin" src="../Public/images/江南古镇.jpg"/>
  67. <div class="shuoming">热门目的地:江南古镇(同里周庄乌镇西塘)</div> -->
  68. <div style="position: relative;">
  69. <div class="xianleft"></div>
  70. <div class="tishi">请输入手机号参与报名</div>
  71. <div class="xianright"></div>
  72. </div>
  73. <input type="hidden" id="yonghuid" value="<?php echo $openId; ?>"/>
  74. <input type="hidden" id="xfromOpenid" value="<?php echo $fromOpenId; ?>"/>
  75. <div class="moblie">
  76. <span>手机号</span>
  77. <input id="moblienum" type="tel" />
  78. </div>
  79. <div class="ps">中奖信息将发至手机,请如实填写!</div>
  80. <div class="anniu" id="anniu" >参加抽奖</div>
  81. </div>
  82. </body>
  83. <script>
  84. var moblienum=document.getElementById("moblienum");
  85. var yonghuid=document.getElementById("yonghuid");
  86. var xfromOpenid=document.getElementById("xfromOpenid");
  87. var myform=document.getElementById("myform");
  88. var anniu=document.getElementById("anniu");
  89. var regtel=/(13\d|14[57]|15[^4,\D]|17[678]|18\d)\d{8}|170[059]\d{7}/;
  90. anniu.onclick=function(){
  91. if(regtel.test(moblienum.value)&&moblienum.value.length==11){
  92. var str = moblienum.value;
  93. var openid = yonghuid.value;
  94. var fromOpenid=xfromOpenid.value;
  95. ajax({
  96. method:'post',
  97. url : 'http://xmwx.zhizhuchuxing.cn/wechat/jssdk/lotteryinfo.php',
  98. //data : str+openid,
  99. data : {openid:openid,tel:str,fromOpenid:fromOpenid},
  100. success : function (text) {
  101. var jieguo=JSON.parse(text);
  102. if(jieguo.errorcode==0){
  103. alert(jieguo.errorinfo);
  104. window.location.href = "http://xmwx.zhizhuchuxing.cn/wechat/jssdk/lotteryinfo.php?openId="+openid;
  105. }else{
  106. alert(jieguo.errorinfo);
  107. }
  108. },
  109. async : true
  110. });
  111. }
  112. else{
  113. alert("请输入正确手机号!");
  114. return false;
  115. }
  116. }
  117. function createXHR() {
  118. if (typeof XMLHttpRequest != 'undefined') {
  119. return new XMLHttpRequest();
  120. } else if (typeof ActiveXObject != 'undefined') {
  121. var version = [
  122. 'MSXML2.XMLHttp.6.0',
  123. 'MSXML2.XMLHttp.3.0',
  124. 'MSXML2.XMLHttp'
  125. ];
  126. for (var i = 0; version.length; i ++) {
  127. try {
  128. return new ActiveXObject(version[i]);
  129. } catch (e) {
  130. //跳过
  131. }
  132. }
  133. } else {
  134. throw new Error('您的系统或浏览器不支持XHR对象!');
  135. }
  136. }
  137. function ajax(obj) {
  138. var xhr = createXHR();
  139. obj.url = obj.url + '?rand=' + Math.random();
  140. obj.data=params(obj.data);
  141. //console.log(obj.data)
  142. if (obj.method === 'get') obj.url += obj.url.indexOf('?') == -1 ? '?' + obj.data : '&' + obj.data;
  143. if (obj.async === true) {
  144. xhr.onreadystatechange = function () {
  145. if (xhr.readyState == 4) {
  146. callback();
  147. }
  148. };
  149. }
  150. xhr.open(obj.method, obj.url, obj.async);
  151. if (obj.method === 'post') {
  152. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  153. xhr.send(obj.data);
  154. } else {
  155. xhr.send(null);
  156. }
  157. if (obj.async === false) {
  158. callback();
  159. }
  160. function callback() {
  161. if (xhr.status == 200) {
  162. obj.success(xhr.responseText); //回调传递参数
  163. } else {
  164. alert('获取数据错误!错误代号:' + xhr.status + ',错误信息:' + xhr.statusText);
  165. }
  166. }
  167. }
  168. //名值对转换为字符串
  169. function params(data) {
  170. var arr = [];
  171. for (var i in data) {
  172. arr.push(encodeURIComponent(i) + '=' + encodeURIComponent(data[i]));
  173. }
  174. return arr.join('&');
  175. }
  176. </script>
  177. </html>