SanJinService.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. /**
  12. * @description: 获取请求客户端
  13. * @return {*}
  14. */
  15. public static function getClient(): Client
  16. {
  17. return new Client([
  18. 'base_uri' => self::REQUEST_URL,
  19. 'timeout' => 5.0,
  20. ]);
  21. }
  22. // 查询商户余额
  23. public static function findBalance()
  24. {
  25. $merchant_id = config('app.tree_payment_merchant_id');
  26. $secret = config('app.tree_payment_secret');
  27. $sign = md5($merchant_id . $secret);
  28. $data = [
  29. 'merchantNum' => $merchant_id,
  30. 'sign' => $sign,
  31. ];
  32. $client = self::getClient();
  33. $response = $client->get('api/findBalance', [
  34. 'query' => $data,
  35. ]);
  36. $body = $response->getBody();
  37. return json_decode($body->getContents(), true);
  38. }
  39. }