php对接建行app内部使用h5网页支付 代码示例 BRANCHID PLATMCTID
以下是一个示例代码,用于在PHP中对接建行App内部使用H5网页支付。
<?php
// 请求参数
$branchId = 'xxx'; // 商户号
$platMctId = 'xxx'; // 平台商户号
$orderId = 'xxx'; // 订单号
$orderAmt = 'xxx'; // 订单金额(分)
$backUrl = 'xxx'; // 后台通知地址
// 构建请求参数数组
$params = array(
'branchId' => $branchId,
'platMctId' => $platMctId,
'orderId' => $orderId,
'orderAmt' => $orderAmt,
'backUrl' => $backUrl,
);
// 构建请求URL
$url = 'https://openapi.ccb.com/ccbopenapi/oauth/token?grant_type=client_credentials';
// 发送请求获取access_token
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/x-www-form-urlencoded',
'Authorization: Basic ' . base64_encode($branchId . ':' . $platMctId),
));
$response = curl_exec($ch);
curl_close($ch);
// 解析响应获取access_token
$responseData = json_decode($response, true);
$accessToken = $responseData['access_token'];
// 构建支付URL
$payUrl = 'https://openapi.ccb.com/ccbopenapi/payment/pay/onlineH5?access_token=' . $accessToken;
// 发送支付请求
$ch = curl_init($payUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
));
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($params));
$response = curl_exec($ch);
curl_close($ch);
// 解析响应获取支付页面URL
$responseData = json_decode($response, true);
$payPageUrl = $responseData['data']['payPageUrl'];
// 跳转到支付页面
header('Location: ' . $payPageUrl);
exit;
?>
在上述代码中,你需要将以下变量替换为你自己的实际值:
$branchId:商户号,由建行提供。$platMctId:平台商户号,由建行提供。$orderId:订单号,你自己定义的唯一标识。$orderAmt:订单金额,单位为分。$backUrl:后台通知地址,建行支付成功后会向该地址发送通知。
代码中的过程如下:
- 构建请求URL,发送请求获取access_token。
- 解析响应获取access_token。
- 构建支付URL。
- 发送支付请求,获取支付页面URL。
- 跳转到支付页面。
请注意,以上代码仅为示例,实际使用时还需要根据建行提供的接口文档进行相应的参数处理和验签操作
原文地址: https://www.cveoy.top/t/topic/iTst 著作权归作者所有。请勿转载和采集!