WithdrawService.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. use crmeb\exceptions\ApiException;
  10. class WithdrawService
  11. {
  12. static $url = 'https://testshuichou.zhuoyankeji.com';
  13. // static $url = 'https://api.yeeshui.com';
  14. static $token;
  15. static $user_name = '星领测试';
  16. static $password = '123456';
  17. static $secret = '2a879ac637d65ced5ed5892e1bf82e4c';
  18. static $aeskey = '37d65ced5ed5892e';
  19. public function __construct($token)
  20. {
  21. self::$token = $token;
  22. }
  23. public static function init()
  24. {
  25. $token = CacheService::get('withdraw_token', '');
  26. if (!$token) {
  27. $token = self::login();
  28. CacheService::set('withdraw_token', $token, 500);
  29. }
  30. return new self($token);
  31. }
  32. public static function addEmployee($name, $id_card, $bank_code, $mobile, $front_img, $back_img)
  33. {
  34. $url = '/Enterprise/addEmployee';
  35. $data = [
  36. 'name' => $name,//姓名
  37. 'cer_code' => $id_card,//身份证号码
  38. 'bank_code' => $bank_code,//银行卡号
  39. 'mobile' => $mobile,//银行卡预留手机号
  40. 'has_auth' => 1,
  41. 'source' => 1,
  42. 'auth' => 2,
  43. 'cer_front_img' => $front_img,//身份证正面照
  44. 'cer_reverse_img' => $back_img,//身份证反面照
  45. ];
  46. $res = self::request($url, $data);
  47. var_dump($res);
  48. }
  49. public static function login()
  50. {
  51. $data = [
  52. 'user_name' => self::$user_name,
  53. 'password' => self::$password,
  54. 'timestamp' => time(),
  55. ];
  56. ksort($data);
  57. $signString = http_build_query($data) . '&secret=' . self::$secret;
  58. $sign = md5($signString);
  59. $data['sign'] = $sign;
  60. $res = json_decode(self::do_request(self::$url . '/sdk/v1/login', $data, ['content-type:application/json'], true, true), true);
  61. if ($res['code'] == 200) {
  62. return $res['token'];
  63. } else {
  64. throw new ApiException($res['msg'] ?? '企业登陆失败');
  65. }
  66. }
  67. public static function request($url, $data)
  68. {
  69. $url = self::$url . $url;
  70. $data = ['token' => self::$token, 'data' => $data];
  71. return json_decode(self::do_request(self::$url . $url, $data, ['content-type:application/json'], true, true), true);
  72. }
  73. protected static function do_request($url, $data, $header = null, $post = true, $json = false, $format = 0, $form = false)
  74. {
  75. $curl = curl_init();
  76. curl_setopt($curl, CURLOPT_URL, $url);
  77. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  78. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  79. if ($post) {
  80. curl_setopt($curl, CURLOPT_POST, 1);
  81. if (!$json && !$form) {
  82. curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
  83. } else if ($json && !$form) {
  84. curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data, $format));
  85. } else {
  86. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  87. }
  88. }
  89. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  90. if ($header) {
  91. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  92. curl_setopt($curl, CURLOPT_HEADER, 0);
  93. }
  94. $result = curl_exec($curl);
  95. if (curl_errno($curl)) {
  96. return json_encode(['status' => curl_errno($curl), 'msg' => '请求失败']);
  97. }
  98. curl_close($curl);
  99. return $result;
  100. }
  101. }