Всем привет! Пытаюсь подключить на сайт оплату в рассрочку от СберБанка. Дошел до отправки данных на сервис Сбера. Нужно для теста отправить в POST запросе следующие тестовые данные: Код (Text): amount=3200000¤cy=643&language=ru&orderNumber=1590585951&password=testPwd&returnUrl=http://www.google.com&userName=login&description=INSTALLMENT&sessionTimeoutSecs=1200&orderBundle= { "cartItems": { "items": [{ "agentInterest": { "interestType": "3", "interestValue": "2" }, "discount": { "discountType": "percent", "discountValue": "5" }, "itemAmount": "3000000", "itemCode": "123", "itemCurrency": "643", "itemDetails": {}, "itemPrice": "3000000", "name": "position_1", "positionId": "1", "quantity": { "measure": "kg", "value": 1 } }, { "agentInterest": { "interestType": "3", "interestValue": "2" }, "discount": { "discountType": "percent", "discountValue": "5" }, "itemAmount": "100000", "itemCode": "456", "itemCurrency": "643", "itemDetails": {}, "itemPrice": "50000", "name": "position_2", "positionId": "2", "quantity": { "measure": ".", "value": 2 } }, { "agentInterest": { "interestType": "3", "interestValue": "2" }, "discount": { "discountType": "percent", "discountValue": "5" }, "itemAmount": "100000", "itemCode": "789", "itemCurrency": "643", "itemDetails": }, "itemPrice": "100000", "name": "position_3", "positionId": "3", "quantity": { "measure": ".", "value": 1 } ] }, "customerDetails": { "contact": "Ivan", "deliveryInfo": { "city": "Moscow", "country": "RU", "deliveryType": "courier", "postAddress": " , 1" }, "email": "mail@bpcbt.com", "phone": "79032177751" }, "installments": { "productID": "10", "productType": "CREDIT", "rightTerms": [3,5] }, "orderCreationDate": "2019-02-04T13:51:00" }&jsonParams= { "phone": "79262440101" }&additionalOfdParams= { "agent_info.type": "7", "agent_info.paying.operation": " ", "agent_info.paying.phones": "+71111111111", "agent_info.paymentsOperator.phones": "+72222222222", "agent_info.MTOperator.address": " ", "agent_info.MTOperator.inn": "169910020020", "agent_info.MTOperator.name": " ", "agent_info.MTOperator.phones": "+73333333333", "supplier_info.phones": "+74444444444", "additional_check_props": "09090909", "additional_user_props.name": " ", "additional_user_props.value": " ", "cashier": " " } Подскажите, пожалуйста, как отправить это в запросе POST ?
Я отправляю через curl, у меня есть образец, который сам "делал", но там адрес типа: https://site.ru/api/push.json?id=233&type=465 А отправляю кодом: Код (Text): $curl = curl_init(https://site.ru/api/push.json?id=233&type=465); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, 30); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); $result = json_decode(curl_exec($curl), true); curl_close($curl); Где все, что мне нужно в массиве $data в формате json. А в этом случае с банком адрес типа (это все взято из их мануала): https://3dsec.sberbank.ru/sbercredi...r=1&returnUrl=http://yoursite.com&jsonParams= {"phone": "+79268936532"}&sessionTimeoutSecs=86400&orderBundle={"cartItems":{"items": [{ и пошло поехало, а в конце снова параметр } &installments={"productID":"10","productType":"INSTALLMENT"}} Т.е. в адресе не только параметры через амперсанд перечислены, а еще и данные в формате json. Вот как это передать? Я ума не приложу ...
Что то вроде: Код (Text): $params = array( //массив параметров ); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params)); $result = json_decode(curl_exec($curl), true);
Т.е. взять все параметры из адресной строки, засунуть из в массив, перевести в json и отправить... Тоже так думаю, задал такой вопрос в поддержку, жду ответа.
Там есть возможность получения тестовых данных? Самая лучшая проверка - это увидеть результат запроса.
Да, в начале все делается в тестовой среде. curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params)); - можно исключить, если $params передавать не буду?
Разобрался, если кому надо: Код (Text): $url = 'https://...'; $data = 'amount=3200000&dummy=true¤cy=643&language=ru&orderNumber=288_004&password=bb4FL52j&returnUrl=https://yandex.ru/&failUrl=https://www.google.ru/&userName=proyagodki-credit-api&description=INSTALLMENT&sessionTimeoutSecs=1200&orderBundle={"cartItems":{"items":[{"agentInterest":{"interestType":"3","interestValue":"2"},"discount":{"discountType":"percent","discountValue":"5"},"itemAmount":"3000000","itemCode":"123","itemCurrency":"643","itemDetails":{},"itemPrice":"3000000","name":"position_1","positionId":"1","quantity":{"measure":"шт","value":1}},{"agentInterest":{"interestType":"3","interestValue":"2"},"discount":{"discountType":"percent","discountValue":"5"},"itemAmount":"100000","itemCode":"456","itemCurrency":"643","itemDetails":{},"itemPrice":"50000","name":"position_2","positionId":"2","quantity":{"measure":"шт.","value":2}},{"agentInterest":{"interestType":"3","interestValue":"2"},"discount":{"discountType":"percent","discountValue":"5"},"itemAmount":"100000","itemCode":"789","itemCurrency":"643","itemDetails":{},"itemPrice":"100000","name":"position_3","positionId":"3","quantity":{"measure":"шт.","value":1}}]},"customerDetails":{"contact":"Ivan","deliveryInfo":{"city":"Moscow","country":"RU","deliveryType":"courier","postAddress":"Адресдоставки1"},"email":"test@bpcbt.com","phone":"79032177777"},"installments":{"productID":"10","productType":"INSTALLMENT","rightTerms":[3,5]},"orderCreationDate":"2019-02-04T13:51:00"}&jsonParams={"phone":"79262440101"}'; // В $data данные, которые отправляем $curl = curl_init($url); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, $data); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_TIMEOUT, 30); $result = json_decode(curl_exec($curl), true); curl_close($curl); var_dump($result);
@don.bidon просто первоначальная идея была закодировать исходный массив в json функцией encode_json, а тут $data это строка
Да, строка, где параметр=значение в перемешку с параметр=json (все в куче одной строкой) отправляются в POST. --- Добавлено --- На том конце закодированное в json не принимают, только такой вариант разбирают.
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); $data - обычный массив. PHP: curl_setopt - Manual (искать описание CURLOPT_POSTFIELDS) Если хотите строку - PHP: urlencode - Manual вам в помощь.