您现在的位置:新闻首页>彩票资讯

go语言一元云购独立时 时 彩开奖计算程序源码实例

2018-05-12 03:53编辑:新特彩票网人气:


【实例简介】 独立运行,绝对不会因取不到时时彩数据而开不了奖。获取重庆时时彩最新一期彩票号码,获取网站N条购物记录,计算出中奖号码,修改数据库,发送中奖通知。需修改云购源码才能对接,自行研究!


【实例截图】

go语言一元云购独立时 时 彩开奖计算程序源码实例

【核心代码】

//获取到最新的时时彩开奖结果
func getShiShiCai() {
resp, err := http.Get(caipiaourl)
if err != nil {
fmt.Println("时时彩开奖结果获取失败")
return
}
result, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
fmt.Println("时时彩开奖结果获取失败")
return
}
var data map[string]interface{}
err = json.Unmarshal([]byte(result), &data)
if err != nil {
fmt.Println("时时彩数据解析失败" err.Error())
return
}
data = data["data"].([]interface{})[0].(map[string]interface{})
caipiao, err := strconv.ParseInt(strings.Replace(data["opencode"].(string), ",", "", -1), 10, 64)
if err == nil {
caipiaocode = caipiao
caipiaoqishu = data["expect"].(string)
fmt.Println("获取到彩票[" caipiaoqishu "期]开奖结果:" strconv.FormatInt(caipiaocode, 10))
}
}

//计算中奖号码
func runCode() {
for {
shopValue := <-shop
fmt.Println("开始开奖[" gosql.StringDefault(shopValue["qishu"], "未知") "期]" gosql.StringDefault(shopValue["title"], "未知商品"))
//获取最后购买时间点的第n条时间纪录
lastbuyinfo, err := db.Rows("SELECT * FROM " dbPrefix "member_go_record WHERE time <= (SELECT time FROM " dbPrefix "member_go_record WHERE shopid = ? ORDER BY id DESC LIMIT 1) ORDER BY id DESC LIMIT " strconv.FormatInt(last, 10), shopValue["id"])
if err != nil {
fmt.Println("获取最后购买的" strconv.FormatInt(last, 10) "条数据失败:" err.Error())
continue
}
array := make(phpserialize.PhpSlice, len(lastbuyinfo))
var timecount int64
for index, v := range lastbuyinfo {
buytime, _ := gosql.String(v["time"])
buytimes := strings.Split(buytime, ".")
unixtime, _ := strconv.ParseInt(buytimes[0], 10, 64)
t := time.Unix(unixtime, 0)
count := fmtLen(strconv.FormatInt(int64(t.Hour()), 10)) fmtLen(strconv.FormatInt(int64(t.Minute()), 10)) fmtLen(strconv.FormatInt(int64(t.Second()), 10)) buytimes[1]
info := make(phpserialize.PhpArray)
info["time"], _ = gosql.String(v["time"])
info["username"], _ = gosql.String(v["username"])
info["uid"], _ = gosql.String(v["uid"])
info["shopid"], _ = gosql.String(v["shopid"])
info["shopname"], _ = gosql.String(v["shopname"])
info["shopqishu"], _ = gosql.String(v["shopqishu"])
info["gonumber"], _ = gosql.String(v["gonumber"])
info["time_add"] = count
array[index] = info
tc, _ := strconv.ParseInt(count, 10, 64)
timecount = tc
}
phps, err := phpserialize.Serialize(array)
if err != nil {
fmt.Println("php序列化失败:" err.Error())
continue
}
zhonrenshu, _ := gosql.Int64(shopValue["zongrenshu"]) //总人数
counttime := timecount                                //时间中值
timecount = caipiaocode                              //获取到所有数据值 = 时间统计+彩票值
timecount = timecount % zhonrenshu                    //取总人数余数
//timecount := caipiaocode % zhonrenshu //彩票结果取余
timecount = 10000001 //得到中奖代码
fmt.Println("开奖结果:" strconv.FormatInt(timecount, 10))
//查询中奖者
uGoInfo, err := db.Rows("SELECT * FROM " dbPrefix "member_go_record WHERE `shopid` = ? AND `shopqishu` = ? AND goucode LIKE ? LIMIT 1 ", shopValue["id"], shopValue["qishu"], "%" strconv.FormatInt(timecount, 10) "%")
if err != nil || len(uGoInfo) < 1 {
fmt.Println("中奖者信息查询失败")
continue
}
userBuyInfo := uGoInfo[0]
uInfo, err := db.Rows("SELECT uid,username,email,mobile,img FROM " dbPrefix "member WHERE `uid` = ? LIMIT 1", userBuyInfo["uid"])
if err != nil || len(uInfo) < 1 {
fmt.Println("中奖者不存在[" gosql.StringDefault(userBuyInfo["uid"], "") "]")
continue
}
userInfo := phpserialize.PhpArray{
"uid":      gosql.Int64Default(uInfo[0]["uid"], 0),
"username": gosql.StringDefault(uInfo[0]["username"], ""),
"email":    gosql.StringDefault(uInfo[0]["email"], ""),
"mobile":   gosql.StringDefault(uInfo[0]["mobile"], ""),
"img":      gosql.StringDefault(uInfo[0]["img"], ""),
}
userInfo["cpqs"] = caipiaoqishu //保存彩票期数
userInfo["cpjg"] = caipiaocode  //保存彩票号码
//更新商品
user, err := phpserialize.Serialize(userInfo)
if err != nil {
fmt.Println("用户数据序列化失败:" err.Error())
continue
}
sqlss := "UPDATE `" dbPrefix "shoplist` SET `canyurenshu`=`zongrenshu`,`shenyurenshu` = '0',`q_counttime` = ? ,`q_content` = ?,`q_uid` = ?,`q_user` = ?,`q_user_code` = ? WHERE `id` = ? "
_, err = db.Exec(sqlss, counttime, phps, userInfo["uid"], user, timecount, shopValue["id"])
if err != nil {
fmt.Println("开奖失败:" err.Error())
continue
}
//更新中奖者信息
db.Exec("UPDATE `" dbPrefix "member_go_record` SET `huode` = ? where `id` = ? ", timecount, userBuyInfo["id"])
//通知开奖
res, _ := http.Get(notify "http://www.haolizi.net/" gosql.StringDefault(shopValue["id"], ""))
if res != nil {
res.Body.Close()
}
}
}

(来源:网络整理)

织梦二维码生成器
已推荐
0
  • 凡本网注明"来源:的所有作品,版权均属于中,转载请必须注明中,http://www.xthosp.com。违反者本网将追究相关法律责任。
  • 本网转载并注明自其它来源的作品,目的在于传递更多信息,并不代表本网赞同其观点或证实其内容的真实性,不承担此类作品侵权行为的直接责任及连带责任。其他媒体、网站或个人从本网转载时,必须保留本网注明的作品来源,并自负版权等法律责任。
  • 如涉及作品内容、版权等问题,请在作品发表之日起一周内与本网联系,否则视为放弃相关权利。






图说新闻

更多>>
八闽福建麻将电脑版下载v1.1.2 官方pc版

八闽福建麻将电脑版下载v1.1.2 官方pc版



返回首页