You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
ymww_backend/vendor/huifurepo/dg-php-sdk/BsPayDemo/V2TradeHostingPaymentPreord...

102 lines
2.6 KiB

<?php
/**
* H5、PC预下单接口 - 示例
*
* @author sdk-generator
* @Description
*/
namespace BsPayDemo;
// 1. 资源及配置加载
require_once dirname(__FILE__) . "/loader.php";
require_once dirname(__FILE__). "/../BsPaySdk/request/V2TradeHostingPaymentPreorderH5Request.php";
use BsPaySdk\core\BsPayClient;
use BsPaySdk\request\V2TradeHostingPaymentPreorderH5Request;
// 2.组装请求参数
$request = new V2TradeHostingPaymentPreorderH5Request();
// 请求日期
$request->setReqDate(date("Ymd"));
// 请求流水号
$request->setReqSeqId(date("YmdHis").mt_rand());
// 商户号
$request->setHuifuId("6666000111546360");
// 交易金额
$request->setTransAmt("0.10");
// 商品描述
$request->setGoodsDesc("支付托管消费");
// 预下单类型
$request->setPreOrderType("1");
// 半支付托管扩展参数集合
$request->setHostingData(getHostingData());
// 设置非必填字段
$extendInfoMap = getExtendInfos();
$request->setExtendInfo($extendInfoMap);
// 3. 发起API调用
$client = new BsPayClient();
$result = $client->postRequest($request);
if (!$result || $result->isError()) { //失败处理
var_dump($result -> getErrorInfo());
} else { //成功处理
var_dump($result);
}
/**
* 非必填字段
*
*/
function getExtendInfos() {
// 设置非必填字段
$extendInfoMap = array();
// 收银台ID
$extendInfoMap["checkout_id"]= "";
// 是否延迟交易
$extendInfoMap["delay_acct_flag"]= "N";
// 分账对象
$extendInfoMap["acct_split_bunch"]= getAcctSplitBunch();
// 异步通知地址
$extendInfoMap["notify_url"]= "https://callback.service.com/xx";
// 交易失效时间
// $extendInfoMap["time_expire"]= "";
return $extendInfoMap;
}
function getAcctInfosRucan() {
$dto = array();
// 分账金额
$dto["div_amt"] = "0.08";
// 被分账方ID
$dto["huifu_id"] = "6666000111546360";
$dtoList = array();
array_push($dtoList, $dto);
return $dtoList;
}
function getAcctSplitBunch() {
$dto = array();
// 分账明细
$dto["acct_infos"] = getAcctInfosRucan();
return json_encode($dto,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
}
function getHostingData() {
$dto = array();
// 项目标题
$dto["project_title"] = "收银台标题";
// 半支付托管项目号
$dto["project_id"] = "PROJECTID2022032912492559";
// 商户私有信息
$dto["private_info"] = "商户私有信息test";
// 回调地址
$dto["callback_url"] = "https://paas.huifu.com";
return json_encode($dto,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
}