Java获取腾讯分分彩程序

这几天刚好需要做腾讯时时彩,于是着手研究了下,是以每分钟腾讯QQ的在线用户人数生成一个五位数字作为腾讯分分彩当期的开奖号码;计算公式如下:

万位数:依照官方公布当时的在线人数数字之总和,再取尾数;(例如:线上人数227415242人,则为2+2+7+4+1+5+2+4+2=29,取尾数9,因此万位为9)

后四码:依照官方公布当时的在线人数,取末位为千百个十这四个号码;(例如线上人数227415242人,则末4码5242)

下面是Java代码:

package org.framework.task.lottery;

import com.alibaba.fastjson.JSONObject;
import org.framework.constants.LotteryTemp;
import org.framework.core.http.HttpClient;
import org.framework.core.util.DateUtils;
import org.framework.web.entity.ProductQuery;
import org.framework.web.service.LotteryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Calendar;
import java.util.Date;

/**
 * @author : [email protected]
 * @date : 2018/1/17  下午4:05
 */
@Component
public class TencentTask {
    private Logger logger = LoggerFactory.getLogger(TencentTask.class);

    private static final String BASE_URL = "http://mma.qq.com/cgi-bin/im/online";


    @Autowired
    public LotteryService lotteryService;
    @Autowired
    private HttpClient httpClient;

    @Value("${product}")
    private String product;

    @Scheduled(cron = "0/5 * * * * ?")
    public void lotteryProc() throws IOException, InterruptedException {
        if ("false".equals(product)) {
            return;
        }
        String lotteryNo = "";
        String dateTime = DateUtils.getDate(DateUtils.YYYY_MMDD);
        Calendar calendar = Calendar.getInstance();
        int minute = calendar.get(Calendar.HOUR_OF_DAY) * 60 + calendar.get(Calendar.MINUTE);
        if (calendar.get(Calendar.SECOND) == 0) {
            return;
        }
        /**
         * 0 - 1440
         */
        if (minute < 10) {
            lotteryNo = DateUtils.getDate(DateUtils.YYYY_MMDD, -1) + "1440";
        } else {
            lotteryNo = dateTime + getNums(minute);
        }
        /**
         * 采集数据
         */
        String text = httpClient.getExchange(BASE_URL, null);
        JSONObject jsonObject = JSONObject.parseObject(text.substring(text.indexOf("(") + 1, text.indexOf(")")));
        int current = jsonObject.getInteger("c");
        int[] array = new int[String.valueOf(current).length()];
        int sum = 0;
        for (int i = 0; i < array.length; i++) {
            array[i] = Integer.valueOf(String.valueOf(current).substring(i, i + 1));
            sum = sum + array[i];
        }
        int length = array.length;
        //最高位数
        int height = sum - sum / 10 * 10;
        //号码
        String lotteryNums = height + "" + array[length - 4] + "" + array[length - 3] + "" + array[length - 2] + "" + array[length - 1];

        ProductQuery productQuery = new ProductQuery();
        productQuery.setLotteryNo(lotteryNo);
        productQuery.setLotteryNums(lotteryNums);
        productQuery.setSpell(LotteryTemp.FFCQQ);
        productQuery.setUts(new Date());
        productQuery.setFrom(4);
        lotteryService.updateProductQuery(productQuery);

    }


    String getNums(int second) {
        if (second < 10) {
            return "000" + second;
        }
        if (second < 100) {
            return "00" + second;
        }
        if (second < 1000) {
            return "0" + second;
        }
        return String.valueOf(second);
    }

}

猜你喜欢

转载自blog.csdn.net/caipiaocloud/article/details/79096952