SanJinService.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace App\Services\Payment;
  3. use GuzzleHttp\Client;
  4. use GuzzleHttp\Exception\RequestException;
  5. use GuzzleHttp\Psr7\Response;
  6. use App\Services\BaseService;
  7. class SanJinService extends BaseService
  8. {
  9. // SanJin payment service methods would go here
  10. const REQUEST_URL = 'https://api.qbdf13.com/';
  11. const ALIPAY_TO_CARD = 'DF001'; // 支付宝转银行卡
  12. const ALIPAY_TO_ALIPAY = 'DF002'; // 支付宝转支付宝
  13. // 获取异步的通知地址
  14. public static function getNotifyUrl()
  15. {
  16. return 'https://botpc28.testx2.cc/';
  17. }
  18. /**
  19. * @description: 获取请求客户端
  20. * @return {*}
  21. */
  22. public static function getClient(): Client
  23. {
  24. return new Client([
  25. 'base_uri' => self::REQUEST_URL,
  26. 'timeout' => 5.0,
  27. ]);
  28. }
  29. /**
  30. * @description: 查询商户余额
  31. * @return {array}
  32. * {array.success - 是否成功 true|false}
  33. * {array.msg - 返回错误消息}
  34. * {array.code - 返回状态码:200成功,其他失败}
  35. * {array.timestamp - 时间戳 13位}
  36. * {array.data - 商户余额}
  37. */
  38. public static function findBalance()
  39. {
  40. $merchant_id = config('app.tree_payment_merchant_id');
  41. $secret = config('app.tree_payment_secret');
  42. $sign = md5($merchant_id . $secret);
  43. $data = [
  44. 'merchantNum' => $merchant_id,
  45. 'sign' => $sign,
  46. ];
  47. $client = self::getClient();
  48. $response = $client->get('api/findBalance', [
  49. 'query' => $data,
  50. ]);
  51. $body = $response->getBody();
  52. return json_decode($body->getContents(), true);
  53. }
  54. public static function pay($amount, $order_no, $notify_url, $return_url)
  55. {
  56. $data = [];
  57. $merchant_id = config('app.tree_payment_merchant_id');
  58. $secret = config('app.tree_payment_secret');
  59. $data['merchantNum'] = $merchant_id;
  60. $data['amount'] = $amount;
  61. $data['orderNo'] = $order_no;
  62. $data['notifyUrl'] = $notify_url;
  63. $data['returnUrl'] = $return_url;
  64. $signStr = $merchant_id . $order_no . $amount . $secret;
  65. $sign = md5($signStr);
  66. $data['sign'] = $sign;
  67. $client = self::getClient();
  68. $response = $client->post('api/pay', [
  69. 'json' => $data,
  70. 'headers' => [
  71. 'Content-Type' => 'application/json',
  72. ]
  73. ]);
  74. $body = $response->getBody();
  75. $result = json_decode($body->getContents(), true);
  76. return $result;
  77. }
  78. }