curl Razorpay集成,问题:请提供您的API密钥以进行身份验证

ulmd4ohb  于 2023-11-19  发布在  其他
关注(0)|答案(2)|浏览(147)

我正在将此cURL代码转换为JavaScript。

curl -u <YOUR_KEY_ID>:<YOUR_KEY_SECRET> \
-X POST https://api.razorpay.com/v1/customers \
-H "Content-Type: application/json" \
-d '{
  "name": "Gaurav Kumar1"
  "email": "[email protected]"
  "contact": "9123456781"
}'

个字符
当我在Postman中检查这个时,它会给出正确的响应。但是当我在我的网站中使用这个时,它会给出错误。
POST https://api.razorpay.com/v1/customers 401(Unauthorized)data:error:{code:“BAD_REQUEST_ERROR”,description:“Please provide your API key for authentication purposes."}

vyswwuz2

vyswwuz21#

你错过了头Authorization,看看这个,我用jQuery Ajax为它,我从 Postman 本身得到的代码。

var settings = {
  "async": true,
  "crossDomain": true,
  "url": "https://api.razorpay.com/v1/customers",
  "method": "POST",
  "headers": {
    "Content-Type": "application/x-www-form-urlencoded",
    "Authorization": "Basic cnpwX2xpdmVfa2V5OmFfbG9uZ19wYXNzd29yZA==",
    "User-Agent": "PostmanRuntime/7.13.0",
    "Accept": "*/*",
    "Cache-Control": "no-cache",
    "Postman-Token": "f1c3919b-d2b8-4646-8ce0-caa60f2dfc3a,9dd079e3-ddab-41a8-8b1d-5ac53c00e07b",
    "Host": "api.razorpay.com",
    "accept-encoding": "gzip, deflate",
    "content-length": "59",
    "Connection": "keep-alive",
    "cache-control": "no-cache"
  },
  "data": {
    "name": "Gaurav Kumar1",
    "email": "[email protected]",
    "contact": "9123456781"
  }
}

$.ajax(settings).done(function (response) {
  console.log(response);
});

字符串
请参考官方文档中生成授权密钥和密钥的步骤。
https://razorpay.com/docs/assets/images/generate-api-keys.gif
希望这对你有帮助:)


的数据

fquxozlt

fquxozlt2#

这是我的代码。它的工作完美
你必须通过以下方法对密钥和密钥进行编码:
key:key_secret
通过base64加密算法,
然后你将传递给你的授权令牌API>

fetch("https://api.razorpay.com/v1/orders", {
                 method: "POST",
                 headers: {
                   "Content-Type": "application/json",
                   Authorization: "Basic cnpwX3Rlc3RfMWNIbVVzREJRczhUVVY6WDRTRG95YVBqcHNTb3dac0JHQ29TdEs5",
                   Accept: "application/json",
                   "Cache-Control": "no-cache",
                   Host: "api.razorpay.com"
                 },
                 body: JSON.stringify({
                   amount: 50000,
                   currency: "INR",
                   receipt: "receipt#1",
                   payment_capture: 1
                 })
               })
                 .then(response => response.json())
                 .then(responseJson => {
                   console.log("responseJson", responseJson);
                   var order = responseJson;
                 });

字符串

相关问题