<?php
header("Content-Type:text/html;Charset=utf-8");
//这是一个工具类,作用是完成对数据库的操作
class mysqlHelper{
private $host = "localhost";
private $username = "test";
private $password = "188632";
private $dbname = "wx_votesystem";
private $conn;
public function __construct() {
$this->conn=mysqli_connect($this->host,$this->username,$this->password,$this->dbname);
if (!$this->conn) {
mysqli_error($this->conn);
die("连接失败".mysqli_error($this->conn));
}
//设置访问数据库的编码
mysqli_query($this->conn, "set names utf8") or die(mysqli_error($this->conn));
}
//执行sql语句,返回的是一个数组
public function execute_sql($sql) {
$arr = array();
$res = mysqli_query($this->conn,$sql) or die(mysqli_error($this->conn));
//$i=0;
while($row=mysqli_fetch_array($res)) {
//$arr[$i++]=$row;
$arr[]=$row;
}
//这里就可以马上把$res关闭
mysqli_free_result($res);
//返回数据
return $arr;
}
//执行sql语句,返回的是一个结果
public function execute_sql2($sql) {
$arr;
$res= mysqli_query($this->conn,$sql) or die(mysqli_error($this->conn));
$arr = mysqli_fetch_row($res);
//这里就可以马上把$res关闭
mysqli_free_result($res);
//返回数据
return sizeof($arr)>0?$arr[0]:0;
}
//执行sql语句,插入数据 没有返回值
public function execute_sql3($sql) {
mysqli_query($this->conn,$sql) or die(mysqli_error($this->conn));
}
//关闭链接
public function close_connect(){
mysqli_close($this->conn);
}
//关闭自动提交
public function closeautocommit(){
$this->conn->autocommit(false);
}
//提交事务
public function commit(){
$this->conn->commit();
}
//回滚事务
public function rollback(){
$this->conn->rollback();
}
//打开自动提交
public function openautocommit(){
$this->conn->autocommit(TRUE); //开启自动提交功能
}
}//mysqlHelper end
//图片上传
$upload = isset($_POST["upload"])?$_POST["upload"]:"";
//echo !empty($upload);
if(!empty($upload)){
if($upload == "wx_vote_uploadimg"){
$userid=$_POST['userid'];//上传者id
//$file = $_FILES['file'];
// echo json_encode($file);
/*
//获取文件的大小
$file_size=$_FILES['file']['size'];
if($file_size>2*1024*1024) {
echo 100;//文件过大..
exit();
}
不限制大小*/
//判断是否上传成功(是否使用post方式上传)
if(is_uploaded_file($_FILES['file']['tmp_name'])) {
//把文件转存到你希望的目录(不要使用copy函数)
$uploaded_file=$_FILES['file']['tmp_name'];
//我们给每个用户动态的创建一个文件夹
$user_path=$_SERVER['DOCUMENT_ROOT']."/wx_graduation_voteforyou/uploadfile/img/".$userid;
//判断该用户文件夹是否已经有这个文件夹
if(!file_exists($user_path)){
mkdir($user_path,0777,true);//必须加上true,多级目录,和java不同
}
//$move_to_file=$user_path."/".$_FILES['myfile']['name'];
$file_true_name=$_FILES['file']['name'];
$move_to_file=$user_path."/".time().rand(1,1000). "_" . $file_true_name;
//echo "$uploaded_file $move_to_file";
if(move_uploaded_file($uploaded_file,iconv("utf-8","gb2312",$move_to_file))){
//返回服务器地址
//echo $move_to_file;
$move_to_file =substr($move_to_file,strpos($move_to_file,"/wx_graduation_vote"));
echo $move_to_file;//成功
} else {
echo 500;//失败
}
}else {
echo 500;//失败
}
}
exit();
}
//创建一数据链接
$mysql = new mysqlHelper();
$req = isset($_GET["scene"])?$_GET["scene"]:"";//场景——跳转
$id = isset($_GET["id"])?$_GET["id"]:"";//场景跳转——详情id
if($req == "vote_login"){
$code = isset($_GET["code"])?$_GET["code"]:"";
$url = "https://api.weixin.qq.com/sns/jscode2session?appid=wx666d9a39d2780738&secret=7fd0064a2a67539d1d869d2741e84ce5&js_code=" . $code . "&grant_type=authorization_code";
//$url = "https://api.weixin.qq.com/sns/jscode2session?appid=wxb24d17bf7af92f83&secret=ac05766953f53ff245c3f45a68860e4a&js_code=" . $code . "&grant_type=authorization_code";
$curl = curl_init(); // 启动一个CURL会话
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
$result = curl_exec($curl); //返回api的json对象
//关闭URL请求
curl_close($curl);
$openid = json_decode($result)->openid;//返回json对象_中的openid
$userinfo = $_GET['userinfo'];
$user = json_decode($userinfo);
//echo "opedid:" . $openid;
//查找数据库判断是否存在
$sql = "select count(id) from tbl_user where openid = '" . $openid . "'";
$result = $mysql->execute_sql2($sql);
//echo $result;
//不存在 则添加用户
if($result == 0){
$sql = "insert tbl_user (id,name,image,openid,gender) values(null," . "'" . $user->nickName . "'," . "'" . $user->avatarUrl . "'," . "'" . $openid . "'," . $user->gender . ")";
$mysql->execute_sql3($sql);
}else{
//存在就更新_可能用户名 等信息改动
$sql = "update tbl_user set name = '" . $user->nickName . "' ,image = '" . $user->avatarUrl . "', gender = " . $user->gender . " where openid = '" . $openid . "'";
//echo $sql;
$mysql->execute_sql3($sql);
};
//查询id返回
$sql = "select id from tbl_user where openid = '" . $openid . "'";
$result = $mysql->execute_sql2($sql);
header("content-type:text/html; charset=utf-8");
echo $result;
}else if($req == "wx_vote_save"){
//获取投票信息
$votepack = $_GET['votepack'];
//json解码
$votepack = json_decode($votepack);
//获取用户id
$userid = $_GET['userid'];
$title = $votepack->title;
$votedesc = $votepack->text;
$endtime = $votepack->endTime;
$votetype = $votepack->voteOptionCount;
$isanonymous = $votepack->anonymous;
$image = $votepack->image;
$date =Date("Y-m-d H:i:s");
//插入vote表
$sql = "insert tbl_vote (title,votedesc,votetype,endtime,isanonymous,userid,starttime,image) values('" .$title . "','" . $votedesc . "'," . $votetype .",'" . $endtime . "'," . $isanonymous . "," .$userid .",'" . $date. "','" .$image ."')";
//echo $sql;
$mysql->execute_sql3($sql);
//查询id返回
$sql =" select id from tbl_vote where starttime = '" . $date ."'";
$id = $mysql->execute_sql2($sql);
//echo $id;
//插入选项
$options = $votepack->options;
foreach($options as $opt){
$sql = "insert tbl_voteoption(vdesc,voteid) values ('" . $opt . "'," .$id .")";
$mysql->execute_sql3($sql);
}
//返回选项id
echo $id;
}else if($req == "get_vote_list"){//获取投票列表
$sql = "select v.id,v.title,v.starttime,v.endtime,v.isanonymous,v.image,v.end,u.image logo,u.name,u.gender from tbl_vote v left join tbl_user u on v.userid=u.id where v.vshow = 2 order by v.id desc ";
//echo $sql;
$result = $mysql->execute_sql($sql);
echo json_encode($result);
}else if($req == "get_vote_list_own"){//获取投票列表_我发起的
$sql = "select v.id,v.title,v.starttime,v.endtime,v.isanonymous,v.image,v.end
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
界面美观,功能齐全,适合用作毕业设计、课程设计作业等,项目均经过测试,可快速部署运行! 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用! 2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。 3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。 下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
资源推荐
资源详情
资源评论
收起资源包目录
毕业设计....微信 投票小程序.zip (89个子文件)
wx_voteforyou-master
other
index.php 11KB
mysql.sql 18KB
pages
detail
detail.json 48B
detail.js 9KB
detail.wxml 3KB
detail.wxss 3KB
optiondetail
optiondetail.json 2B
optiondetail.wxml 288B
optiondetail.js 1KB
optiondetail.wxss 242B
involved
involved.js 7KB
involved.wxss 174B
involved.json 2B
involved.wxml 2KB
index
index.wxml 2KB
index.js 5KB
index.json 68B
index.wxss 1014B
create
create.js 9KB
create.wxss 867B
create.wxml 5KB
create.json 48B
logs
logs.json 54B
logs.js 266B
logs.wxml 188B
logs.wxss 106B
app.json 1KB
project.config.json 605B
app.js 2KB
utils
util.js 472B
weui.wxss 22KB
app.wxss 88B
style
weui.wxss 22KB
base
variable
weui-msg.wxss 0B
weui-dialog.wxss 0B
weui-cell.wxss 0B
weui-grid.wxss 0B
global.wxss 0B
weui-progress.wxss 0B
color.wxss 0B
weui-button.wxss 0B
reset.wxss 129B
mixin
setArrow.wxss 0B
setOnepx.wxss 0B
text.wxss 0B
fn.wxss 0B
widget
weui-page
weui-msg.wxss 663B
weui-article.wxss 405B
weui-agree
weui-agree.wxss 524B
weui-animate
weui-animate.wxss 2KB
weui-searchbar
weui-searchbar.wxss 1KB
weui-media-box
weui-media-box.wxss 2KB
weui-button
weui-button.wxss 131B
weui-panel
weui-panel.wxss 769B
weui-tab
weui-tab.wxss 1KB
weui-navbar.wxss 923B
weui-cell
weui-switch.wxss 65B
weui-cell.wxss 2KB
weui-form.wxss 4KB
weui-check.wxss 394B
weui-form
weui-form_common.wxss 781B
weui-select.wxss 774B
weui-form-preview.wxss 2KB
weui-vcode.wxss 442B
weui-access.wxss 689B
weui-uploader.wxss 2KB
weui-grid
weui-grid.wxss 628B
weui-loading
weui-loading.wxss 4KB
weui-tips
weui-loadmore.wxss 737B
weui-badge.wxss 292B
weui-flex
weui-flex.wxss 163B
weui-progress
weui-progress.wxss 322B
weui-footer
weui-footer.wxss 692B
images
sex_women.png 2KB
sex_no.png 1KB
end.png 15KB
common
1-1.png 2KB
3.png 18KB
2-2.png 3KB
1.png 2KB
6.png 4KB
5.png 2KB
4.png 2KB
3-3.png 3KB
2.png 2KB
sex_men.png 2KB
start.png 12KB
uploader
pic_160.png 3KB
vote.jpg 25KB
共 89 条
- 1
资源评论
机智的程序员zero
- 粉丝: 2416
- 资源: 4812
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Spring Cloud商城项目专栏 047 订单结算页
- 学习记录111111111111111111111111
- 删除重复字符-Python与Java中实现字符串去重方法详解
- 面向初学者的 Java 教程(包含 500 个代码示例).zip
- 阿里云OSS Java版SDK.zip
- 阿里云api网关请求签名示例(java实现).zip
- 通过示例学习 Android 的 RxJava.zip
- 通过多线程编程在 Java 中发现并发模式和特性 线程、锁、原子等等 .zip
- 通过在终端中进行探索来学习 JavaScript .zip
- 通过不仅针对初学者而且针对 JavaScript 爱好者(无论他们的专业水平如何)设计的编码挑战,自然而自信地拥抱 JavaScript .zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功