php - 在 BlueSnap 支付网关中如何创建托管支付字段令牌请求
问题描述
curl -v -X POST https://ws.bluesnap.com/services/2/payment-fields-tokens \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=' \
-d '
在 php 中如何在 curl 发布和显示位置 url 中描述上述代码。
解决方案
$api_usernam = bluesnap::$username ;
$api_password = bluesnap::$password ;
$auth_token = base64_encode( $api_usernam . ':' . $api_password );
$header = array("Authorization: Basic ".$auth_token."", "Content-type: application/json");
$url = "https://sandbox.bluesnap.com/services/2/payment-fields-tokens"; //change the URL on production
//start request
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header );
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$resp = curl_exec($ch);
curl_close($ch);
list($Headers, $Response)=explode("\r\n\r\n",$resp, 2);
$Headers=explode("\n", $Headers);
foreach($Headers as $Header)
{
if (stripos($Header, "Location")!==false)
{
$Token=trim(str_replace("Location: ", "", $Header));
}
}
$Token = substr(strrchr( $Token, '/' ),1);
// test if secuss
return $Token;
}
推荐阅读
- google-cloud-pubsublite - PubSub Lite:确认当前积压的所有消息
- django - 如何在同一个 Django 应用程序中配置两个具有不同表的数据库?
- typescript - TypeScript - 当 getter/setter 之一被移除时,抽象类 getter 和 setter 实现不会抱怨
- javascript - 如何将图像变成按钮?
- node.js - 多个 POST 请求的幂等性(条带化)
- r - Pentaho,R Executor 插入数据库
- sql - AWS DR 解决方案 - 自动故障转移而不是手动?
- python - 如何在 Python 中每 24 小时调用一次函数?我目前正在使用 Threading 同时运行 Flask 服务器和函数
- asp.net - 如何使用asp.net mvc为facebook或其他社交媒体网站设置cookie过期时间?
- hibernate - Hibernate envers :: 使用 AuditReader 从审计表中获取关联实体(具有一对多关系)的方法是什么?