2,348
社区成员




// lottery project main.go
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/url"
)
const (
key = "×××××××××××××××××××××××××××××××××××××××××××××××××"
lottery_id = "ssq"
)
func main() {
lotteryNum := [2]string{"04,11,18,19,26,32@04", "01,05,07,12,23,25@03"}
for index, value := range lotteryNum {
jsonStr := queryLotteryResult(value)
var dataMap map[string]interface{}
if err := json.Unmarshal([]byte(jsonStr), &dataMap); err != nil {
fmt.Println(err)
}
//fmt.Println(dataMap)
result, ok := dataMap["result"]
//fmt.Println(result)
if ok == true {
if result == nil {
fmt.Printf("查询失败")
} else {
isPrize := result.(map[string]interface{})["is_prize"]
realRes := result.(map[string]interface{})["real_lottery_res"]
lotteryDate := result.(map[string]interface{})["lottery_date"]
fmt.Println("开奖时间:", lotteryDate)
fmt.Println("当期中奖号码:", realRes)
if v := isPrize.(string); v == "0" {
fmt.Printf("查询第%d个号码[%s],结果:%s \n", index+1, value, "未中奖")
} else {
fmt.Printf("查询第%d个号码[%s],结果:%s \n", index+1, value, "中奖")
prizeResult := result.(map[string]interface{})["lottery_prize"]
//fmt.Println(prizeResult)
for _, value := range prizeResult.([]interface{}) {
name := value.(map[string]interface{})["prize_name"]
money := value.(map[string]interface{})["prize_money"]
fmt.Printf("压中%s ,金额%s \n", name, money)
}
}
}
} else {
fmt.Println("不能取值")
}
fmt.Println("======================================================================")
}
}
func queryLotteryResult(lotteryNum string) (reslut string) {
clusterinfo := url.Values{}
clusterinfo.Add("key", key)
clusterinfo.Add("lottery_id", lottery_id)
clusterinfo.Add("lottery_res", lotteryNum)
resp, err := http.PostForm("http://apis.juhe.cn/lottery/bonus", clusterinfo)
if err != nil {
fmt.Println("请求错误", err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("解析错误", err)
}
//fmt.Println(string(body))
return string(body)
}