V2TradeElectronReceiptsJumpinfoRequestDemo.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * 跳转电子小票页面 - 示例
  4. *
  5. * @author sdk-generator
  6. * @Description
  7. */
  8. namespace BsPayDemo;
  9. // 1. 资源及配置加载
  10. require_once dirname(__FILE__) . "/loader.php";
  11. require_once dirname(__FILE__). "/../BsPaySdk/request/V2TradeElectronReceiptsJumpinfoRequest.php";
  12. use BsPaySdk\core\BsPayClient;
  13. use BsPaySdk\request\V2TradeElectronReceiptsJumpinfoRequest;
  14. // 2.组装请求参数
  15. $request = new V2TradeElectronReceiptsJumpinfoRequest();
  16. // 请求流水号
  17. $request->setReqSeqId(date("YmdHis").mt_rand());
  18. // 请求时间
  19. $request->setReqDate(date("Ymd"));
  20. // 商户汇付Id
  21. $request->setHuifuId("6666000103334211");
  22. // 原请求日期
  23. $request->setOrgReqDate("20230517");
  24. // 原请求流水号原请求流水号、原交易返回的全局流水号至少要送其中一项;&lt;br/&gt;&lt;font color&#x3D;&quot;green&quot;&gt;示例值:2021091708126665001&lt;/font&gt;
  25. $request->setOrgReqSeqId("20230517111710E83514");
  26. // 汇付全局流水号原请求流水号、原交易返回的全局流水号至少要送其中一项;&lt;br/&gt;&lt;font color&#x3D;&quot;green&quot;&gt;示例值:00290TOP1GR210919004230P853ac13262200000&lt;/font&gt;
  27. $request->setOrgHfSeqId("0036000topB230517111710P034c0a8304100000");
  28. // 票据信息
  29. $request->setReceiptData(getReceiptDataRucan());
  30. // 设置非必填字段
  31. $extendInfoMap = getExtendInfos();
  32. $request->setExtendInfo($extendInfoMap);
  33. // 3. 发起API调用
  34. $client = new BsPayClient();
  35. $result = $client->postRequest($request);
  36. if (!$result || $result->isError()) { //失败处理
  37. var_dump($result -> getErrorInfo());
  38. } else { //成功处理
  39. var_dump($result);
  40. }
  41. /**
  42. * 非必填字段
  43. *
  44. */
  45. function getExtendInfos() {
  46. // 设置非必填字段
  47. $extendInfoMap = array();
  48. return $extendInfoMap;
  49. }
  50. function getJumpInfo() {
  51. $dto = array();
  52. // 小票跳转信息小程序AppID
  53. $dto["merchant_app_id"] = "wxcaced8415a866378";
  54. // 小票跳转信息小程序路径
  55. $dto["merchant_path"] = "pages/cashier/paySuccess";
  56. return $dto;
  57. }
  58. function getWxReceiptDataRucan() {
  59. $dto = array();
  60. // 跳转信息
  61. $dto["jump_info"] = getJumpInfo();
  62. return $dto;
  63. }
  64. function getReceiptDataRucan() {
  65. $dto = array();
  66. // 三方通道类型
  67. $dto["third_channel_type"] = "T";
  68. // 微信票据信息
  69. $dto["wx_receipt_data"] = getWxReceiptDataRucan();
  70. return json_encode($dto,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
  71. }