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.
159 lines
4.4 KiB
159 lines
4.4 KiB
5 months ago
|
<?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("6666000109133323");
|
||
|
// 交易金额
|
||
|
$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();
|
||
|
// 收银台样式
|
||
|
// $extendInfoMap["style_id"]= "";
|
||
|
// 是否延迟交易
|
||
|
$extendInfoMap["delay_acct_flag"]= "N";
|
||
|
// 分账对象
|
||
|
$extendInfoMap["acct_split_bunch"]= getAcctSplitBunch();
|
||
|
// 交易失效时间
|
||
|
// $extendInfoMap["time_expire"]= "";
|
||
|
// 业务信息
|
||
|
$extendInfoMap["biz_info"]= getBizInfo();
|
||
|
// 交易异步通知地址
|
||
|
$extendInfoMap["notify_url"]= "https://callback.service.com/xx";
|
||
|
// 使用类型
|
||
|
// $extendInfoMap["usage_type"]= "";
|
||
|
// 交易类型
|
||
|
// $extendInfoMap["trans_type"]= "";
|
||
|
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"] = "PROJECTID2023101225142567";
|
||
|
// 请求类型P:PC页面版,默认:P;M:H5页面版;指定交易类型时必填;<font color="green">示例值:M</font>
|
||
|
// $dto["request_type"] = "test";
|
||
|
// 商户私有信息
|
||
|
$dto["private_info"] = "商户私有信息test";
|
||
|
// 回调地址
|
||
|
$dto["callback_url"] = "https://paas.huifu.com";
|
||
|
|
||
|
return json_encode($dto,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
|
||
|
}
|
||
|
|
||
|
function getPayerCheckAli() {
|
||
|
$dto = array();
|
||
|
// 是否提供校验身份信息
|
||
|
$dto["need_check_info"] = "T";
|
||
|
// 允许的最小买家年龄
|
||
|
$dto["min_age"] = "12";
|
||
|
// 是否强制校验付款人身份信息
|
||
|
$dto["fix_buyer"] = "F";
|
||
|
|
||
|
return $dto;
|
||
|
}
|
||
|
|
||
|
function getPayerCheckWx() {
|
||
|
$dto = array();
|
||
|
// 指定支付者
|
||
|
$dto["limit_payer"] = "ADULT";
|
||
|
// 微信实名验证
|
||
|
$dto["real_name_flag"] = "Y";
|
||
|
|
||
|
return $dto;
|
||
|
}
|
||
|
|
||
|
function getPersonPayer() {
|
||
|
$dto = array();
|
||
|
// 姓名
|
||
|
$dto["name"] = "张三";
|
||
|
// 证件类型
|
||
|
$dto["cert_type"] = "IDENTITY_CARD";
|
||
|
// 证件号
|
||
|
$dto["cert_no"] = "OLOxrl809XmVIMmPRTIyIpJHxi4HFMJNmxGz1nhZAtps9xPEVDysU3UZPBZfsNFLFcXEMENPsJ+tymbYt42dNQ+76hyEtx+qz0BQhU8SKV8H5itrI4kaXpaJf+sV8OewrJkhDidPdz01vqMEDQRhaMnNwl8snHZxDdpu7HVUz5JwsLYfBbZP2Q4CZpVWS3NunQahZ8zHQ+8EhvYVH1vE7f/M6nJt1/4GoHz9C/UnuYudV0S2uBhlywbX+YkRGNMl/oz5+UNeMDA2jqhtTreSD4+w7S82L53rqKsAbosodOPo4OAMZk4/0QOH5LDbqFByVM97mzHfw7z+Tx/dsXJ8QQ==";
|
||
|
// 手机号
|
||
|
$dto["mobile"] = "15012345678";
|
||
|
|
||
|
return $dto;
|
||
|
}
|
||
|
|
||
|
function getBizInfo() {
|
||
|
$dto = array();
|
||
|
// 付款人验证(支付宝)
|
||
|
$dto["payer_check_ali"] = getPayerCheckAli();
|
||
|
// 付款人验证(微信)
|
||
|
$dto["payer_check_wx"] = getPayerCheckWx();
|
||
|
// 个人付款人信息
|
||
|
$dto["person_payer"] = getPersonPayer();
|
||
|
|
||
|
return json_encode($dto,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
|
||
|
}
|
||
|
|
||
|
|