FoxPay.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. namespace App\Services;
  3. class FoxPay
  4. {
  5. protected $merchantOrder;
  6. protected $thirdUserId;
  7. protected $currency;
  8. protected $amount;
  9. /**
  10. * 充值
  11. * 传入数组进行HTTP POST请求
  12. * @param $url
  13. * @param array $params
  14. * @param int $timeout
  15. * @return bool|string
  16. */
  17. public function curlPost($url, $params = array(),$timeout)
  18. {
  19. $payConfigService = new PayConfig();
  20. $config = $payConfigService->getConfig('foxPay');
  21. $data_string = json_encode($params); //将数组转json格式的数据
  22. $ch = curl_init($url);
  23. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  24. curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
  25. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  26. 'Content-Type: application/json',
  27. 'Authorization: Basic'.base64_encode($config['merchantID'].':'.$config['SecretKey'].''), //添加头
  28. 'Content-Length: ' . strlen($data_string))
  29. );
  30. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // 设置超时限制防止死循环
  31. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  32. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  33. $hdresult = curl_exec($ch);
  34. curl_close($ch);
  35. return $hdresult;
  36. }
  37. public function sign($data = [])
  38. {
  39. unset($data['amount']);
  40. unset($data['fee']);
  41. ksort($data); //按照参数名ASCII码从小到大排序
  42. $payConfigService = new PayConfig();
  43. $config = $payConfigService->getConfig('foxPay');
  44. $md5key = $config['SecretKey']; //md5密钥
  45. $stringA = "";
  46. foreach ($data as $key => $value) {
  47. $stringA .= $value;
  48. }
  49. return md5($stringA . $md5key); //拼接密钥后,md5加密后转为大写
  50. }
  51. // 提现签名
  52. public function cashierSign($requestData,$data)
  53. {
  54. ksort($requestData); //按照参数名ASCII码从小到大排序
  55. $stringA = urldecode(http_build_query($requestData));
  56. ksort($data); //按照参数名ASCII码从小到大排序
  57. $stringB = urldecode(http_build_query($data));
  58. $stringC = $stringA.'&'.$stringB;
  59. $payConfigService = new PayConfig();
  60. $config = $payConfigService->getConfig('auPay');
  61. $md5key = $config['SecretKey']; //md5密钥
  62. return strtoupper(md5($stringC.$md5key));
  63. }
  64. public function allData()
  65. {
  66. $data = get_object_vars($this);
  67. return array_filter($data);
  68. }
  69. /**
  70. * @param mixed $amount
  71. */
  72. public function setAmount($amount): void
  73. {
  74. $this->amount = $amount;
  75. }
  76. /**
  77. * @return mixed
  78. */
  79. public function getAmount()
  80. {
  81. return $this->amount;
  82. }
  83. /**
  84. * @param mixed $memberid
  85. */
  86. public function setMemberid($memberid): void
  87. {
  88. $this->thirdUserId = $memberid;
  89. }
  90. /**
  91. * @return mixed
  92. */
  93. public function getMemberid()
  94. {
  95. return $this->thirdUserId;
  96. }
  97. /**
  98. * @param mixed $orderid
  99. */
  100. public function setOrderid($orderid): void
  101. {
  102. $this->merchantOrder = $orderid;
  103. }
  104. /**
  105. * @return mixed
  106. */
  107. public function getOrderid()
  108. {
  109. return $this->merchantOrder;
  110. }
  111. /**
  112. * @param mixed $currency
  113. */
  114. public function setCurrency($currency): void
  115. {
  116. $this->currency = $currency;
  117. }
  118. }