Skip to content

Instantly share code, notes, and snippets.

@albeebe
Last active March 12, 2022 20:22
Show Gist options
  • Save albeebe/422988fa63a9a46d5482cca2bca33a26 to your computer and use it in GitHub Desktop.
Save albeebe/422988fa63a9a46d5482cca2bca33a26 to your computer and use it in GitHub Desktop.
This PHP script will pull the latest Keno603 draws from the NH Lottery API
<?php
/*
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org>
*/
##########################################################################
# #
# This PHP script will pull the latest Keno603 draws from the NH Lottery #
# #
# Created by Al Beebe (albeebe.com) on March 12, 2022 #
# #
##########################################################################
// Fetch a temporary auth token for interacting with the APIs
function getAuthToken() {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://apisolutions.my603rewards.com/1.0/Authentication/Login');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"userName\":\"mobilepublic@mtllc.com\",\"password\":\"R7V5Sz8@\",\"refreshToken\":\"\"}");
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = 'Host: apisolutions.my603rewards.com';
$headers[] = 'Content-Type: application/json-patch+json';
$headers[] = 'Accept-Language: en-US,en;q=0.9';
$headers[] = 'Accept: */*';
$headers[] = 'User-Agent: Appcelerator Titanium/0.0.0 (iPhone/15.1.1; iOS; en_US;)';
$headers[] = 'X-Titanium-Id: 265d6dc5-9e8b-481e-84a2-6e8a9776cc6d';
$headers[] = 'X-Requested-With: XMLHttpRequest';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
panic("Error: ".curl_error($ch));
}
curl_close($ch);
$response = json_decode($result, true);
$authToken = $response["data"]["token"];
if (strlen($authToken) == 0) {
panic("No token was returned");
}
return $authToken;
}
// Get the recent KENO draws
function getRecentKenoDraws($authToken) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://apisolutions.my603rewards.com/1.0/Games/DrawGames/Keno/GetGameInformation');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
$headers = array();
$headers[] = 'Host: apisolutions.my603rewards.com';
$headers[] = 'Accept-Language: en-US,en;q=0.9';
$headers[] = 'Accept: */*';
$headers[] = 'User-Agent: Appcelerator Titanium/0.0.0 (iPhone/15.1.1; iOS; en_US;)';
$headers[] = 'Authorization: Bearer '.$authToken;
$headers[] = 'X-Titanium-Id: 265d6dc5-9e8b-481e-84a2-6e8a9776cc6d';
$headers[] = 'X-Requested-With: XMLHttpRequest';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
panic("Error: ".curl_error($ch));
}
curl_close($ch);
$response = json_decode($result, true);
// Parse the draws
$results = array();
foreach ($response["data"]["draws"] as $draw) {
$result = array();
$result["id"] = $draw["externalDrawId"];
$result["date"] = date("c", strtotime($draw["drawDate"]));
$result["plus"] = "?";
$result["balls"] = array();
foreach ($draw["numbers"] as $number) {
if ($number["position"] == 21) {
$result["plus"] = $number["value"];
} else {
array_push($result["balls"], $number["value"]);
}
}
array_push($results, $result);
}
return $results;
}
// Step 1: Get an auth token for interacting with the API
$authToken = getAuthToken();
// Step 2: Get the recent draws
$output = array();
$output["results"] = getRecentKenoDraws($authToken);
// Step 3: Output the response in JSON format
header('Content-Type: application/json; charset=utf-8');
print(json_encode($output, JSON_PRETTY_PRINT));
/*
Sample Output
{
"results": [
{
"id": 253179,
"date": "2022-03-12T15:15:00-06:00",
"plus": 3,
"balls": [
43,
80,
57,
20,
15,
3,
11,
13,
21,
64,
19,
39,
26,
10,
61,
6,
2,
77,
58,
44
]
},
{
"id": 253178,
"date": "2022-03-12T15:10:00-06:00",
"plus": 1,
"balls": [
34,
39,
14,
53,
44,
59,
6,
64,
41,
49,
56,
71,
43,
70,
31,
10,
67,
47,
29,
57
]
},
{
"id": 253177,
"date": "2022-03-12T15:05:00-06:00",
"plus": 3,
"balls": [
52,
4,
28,
76,
60,
27,
3,
35,
2,
79,
17,
29,
57,
67,
14,
11,
63,
42,
40,
9
]
},
{
"id": 253176,
"date": "2022-03-12T15:00:00-06:00",
"plus": 1,
"balls": [
70,
69,
22,
13,
34,
42,
23,
12,
27,
59,
17,
54,
15,
43,
16,
28,
73,
62,
60,
44
]
},
{
"id": 253175,
"date": "2022-03-12T14:55:00-06:00",
"plus": 3,
"balls": [
59,
33,
48,
20,
55,
64,
4,
1,
39,
61,
74,
23,
56,
22,
6,
24,
50,
35,
37,
66
]
},
{
"id": 253174,
"date": "2022-03-12T14:50:00-06:00",
"plus": 3,
"balls": [
75,
34,
48,
51,
47,
37,
26,
80,
17,
13,
62,
67,
64,
23,
9,
43,
10,
53,
33,
24
]
},
{
"id": 253173,
"date": "2022-03-12T14:45:00-06:00",
"plus": 5,
"balls": [
24,
29,
20,
2,
41,
57,
55,
66,
52,
54,
10,
13,
70,
31,
80,
40,
34,
62,
9,
35
]
},
{
"id": 253172,
"date": "2022-03-12T14:40:00-06:00",
"plus": 3,
"balls": [
68,
56,
3,
35,
72,
9,
51,
64,
28,
67,
79,
2,
70,
1,
39,
76,
49,
65,
29,
43
]
},
{
"id": 253171,
"date": "2022-03-12T14:35:00-06:00",
"plus": 1,
"balls": [
6,
50,
39,
25,
65,
60,
51,
54,
45,
66,
18,
22,
76,
11,
40,
30,
78,
10,
7,
59
]
},
{
"id": 253170,
"date": "2022-03-12T14:30:00-06:00",
"plus": 4,
"balls": [
65,
31,
23,
33,
56,
17,
69,
13,
29,
6,
44,
25,
1,
36,
74,
71,
63,
77,
68,
15
]
}
]
}
*/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment