V2TradeElectronReceiptsCustomentrancesQueryRequestDemo.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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/V2TradeElectronReceiptsCustomentrancesQueryRequest.php";
  12. use BsPaySdk\core\BsPayClient;
  13. use BsPaySdk\request\V2TradeElectronReceiptsCustomentrancesQueryRequest;
  14. // 2.组装请求参数
  15. $request = new V2TradeElectronReceiptsCustomentrancesQueryRequest();
  16. // 请求流水号
  17. $request->setReqSeqId(date("YmdHis").mt_rand());
  18. // 请求日期
  19. $request->setReqDate(date("Ymd"));
  20. // 商户号
  21. $request->setHuifuId("6666000103334211");
  22. // 设置非必填字段
  23. $extendInfoMap = getExtendInfos();
  24. $request->setExtendInfo($extendInfoMap);
  25. // 3. 发起API调用
  26. $client = new BsPayClient();
  27. $result = $client->postRequest($request);
  28. if (!$result || $result->isError()) { //失败处理
  29. var_dump($result -> getErrorInfo());
  30. } else { //成功处理
  31. var_dump($result);
  32. }
  33. /**
  34. * 非必填字段
  35. *
  36. */
  37. function getExtendInfos() {
  38. // 设置非必填字段
  39. $extendInfoMap = array();
  40. // 票据信息
  41. $extendInfoMap["receipt_data"]= getReceiptDataRucan();
  42. return $extendInfoMap;
  43. }
  44. function getWxReceiptDataRucan() {
  45. $dto = array();
  46. // 品牌ID
  47. $dto["brand_id"] = "11";
  48. return $dto;
  49. }
  50. function getReceiptDataRucan() {
  51. $dto = array();
  52. // 三方通道类型
  53. $dto["third_channel_type"] = "T";
  54. // 微信票据信息
  55. $dto["wx_receipt_data"] = getWxReceiptDataRucan();
  56. return json_encode($dto,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
  57. }