transfer.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /* *
  3. * Ping++ Server SDK
  4. * 说明:
  5. * 以下代码只是为了方便商户测试而提供的样例代码,商户可根据自己网站需求按照技术文档编写, 并非一定要使用该代码。
  6. * 接入企业付款流程参考开发者中心:https://www.pingxx.com/docs/server/transfer ,文档可筛选后端语言和接入渠道。
  7. * 该代码仅供学习和研究 Ping++ SDK 使用,仅供参考。
  8. */
  9. require dirname(__FILE__) . '/../init.php';
  10. // api_key 获取方式:登录 [Dashboard](https://dashboard.pingxx.com)->点击管理平台右上角公司名称->开发信息-> Secret Key
  11. $api_key = 'sk_test_ibbTe5jLGCi5rzfH4OqPW9KC';
  12. // app_id 获取方式:登录 [Dashboard](https://dashboard.pingxx.com)->点击你创建的应用->应用首页->应用 ID(App ID)
  13. $app_id = 'app_1Gqj58ynP0mHeX1q';
  14. \Pingpp\Pingpp::setApiKey($api_key);
  15. // 创建 Transfer
  16. try {
  17. $tr = \Pingpp\Transfer::create(
  18. array(
  19. 'amount' => 100,// 订单总金额, 人民币单位:分(如订单总金额为 1 元,此处请填 100,企业付款最小发送金额为 1 元)
  20. 'order_no' => date('mdHis') . mt_rand(1, 9999),// 企业转账使用的商户内部订单号。wx(新渠道)、wx_pub 规定为 1 ~ 50 位不能重复的数字字母组合、unionpay 为不 1~16 位数字
  21. 'currency' => 'cny',
  22. 'channel' => 'unionpay',// 目前支持 wx(新渠道)、 wx_pub、unionpay
  23. 'app' => array('id' => $app_id),
  24. 'type' => 'b2c',// 付款类型,当前仅支持 b2c 企业付款。
  25. 'recipient' => 'o9zpMs9jIaLynQY9N6yxcZ',// 接收者 id, 为用户在 wx(新渠道)、wx_pub 下的 open_id
  26. 'description' => 'testing',
  27. 'extra' => array(
  28. 'user_name' => 'User Name', //收款人姓名。当该参数为空,则不校验收款人姓名,选填
  29. 'force_check' => false// 是否强制校验收款人姓名。仅当 user_name 参数不为空时该参数生效,选填
  30. )
  31. )
  32. );
  33. echo $tr;// 输出 Ping++ 返回的企业付款对象 Transfer
  34. } catch (\Pingpp\Error\Base $e) {
  35. header('Status: ' . $e->getHttpStatus());
  36. echo($e->getHttpBody());
  37. }
  38. // 查询 Transfer
  39. $tr = \Pingpp\Transfer::retrieve('TRANSFER_ID');
  40. // 取消 Transfer
  41. $tr['status'] = 'canceled';
  42. $tr->save();