V2TradeHostingPaymentPreorder.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * 聚合正扫接口 - 示例
  4. *
  5. * @author sdk-generator
  6. * @Description
  7. */
  8. namespace BsPayClassify;
  9. use BsPaySdk\core\BsPayClient;
  10. use BsPaySdk\request\V2TradeHostingPaymentPreorderWxRequest;
  11. class V2TradeHostingPaymentPreorder extends BaseInfo{
  12. public function pay($huifu_id, $pre_order_type = 3, $trans_amt, $goods_desc=''){
  13. // 2.组装请求参数
  14. $request = new V2TradeHostingPaymentPreorderWxRequest();
  15. // 预下单类型
  16. $request->setPreOrderType($pre_order_type);
  17. // 请求日期
  18. $request->setReqDate(date("Ymd"));
  19. // 请求流水号
  20. $request->setReqSeqId(date("YmdHis").mt_rand());
  21. // 商户号
  22. $request->setHuifuId($huifu_id);
  23. // 交易金额
  24. $request->setTransAmt($trans_amt);
  25. // 商品描述
  26. $request->setGoodsDesc($goods_desc);
  27. // 微信小程序扩展参数集合
  28. $request->setMiniappData($this->getMiniappDataRucan());
  29. // 设置非必填字段
  30. $extendInfoMap = $this->getExtendInfos();
  31. $request->setExtendInfo($extendInfoMap);
  32. // 3. 发起API调用
  33. $client = new BsPayClient();
  34. $result = $client->postRequest($request);
  35. return $result;
  36. }
  37. /**
  38. * 非必填字段
  39. *
  40. */
  41. function getExtendInfos() {
  42. // 设置非必填字段
  43. $extendInfoMap = array();
  44. // 收银台ID
  45. $extendInfoMap["checkout_id"]= "";
  46. // 是否延迟交易
  47. $extendInfoMap["delay_acct_flag"]= "N";
  48. // 分账对象
  49. $extendInfoMap["acct_split_bunch"]= $this->getAcctSplitBunchRucan();
  50. // 异步通知地址
  51. $extendInfoMap["notify_url"]= "https://callback.service.com/xx";
  52. // 交易失效时间
  53. // $extendInfoMap["time_expire"]= "";
  54. return $extendInfoMap;
  55. }
  56. function getAcctInfosRucan() {
  57. $dto = array();
  58. // 分账金额
  59. $dto["div_amt"] = "0.08";
  60. // 被分账方ID
  61. $dto["huifu_id"] = "6666000111546360";
  62. $dtoList = array();
  63. array_push($dtoList, $dto);
  64. return $dtoList;
  65. }
  66. function getAcctSplitBunchRucan() {
  67. $dto = array();
  68. // 分账明细
  69. $dto["acct_infos"] = $this->getAcctInfosRucan();
  70. return json_encode($dto,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
  71. }
  72. function getMiniappDataRucan() {
  73. $dto = array();
  74. // 应用ID
  75. $dto["seq_id"] = "系统应用ID";
  76. // 私有信息
  77. // $dto["private_info"] = "";
  78. return json_encode($dto,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
  79. }
  80. }