JoinPay.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Libs\Pay\Merchants;
  3. use Exception;
  4. use GuzzleHttp\Client;
  5. /**
  6. * 汇聚支付
  7. */
  8. class JoinPay implements PayMerchantInterface
  9. {
  10. private $make_order_url = 'https://www.joinpay.com/trade/uniPayApi.action';
  11. private $query_order_url = 'https://qr.chinaums.com/netpay-route-server/api/';
  12. private $appId;
  13. private $merchantNo;
  14. private $version;
  15. public function __construct(array $config)
  16. {
  17. $this->version = "1.0";
  18. $this->merchantNo = "888108800000947";
  19. }
  20. public function send(array $data)
  21. { }
  22. public function query(string $trade_no)
  23. { }
  24. public function notify(array $data)
  25. { }
  26. public function refund(array $data)
  27. { }
  28. public function makeSign(array $data)
  29. {
  30. //签名步骤一:按字典序排序参数
  31. ksort($data);
  32. $buff = "";
  33. foreach ($data as $k => $v) {
  34. if ($k != "sign" && $v != "" && !is_array($v)) {
  35. $buff .= $k . "=" . $v . "&";
  36. }
  37. }
  38. $buff = trim($buff, "&");
  39. //签名步骤二:在string后加入KEY
  40. $string = $buff . $this->key;
  41. //签名步骤三:MD5加密
  42. $string = md5($string);
  43. //签名步骤四:所有字符转为大写
  44. $result = strtoupper($string);
  45. return $result;
  46. }
  47. private function request(array $data)
  48. {
  49. try {
  50. $data['sign'] = $this->makeSign($data);
  51. $client = new Client(['timeout' => 3]);
  52. $result = $client->request('post', $this->query_order_url, ['json' => $data])->getBody()->getContents();
  53. if ($result) {
  54. $result = json_decode($result);
  55. }
  56. return $result;
  57. } catch (Exception $e) { }
  58. }
  59. }