query($sql); $rowset = $result->fetchAll(PDO::FETCH_ASSOC); $errinfo=$pdo->errorInfo(); if ($errinfo[0] =="00000" && empty($rowset)){ $sql="SELECT TOP 1 id,lotteryCode FROM lottery_code"; $result=$pdo->query($sql); $rowset = $result->fetchAll(PDO::FETCH_ASSOC); $errinfo=$pdo->errorInfo(); if ($errinfo[0] =="00000" && !empty($rowset)){ $lotteryCode=$rowset[0]['lotteryCode']; $id=$rowset[0]['id']; try { $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->beginTransaction(); $sqla="INSERT INTO lottery_user(openId,tel,createtime) VALUES('".$openid."','".$tel."','".date("Y-m-d H:i:s",time())."')"; $resulta=$pdo->exec($sqla); $sqlb="INSERT INTO lottery_friends(openId,friendsOpenId,lotteryCode,createtime) VALUES('".$openid."','".$fromOpenid."',".$lotteryCode.",'".date("Y-m-d H:i:s",time())."')"; $resultb=$pdo->exec($sqlb); $sqlc="DELETE FROM lottery_code WHERE id=".$id; $resultc=$pdo->exec($sqlc); $pdo->exec($sql); $pdo->exec(); $pdo->commit(); if ($resultb && $resultc !==false){ echo json_encode(array("errorcode"=>0,"errorinfo"=>"报名成功")); if ($fromOpenid !=''){ $fsql="SELECT id FROM lottery_user WHERE openId='".$fromOpenid."'"; $fresult=$pdo->query($fsql); $frowset = $fresult->fetchAll(PDO::FETCH_ASSOC); $errinfo=$pdo->errorInfo(); if ($frowset){ $icodesql="SELECT TOP 1 id,lotteryCode FROM lottery_code"; $icoderesult=$pdo->query($icodesql); $icoderowset = $icoderesult->fetchAll(PDO::FETCH_ASSOC); //$icodeerrinfo=$pdo->errorInfo(); if ($icoderowset){ $iid=$icoderowset[0]['id']; $icode=$icoderowset[0]['lotteryCode']; try { $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->beginTransaction(); $isql="INSERT INTO lottery_friends(openId,lotteryCode,createtime) VALUES('".$fromOpenid."',".$icode.",'".date("Y-m-d H:i:s",time())."')"; $iresult=$pdo->exec($isql); $dsql="DELETE FROM lottery_code WHERE id=".$iid; $iresult=$pdo->exec($dsql); $pdo->commit(); } catch (Exception $e) { $pdo->rollBack(); //echo "Failed: " . $e->getMessage(); } } } } exit; } } catch (Exception $e) { $pdo->rollBack(); echo json_encode(array("errorcode"=>1,"errorinfo"=>"报名失败"));exit; } }else{ echo json_encode(array("errorcode"=>2,"errorinfo"=>"抽奖码已发完"));exit; } }else{ echo json_encode(array("errorcode"=>3,"errorinfo"=>"微信号已经报名"));exit; } //} if (isset($_GET['openId'])){ $openId=$_GET['openId']; //$openId="oCVcbv1udkL4iZm-t1h8YMrMDSyU"; $sql="SELECT id,tel,sharTimeLine,lotteryCode FROM lottery_user WHERE openId='{$openId}'"; //$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($rowset){ $htmlTel=$rowset[0]['tel']; $codeSql="SELECT lotteryCode FROM lottery_friends WHERE openId='{$openId}'"; //$pdo=new PDO("mysql:host=".HOST.";dbname=".DB,USER,PASSWORD); //7.0版本pdo连接mysql $codeResult=$pdo->query($codeSql); $codeRowset = $codeResult->fetchAll(PDO::FETCH_ASSOC); if ($codeRowset){ $htmlCode=""; foreach ($codeRowset as $v){ $htmlCode.=$v['lotteryCode'].","; } $htmlCode=rtrim($htmlCode,","); } //$htmlCode=$rowset[0]['lotteryCode']; $sharTimeLine=$rowset[0]['sharTimeLine']; $updateId=$rowset[0]['id']; $jssdk = new JSSDK(APPID, APPSECRET); $signPackage = $jssdk->GetSignPackage(); $news = array( "Title" =>"【免费巴士自由行】千岛湖、普陀山共10名额 蜘蛛出行请你玩", "Description"=>"【蜘蛛出行微信上线啦~】千岛湖、普陀山巴士自由行各5个免单名额相送!关注我们预定安全舒适便捷的巴士出行 : D", "PicUrl" =>'https://mmbiz.qlogo.cn/mmbiz/xVqMASLIx1nE5XSsicXcM1znAqdS9rBA8W1GgS55lnu0fRR1AgsyzRiaTb5ANLVhrtdQ6FFEjFpypPVuylpH1kVQ/0?wx_fmt=jpeg', "Url" =>'http://xmwxc.zhizhuchuxing.cn/wechat/jssdk/activity.php'); $sharfriendArr=array("url"=>'http://xmwxc.zhizhuchuxing.cn/wechat/jssdk/activity.php?fromOpenId='.$openId); }else { $infoUrl="http://".$_SERVER['HTTP_HOST']."/wechat/jssdk/activity.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; } ?>
手机号:
你的抽奖码:
抽奖码:".$v['lotteryCode']."
"; } */ ?>
多要一个抽奖码
×