diff --git a/module/oc_telegram_shop/upload/oc_telegram_shop/framework/Telegram/SignatureValidator.php b/module/oc_telegram_shop/upload/oc_telegram_shop/framework/Telegram/SignatureValidator.php index 1f475bc..119096e 100755 --- a/module/oc_telegram_shop/upload/oc_telegram_shop/framework/Telegram/SignatureValidator.php +++ b/module/oc_telegram_shop/upload/oc_telegram_shop/framework/Telegram/SignatureValidator.php @@ -19,7 +19,7 @@ class SignatureValidator return; } - $initDataString = rawurldecode($request->header('X-Telegram-Initdata')); + $initDataString = base64_decode($request->header('X-Telegram-Initdata')); if (! $initDataString) { throw new TelegramInvalidSignatureException('Invalid Telegram signature!'); @@ -78,13 +78,4 @@ class SignatureValidator return implode(PHP_EOL, $array); } - - public function ensureUserWantsToReceiveMessages($request): void - { - $initDataString = rawurldecode($request->header('X-Telegram-Initdata')); - - if (! $initDataString) { - throw new TelegramInvalidSignatureException('Invalid Telegram signature!'); - } - } } diff --git a/module/oc_telegram_shop/upload/oc_telegram_shop/framework/Telegram/TelegramService.php b/module/oc_telegram_shop/upload/oc_telegram_shop/framework/Telegram/TelegramService.php index b331416..4aab4e4 100755 --- a/module/oc_telegram_shop/upload/oc_telegram_shop/framework/Telegram/TelegramService.php +++ b/module/oc_telegram_shop/upload/oc_telegram_shop/framework/Telegram/TelegramService.php @@ -3,9 +3,6 @@ namespace Openguru\OpenCartFramework\Telegram; use GuzzleHttp\Client; -use JsonException; -use Openguru\OpenCartFramework\Application; -use Openguru\OpenCartFramework\Http\Request; use Openguru\OpenCartFramework\Logger\Logger; class TelegramService @@ -68,29 +65,4 @@ class TelegramService return $this; } - - private function ensureUserWantsToReceiveMessages(): bool - { - /** @var Request $request */ - $request = Application::getInstance()->get(Request::class); - - $initDataString = $request->header('X-Telegram-Initdata'); - - if (! $initDataString) { - return false; - } - - parse_str($initDataString, $initData); - if (! isset($initData['user'])) { - return false; - } - - try { - $user = json_decode($initData['user'], true, 512, JSON_THROW_ON_ERROR); - return ! empty($user['allows_write_to_pm']); - } catch (JsonException $e) { - $this->logger->logException($e); - return false; - } - } } diff --git a/spa/src/components/ProductsList.vue b/spa/src/components/ProductsList.vue index 747d909..41e1e0b 100644 --- a/spa/src/components/ProductsList.vue +++ b/spa/src/components/ProductsList.vue @@ -17,6 +17,7 @@

{{ product.name }}

{{ product.price }}

+
@@ -57,6 +58,7 @@ const route = useRoute(); const categoryId = route.params.category_id ?? null; const productsStore = useProductsStore(); const settings = useSettingsStore(); +const bottom = ref(null); function haptic() { window.Telegram.WebApp.HapticFeedback.selectionChanged(); @@ -89,9 +91,9 @@ async function loadMore() { } useInfiniteScroll( - window, + bottom, loadMore, - {distance: 500} + {distance: 1000} ) watch(() => route.params.id, async newId => { diff --git a/spa/src/utils/ftch.js b/spa/src/utils/ftch.js index 648da3b..7b7034a 100644 --- a/spa/src/utils/ftch.js +++ b/spa/src/utils/ftch.js @@ -2,15 +2,20 @@ import {ofetch} from "ofetch"; const BASE_URL = '/'; +function encodeBase64Unicode(str) { + return btoa(new TextEncoder().encode(str).reduce((data, byte) => data + String.fromCharCode(byte), '')); +} + export const apiFetch = ofetch.create({ throwHttpErrors: true, onRequest({request, options}) { const data = window.Telegram?.WebApp?.initData; if (data) { + const encoded = encodeBase64Unicode(data); options.headers = { ...options.headers, - 'X-Telegram-InitData': data, + 'X-Telegram-InitData': encoded, } } },