Skip to content

Instantly share code, notes, and snippets.

@notpushkin
Created June 8, 2020 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notpushkin/11cb1ada10110b2a526c8814f72c68a5 to your computer and use it in GitHub Desktop.
Save notpushkin/11cb1ada10110b2a526c8814f72c68a5 to your computer and use it in GitHub Desktop.
API для покупки билетов на электрички РЖД (протестировано на СЗППК)
import { stringify as qs } from "querystring";
const API_V3_1 = "https://mobile.svrpk.ru/v3.1/api.php";
const API_MOBILE_USERS = "https://mobile.svrpk.ru/mobile_users/api.php";
export default class PrigorodClient {
static getApiToken() {
return fetch(
API_V3_1 +
"?" +
qs({
action: "mobile_client",
result_type: "json",
device_id: "123456" // XXX: needs to be random?
})
).then(r => r.json());
}
static async init() {
return new PrigorodClient(await PrigorodClient.getApiToken());
}
constructor(token) {
this.token = token;
}
regionList() {
return fetch(
API_V3_1 +
"?" +
qs({
action: "regions_list",
key_client: this.token
})
).then(r => r.json());
}
stationList(ppkId) {
return fetch(
API_V3_1 +
"?" +
qs({
action: "station_list",
result_type: "json",
key_client: this.token,
ppk_id: ppkId
})
).then(r => r.json());
}
trainList(ppkId, fromId, toId, date) {
return fetch(
API_V3_1 +
"?" +
qs({
action: "train_list_by_range",
sort: "dep",
count: 200,
key_client: this.token,
result_type: json,
st1: fromId,
st2: toId,
date: date,
ppk_id: ppkId,
rand: 2313
})
).then(r => r.json());
}
buyTicket(
ppkId,
fromId,
toId,
date,
trainId,
price,
email,
phone,
passengerName, // F I O
passengerDoc, // 4444666666
isRound = false
) {
const discount = price * 0.05;
const item = `
<OrderN6
TripDate="${date}"
StationFrom="${fromId}"
StationTo="${toId}"
Train="${trainId}"
IsRound="${isRound ? "True" : "False"}"
>
<Pass
OrderType="0"
Lgota="0"
PassengerName="${passengerName}"
BuyPackagePlace="0"
BuyAnimalPlace="0"
BuyBikePlace="0"
DocumentType="0"
Document="${passengerDoc}"
TicketPrice="${price - discount}"
PackagePlaceCost="-1"
AnimalPlaceCost="-1"
BikePlaceCost="-1"
Discount="1"
DiscountName="Скидка СЗППК"
DiscountCost="${discount}"
/>
</OrderN6>
`;
return fetch(
API_V3_1 +
"?" +
qs({
action: "pay_n6",
result_type: "json",
mac: "0",
token: "",
email,
phone,
key_client: this.token,
ppk_id: ppkId,
hash_client: "",
item
})
).then(r => r.json());
}
getTicket(ppkId, orderId) {
return fetch(
API_V3_1 +
"?" +
qs({
action: "pay_success_n6",
order_id: orderId,
result_type: "json",
key_client: this.token,
ppk_id: ppkId,
hash_client: ""
})
).then(r => r.json());
}
myOrdersList() {
return fetch(
API_MOBILE_USERS +
"?" +
qs({
action: "ordersList",
hash: "",
key_client: this.token
})
).then(r => r.json());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment