代码拉取完成,页面将自动刷新
同步操作将从 蓝枫叶/小米同城会抽奖程序 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/*
* @Author: 窦子滨<zibin_5257@163.com>
* @Date: 2019-12-25 17:23
*/
package main
import (
"encoding/json"
"io"
"net/http"
"sort"
"strconv"
"strings"
)
func openApi() {
http.HandleFunc("/get_rand", GetRand)
http.HandleFunc("/get_list", GetList)
http.HandleFunc("/init", GetInit)
err := http.ListenAndServe(":666", nil) //设置监听的端口
if err != nil {
log.Error("打开端口出错:%s", err.Error())
}
}
//获取系统初始化数据
func GetInit(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
j := strings.Join(r.Form["callback"], "")
a := returnData{
Data: usersAllList,
Surplus_data: userlist,
Sum: len(usersAllList),
Ssum: len(userlist),
AlreadyNum: len(alreadyList),
}
v, _ := json.Marshal(a)
if j == "" {
io.WriteString(w, string(v))
} else {
io.WriteString(w, j+"("+string(v)+")")
}
}
func GetList(w http.ResponseWriter, r *http.Request) {
r.ParseForm() //解析参数,默认是不会解析的
kind, _ := strconv.Atoi(strings.Join(r.Form["i"], ""))
j := strings.Join(r.Form["callback"], "")
var data []string
switch kind {
case 2: //已中奖
data = make([]string, len(alreadyList))
copy(data, alreadyList)
case 3: //未中奖
data = make([]string, len(userlist))
copy(data, userlist)
default:
data = make([]string, len(usersAllList))
copy(data, usersAllList)
}
sort.Strings(data)
a := returnListData{
Data: data,
Num: len(data),
}
v, _ := json.Marshal(a)
if j == "" {
io.WriteString(w, string(v))
} else {
io.WriteString(w, j+"("+string(v)+")")
}
}
//随机获取抽奖结果
func GetRand(w http.ResponseWriter, r *http.Request) {
r.ParseForm() //解析参数,默认是不会解析的
j := strings.Join(r.Form["callback"], "")
status := strings.Join(r.Form["type"], "")
num, _ := strconv.Atoi(strings.Join(r.Form["num"], ""))
number++
log.Info("第%d次抽奖", number)
var list []string
var err error
if status == "1" {
log.Info("本次抽奖方式:%s,参与人数:%d", "全员模式", len(usersAllList), )
list, err = randMulti(num, true)
} else {
log.Info("本次抽奖方式:%s,参与人数:%d", "未中奖模式", len(userlist))
list, err = randMulti(num, false)
}
var v []byte
var a returnRandData
var surplusData = make([]string, len(userlist))
copy(surplusData, userlist)
if err != nil {
a = returnRandData{
Surplus: len(userlist),
Surplus_data: surplusData,
Err: 1,
ErrMsg: err.Error(),
}
v, _ = json.Marshal(a)
log.Error("本次抽奖出错:%s", err.Error())
goto OUTEND
}
log.Info("本次抽奖中奖人数:%d,中奖名单:%s", len(list), strings.Join(list, ","))
a = returnRandData{
Data: list,
Surplus: len(userlist),
Surplus_data: surplusData,
AlreadyNum: len(alreadyList),
Err: 0,
ErrMsg: "",
}
OUTEND:
v, _ = json.Marshal(a)
if j == "" {
io.WriteString(w, string(v))
} else {
io.WriteString(w, j+"("+string(v)+")")
}
log.Info("=========================")
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。