Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 KB | None | 0 0
  1. <?php
  2.  
  3. require "./core/config.php";
  4.  
  5. $secretKey = $UnitPay['secret_key'];
  6. $price = $UnitPay['price'];
  7.  
  8. function getSignature($method, $params, $secretKey)
  9. {
  10. ksort($params);
  11. unset($params['sign']);
  12. unset($params['signature']);
  13. array_push($params, $secretKey);
  14. array_unshift($params, $method);
  15.  
  16. return hash('sha256', join('{up}', $params));
  17. }
  18.  
  19. /**
  20. * Ошибочный ответ партнера
  21. *
  22. * @param $message
  23. */
  24. function responseError($message) {
  25. $error = array(
  26. "jsonrpc" => "2.0",
  27. "error" => array(
  28. "code" => -32000,
  29. "message" => $message
  30. ),
  31. 'id' => 1
  32. );
  33. echo json_encode($error); exit();
  34. }
  35.  
  36. /**
  37. * Успешный ответ партнера
  38. *
  39. * @param $message
  40. */
  41. function responseSuccess($message) {
  42. $success = array(
  43. "jsonrpc" => "2.0",
  44. "result" => array(
  45. "message" => $message
  46. ),
  47. 'id' => 1
  48. );
  49. echo json_encode($success); exit();
  50. }
  51.  
  52. if(isset($_GET['method'])) {
  53.  
  54. if($_GET['method']=='check') {
  55.  
  56. $params = $_GET['params'];
  57. $sign = $params['sign'];
  58. unset($params['sign']);
  59.  
  60. $db_json = (array)json_decode(file_get_contents('core/db/orders.db'));
  61. $db_json['orders'] = (array)$db_json['orders'];
  62.  
  63. $order = false;
  64.  
  65. foreach($db_json['orders'] as $row) {
  66. if($_GET['params']['account']==$row->{'id'}) {
  67. if($sign==md5(implode("",$params).$secretKey)) {
  68. $order = true;
  69. break;
  70. }
  71. }
  72. }
  73.  
  74. if($order) {
  75. echo '{"result": {"message":"Запрос успешно обработан"}}';
  76. } else {
  77. echo '{"error": {"message":"Заказ не найден!"}}';
  78. }
  79.  
  80. } elseif($_GET['method']=='pay') {
  81.  
  82. $params = $_GET['params'];
  83. $sign = $params['signature'];
  84.  
  85. $db_json = (array)json_decode(file_get_contents('core/db/orders.db'));
  86. $db_json['orders'] = (array)$db_json['orders'];
  87.  
  88. $order = -1;
  89.  
  90. foreach($db_json['orders'] as $k=>$row) {
  91. if($_GET['params']['account']==$row->{'id'}) {
  92. $order = $k;
  93. break;
  94. }
  95. }
  96.  
  97. $unitpayIp = array(
  98. '31.186.100.49',
  99. '178.132.203.105',
  100. '52.29.152.23',
  101. '52.19.56.234'
  102. );
  103.  
  104. if (!in_array($_SERVER["REMOTE_ADDR"], $unitpayIp)) {
  105. die('IP address Error');
  106. }
  107. if(getSignature($_GET['method'], $params, $secretKey) != $sign){
  108. responseError("Invalid signature.");
  109. }
  110.  
  111. if($order>-1) {
  112. require "./core/sql.class.php";
  113. $coin = $db_json['orders'][$order]->{'sum'}/$price;
  114. $acc = $db_json['orders'][$order]->{'account'};
  115. $DB = selectServer($db_json['orders'][$order]->{'server'},$Sql);
  116. $current = $DB->FetchArray($DB->Query("SELECT VoteBonus FROM MEMB_INFO WHERE memb___id = '$acc'"));
  117. $current = (int)$current['VoteBonus'];
  118.  
  119. if($current<1) { $current = (int)$coin; } else { $current += (int)$coin; }
  120. $DB->Query("UPDATE MEMB_INFO SET VoteBonus = $current WHERE memb___id = '$acc'");
  121.  
  122. unset($db_json['orders'][$order]);
  123. $db_json['orders'] = array_values($db_json['orders']);
  124. file_put_contents('core/db/orders.db',json_encode($db_json));
  125. echo '{"result": {"message":"Запрос успешно обработан"}}';
  126. } else {
  127. echo '{"error": {"message":"Заказ не найден!"}}';
  128. }
  129.  
  130. }
  131.  
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement