WithdrawService.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * @Created by PhpStorm
  4. * @author: Kirin
  5. * @day: 2023/12/19
  6. * @time: 16:09
  7. */
  8. namespace crmeb\services;
  9. class WithdrawService
  10. {
  11. static $url = 'https://testshuichou.zhuoyankeji.com';
  12. // static $url = 'https://api.yeeshui.com';
  13. static $token;
  14. static $user_name = '星领测试';
  15. static $password = '123456';
  16. static $secret = '2a879ac637d65ced5ed5892e1bf82e4c';
  17. static $aeskey = '37d65ced5ed5892e';
  18. public static function init()
  19. {
  20. self::$token = CacheService::get('withdraw_token', '');
  21. if (!self::$token) {
  22. self::$token = self::login();
  23. CacheService::set('withdraw_token', 500);
  24. }
  25. }
  26. public static function login()
  27. {
  28. $data = [
  29. 'user_name' => self::$user_name,
  30. 'password' => self::$password,
  31. 'timestamp' => time(),
  32. ];
  33. ksort($data);
  34. var_dump($data);
  35. echo "\n";
  36. $signString = http_build_query($data) . '&secret=' . self::$secret;
  37. var_dump($signString);
  38. echo "\n";
  39. $sign = md5($signString);
  40. var_dump($sign);
  41. echo "\n";
  42. $data['sign'] = $sign;
  43. var_dump($data);
  44. $res = json_decode(self::do_request(self::$url . '/sdk/v1/login', $data, ['content-type:application/json'], true, true), true);
  45. var_dump($res);
  46. }
  47. public static function request($url, $data)
  48. {
  49. $url = self::$url . $url;
  50. $data = ['token' => self::$token, 'data' => $data];
  51. return json_decode(self::do_request(self::$url . $url, $data, ['content-type:application/json'], true, true), true);
  52. }
  53. protected static function do_request($url, $data, $header = null, $post = true, $json = false, $format = 0, $form = false)
  54. {
  55. $curl = curl_init();
  56. curl_setopt($curl, CURLOPT_URL, $url);
  57. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  58. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  59. if ($post) {
  60. curl_setopt($curl, CURLOPT_POST, 1);
  61. if (!$json && !$form) {
  62. curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
  63. } else if ($json && !$form) {
  64. curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data, $format));
  65. } else {
  66. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  67. }
  68. }
  69. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  70. if ($header) {
  71. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  72. curl_setopt($curl, CURLOPT_HEADER, 0);
  73. }
  74. $result = curl_exec($curl);
  75. if (curl_errno($curl)) {
  76. return json_encode(['status' => curl_errno($curl), 'msg' => '请求失败']);
  77. }
  78. curl_close($curl);
  79. return $result;
  80. }
  81. }