|
- <?php
- header("Content-type:text/html; charset=utf-8");
- require_once '../Common/Config.php';
- require_once '../Common/Function.php';
- if (isset($_GET['openId'])){
- $openId=$_GET['openId'];
- //$openId="oCVcbv1udkL4iZm-t1h8YMrMDSyU";
- $sql="SELECT tel,lotteryCode FROM lottery_user WHERE openId='{$openId}'";
-
- $pdo = new PDO("sqlsrv:Server=".HOST.";Database=".DB, USER, PASSWORD);//5.6版本pdo连接sqlsrv
- //$pdo=new PDO("mysql:host=".HOST.";dbname=".DB,USER,PASSWORD); //7.0版本pdo连接mysql
- $result=$pdo->query($sql);
- $rowset = $result->fetchAll(PDO::FETCH_ASSOC);
- $errinfo=$pdo->errorInfo();
- if (isset($_GET['fromOpenId'])){
- $fromOpenId=$_GET['fromOpenId'];
- }else {
- $fromOpenId="";
- }
- if($rowset){
- $infoUrl="http://".$_SERVER['HTTP_HOST']."/wechat/jssdk/lotteryinfo.php?openId=".$openId;
- Header("Location: $infoUrl");
- exit();
- }
- }else if(!isset($_GET['code'])){
- $selfUrl=urlencode("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
- $getCodeUrl="https://open.weixin.qq.com/connect/oauth2/authorize?appid=".APPID."&redirect_uri=".$selfUrl."&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
- Header("Location: $getCodeUrl");
- exit();
- }else{
- $code=$_GET['code'];
- $getOpenidUrl="https://api.weixin.qq.com/sns/oauth2/access_token?appid=".APPID."&secret=".APPSECRET."&code=".$code."&grant_type=authorization_code";
- $response=http_request($getOpenidUrl);
- $openIdObj=json_decode($response);
- $openId=$openIdObj->openid;
- $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."&openId=".$openId;
- Header("Location: $url");
- exit;
- }
- ?>
-
-
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
- <title>免费巴士自由行 | 蜘蛛免单 VOL.1</title>
- <style type="text/css">
- *{margin:0px;padding: 0px;font-family: "黑体";}
- .main{width:100%;overflow: hidden;}
- .jiangpin{width:100%;height: 183px;margin-bottom: 5px;}
- .shuoming{width:100%;text-align: center;font-size: 14px;margin-bottom: 5px;}
- .tishi{width: 100%;text-align: center;font-size: 16px;margin-top:10px;}
- .xianleft{position:absolute;height: 2px;background: #E2E2E2;width:60px;left:3.5%;top:9px;}
- .xianright{position:absolute;height: 2px;background: #E2E2E2;width:60px;right:3.5%;top:9px;}
- .moblie{width:100%;text-align: center;margin-top:20px;}
- .moblie span{font-size: 16px;}
- #moblienum{-webkit-appearance: none;width: 38%;height: 20px;border:2px solid #CCCCCC;border-radius: 5px;padding-left: 1em;font-size:15px;}
- .ps{margin-left:3.5%;margin-right: 3.5%;text-align: center;color:#9d9d9d;margin-top:13px;line-height: 22px;margin-bottom:50px;}
- .anniu{width: 100%;margin:auto;height: 40px;color: #FFFFFF;background: #33d6b0;text-align: center;line-height: 40px;font-size: 18px;position: fixed;bottom:0px;}
- </style>
-
- </head>
- <body id="body">
- <div class="main" id="main" >
- <img class="jiangpin" src="../Public/images/qiandaohu.jpg"/>
- <div class="shuoming">千岛湖</div>
- <img class="jiangpin" src="../Public/images/fo3.jpg"/>
- <div class="shuoming">普陀山</div>
- <div style="position: relative;">
- <div class="xianleft"></div>
- <div class="tishi">请输入手机号参与报名</div>
- <div class="xianright"></div>
- </div>
- <input type="hidden" id="yonghuid" value="<?php echo $openId; ?>"/>
- <input type="hidden" id="xfromOpenid" value="<?php echo $fromOpenId; ?>"/>
- <div class="moblie">
- <span>手机号</span>
- <input id="moblienum" type="tel" />
- </div>
- <div class="ps">中奖信息将发至手机,请如实填写!</div>
- <div class="anniu" id="anniu" >参加抽奖</div>
- </div>
- </body>
- <script>
- var moblienum=document.getElementById("moblienum");
- var yonghuid=document.getElementById("yonghuid");
- var xfromOpenid=document.getElementById("xfromOpenid");
- var myform=document.getElementById("myform");
- var anniu=document.getElementById("anniu");
- var regtel=/(13\d|14[57]|15[^4,\D]|17[678]|18\d)\d{8}|170[059]\d{7}/;
- anniu.onclick=function(){
- if(regtel.test(moblienum.value)&&moblienum.value.length==11){
- var str = moblienum.value;
- var openid = yonghuid.value;
- var fromOpenid=xfromOpenid.value;
- ajax({
- method:'post',
- url : 'http://xmwxc.zhizhuchuxing.cn/wechat/jssdk/lotteryinfo.php',
- //data : str+openid,
- data : {openid:openid,tel:str,fromOpenid:fromOpenid},
- success : function (text) {
- var jieguo=JSON.parse(text);
- if(jieguo.errorcode==0){
- alert(jieguo.errorinfo);
- window.location.href = "http://xmwxc.zhizhuchuxing.cn/wechat/jssdk/lotteryinfo.php?openId="+openid;
- }else{
- alert(jieguo.errorinfo);
- }
- },
- async : true
- });
- }
- else{
- alert("请输入正确手机号!");
- return false;
- }
- }
-
- function createXHR() {
- if (typeof XMLHttpRequest != 'undefined') {
- return new XMLHttpRequest();
- } else if (typeof ActiveXObject != 'undefined') {
- var version = [
- 'MSXML2.XMLHttp.6.0',
- 'MSXML2.XMLHttp.3.0',
- 'MSXML2.XMLHttp'
- ];
- for (var i = 0; version.length; i ++) {
- try {
- return new ActiveXObject(version[i]);
- } catch (e) {
- //跳过
- }
- }
- } else {
- throw new Error('您的系统或浏览器不支持XHR对象!');
- }
- }
-
- function ajax(obj) {
- var xhr = createXHR();
- obj.url = obj.url + '?rand=' + Math.random();
- obj.data=params(obj.data);
- //console.log(obj.data)
- if (obj.method === 'get') obj.url += obj.url.indexOf('?') == -1 ? '?' + obj.data : '&' + obj.data;
- if (obj.async === true) {
- xhr.onreadystatechange = function () {
- if (xhr.readyState == 4) {
- callback();
- }
- };
- }
- xhr.open(obj.method, obj.url, obj.async);
- if (obj.method === 'post') {
- xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
- xhr.send(obj.data);
- } else {
- xhr.send(null);
- }
- if (obj.async === false) {
- callback();
- }
- function callback() {
- if (xhr.status == 200) {
- obj.success(xhr.responseText); //回调传递参数
- } else {
- alert('获取数据错误!错误代号:' + xhr.status + ',错误信息:' + xhr.statusText);
- }
- }
- }
-
- //名值对转换为字符串
- function params(data) {
- var arr = [];
- for (var i in data) {
- arr.push(encodeURIComponent(i) + '=' + encodeURIComponent(data[i]));
- }
- return arr.join('&');
- }
- </script>
- </html>
|