Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. function getCookie(name) {
  2. const matches = document.cookie
  3. .match(new RegExp(`(?:^|; )${name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1')}=([^;]*)`));
  4. return matches ? decodeURIComponent(matches[1]) : undefined;
  5. };
  6.  
  7.  
  8. var generateBindId = async (materialId, specId, profileId) => {
  9. var profileIdfromCookie = getCookie('profile_id');
  10. // var serviceAdress = `https://dnevnik-test.mos.ru/exam/player/api/binding?pid=${profileId || profileIdfromCookie}`;
  11. var serviceAdress = `https://uchebnik-stable.mos.ru/exam/player/api/binding?pid=${profileId || profileIdfromCookie}`;
  12.  
  13.  
  14. const data = {
  15. material_id: materialId,
  16. material_type: 'homework',
  17. test_material_id: specId,
  18. test_material_type: 'spec',
  19. };
  20.  
  21. const options = {
  22. 'method': 'POST',
  23. 'credentials': 'include',
  24. 'headers': {
  25. 'accept': 'application/json;charset=UTF-8',
  26. 'content-type': 'application/json',
  27. },
  28. 'body': JSON.stringify(data),
  29. 'referrerPolicy': 'no-referrer-when-downgrade',
  30. 'mode': 'cors',
  31. };
  32.  
  33. await fetch(
  34. serviceAdress,
  35. options
  36. ).then((res) => res.json())
  37. .then((res) => {
  38. console.log({ res });
  39. console.log('binding_id',res.binding_id);
  40. generateGroupId(res.binding_id);
  41. });
  42. console.log({ generateBindId });
  43. };
  44.  
  45. generateBindId(63444709, 70193, 5787352)
  46.  
  47. var generateGroupId = async (bindingId) => {
  48. const profileIdfromCookie = getCookie('profile_id');
  49. const serviceAdress = `https://uchebnik-stable.mos.ru/exam/rest/secure/testplayer/group?pid=${profileIdfromCookie}`;
  50.  
  51. const data = {
  52. test_type: 'control_test',
  53. generation_context_type: 'homework',
  54. generation_by_id: bindingId,
  55. can_reanswer: true,
  56. can_see_result: true,
  57. can_switch: true,
  58. immediate_result: false,
  59. variants_count: 1
  60. };
  61.  
  62. const options = {
  63. 'method': 'POST',
  64. 'credentials': 'include',
  65. 'headers': {
  66. 'accept': 'application/json;charset=UTF-8',
  67. 'content-type': 'application/json',
  68. },
  69. 'body': JSON.stringify(data),
  70. 'referrerPolicy': 'no-referrer-when-downgrade',
  71. 'mode': 'cors',
  72. };
  73.  
  74. await fetch(serviceAdress, options)
  75. .then((res) => res.json())
  76. .then((res) => {
  77. console.log('group id', res.id);
  78. // const path = `https://uchebnik-stable.mos.ru/exam/test/homework/${bindingId}`;
  79. // console.log({ path });
  80. // window.open(path, '_blank');
  81. });
  82. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement