V2MerchantDirectWechatSubscribeConfigRequestDemo.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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/V2MerchantDirectWechatSubscribeConfigRequest.php";
  12. use BsPaySdk\core\BsPayClient;
  13. use BsPaySdk\request\V2MerchantDirectWechatSubscribeConfigRequest;
  14. // 2.组装请求参数
  15. $request = new V2MerchantDirectWechatSubscribeConfigRequest();
  16. // 请求流水号
  17. $request->setReqSeqId(date("YmdHis").mt_rand());
  18. // 请求日期
  19. $request->setReqDate(date("Ymd"));
  20. // 汇付ID
  21. $request->setHuifuId("6666000003099420");
  22. // 开发者的应用ID
  23. $request->setAppId("wx3767c5bd01df5061");
  24. // 商户号
  25. $request->setMchId("1552470931");
  26. // 特约商户号
  27. $request->setSubMchid("10888880");
  28. // 设置非必填字段
  29. $extendInfoMap = getExtendInfos();
  30. $request->setExtendInfo($extendInfoMap);
  31. // 3. 发起API调用
  32. $client = new BsPayClient();
  33. $result = $client->postRequest($request);
  34. if (!$result || $result->isError()) { //失败处理
  35. var_dump($result -> getErrorInfo());
  36. } else { //成功处理
  37. var_dump($result);
  38. }
  39. /**
  40. * 非必填字段
  41. *
  42. */
  43. function getExtendInfos() {
  44. // 设置非必填字段
  45. $extendInfoMap = array();
  46. // 绑定APPID配置
  47. $extendInfoMap["bind_app_id_conf_list"]= getBindAppIdConfList();
  48. // 关注配置
  49. $extendInfoMap["subscribe_conf_list"]= getSubscribeConfList();
  50. // 支付目录配置
  51. $extendInfoMap["pay_path_conf_list"]= getPayPathConfList();
  52. return $extendInfoMap;
  53. }
  54. function getBindAppIdConfList() {
  55. $dto = array();
  56. // 关联APPID
  57. $dto["sub_appid"] = "oQOa46X2FxRqEy6F4YmwIRCrA7Mk";
  58. $dtoList = array();
  59. array_push($dtoList, $dto);
  60. return json_encode($dtoList,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
  61. }
  62. function getSubscribeConfList() {
  63. $dto = array();
  64. // 关联APPID
  65. $dto["sub_appid"] = "wx5934540532";
  66. // 推荐关注APPID服务商的公众号APPID;与receipt_appid二选一;&lt;font color&#x3D;&quot;green&quot;&gt;示例值:wx5934540532&lt;/font&gt;
  67. $dto["subscribe_appid"] = "oQOa46X2FxRqEy6F4YmwIRCrA7Mk";
  68. // 支付凭证推荐小程序appid需为通过微信认证的小程序appid,且认证主体与服务商主体一致;与subscribe_appid二选一;&lt;font color&#x3D;&quot;green&quot;&gt;示例值:wx852a790f100000fe&lt;/font&gt;
  69. $dto["receipt_appid"] = "wx852a790f100000fe";
  70. $dtoList = array();
  71. array_push($dtoList, $dto);
  72. return json_encode($dtoList,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
  73. }
  74. function getPayPathConfList() {
  75. $dto = array();
  76. // 授权目录
  77. $dto["jsapi_path"] = "http://www.dsf.com/init";
  78. $dtoList = array();
  79. array_push($dtoList, $dto);
  80. return json_encode($dtoList,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
  81. }