WithdrawService.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. "sign_img" => "",
  43. "protocol_img" => "",
  44. "contract_img" => "",
  45. 'auth' => "2",
  46. 'cer_front_img' => $front_img,//身份证正面照
  47. 'cer_reverse_img' => $back_img,//身份证反面照
  48. ];
  49. $res = self::request($url, $data);
  50. var_dump($res);
  51. }
  52. public static function login()
  53. {
  54. $data = [
  55. 'user_name' => self::$user_name,
  56. 'password' => self::$password,
  57. 'timestamp' => time(),
  58. ];
  59. ksort($data);
  60. $signString = http_build_query($data) . '&secret=' . self::$secret;
  61. $sign = md5($signString);
  62. $data['sign'] = $sign;
  63. $res = json_decode(self::do_request(self::$url . '/sdk/v1/login', $data, ['content-type:application/json'], true, true), true);
  64. if ($res['code'] == 200) {
  65. return $res['token'];
  66. } else {
  67. throw new ApiException($res['msg'] ?? '企业登陆失败');
  68. }
  69. }
  70. public static function request($url, $data)
  71. {
  72. $url = self::$url . $url;
  73. $data = ['token' => self::$token, 'data' => $data];
  74. var_dump($data);
  75. var_dump($url);
  76. return json_decode(self::do_request(self::$url . $url, $data, ['content-type:application/json'], true, true), true);
  77. }
  78. protected static function do_request($url, $data, $header = null, $post = true, $json = false, $format = 0, $form = false)
  79. {
  80. $curl = curl_init();
  81. curl_setopt($curl, CURLOPT_URL, $url);
  82. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  83. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  84. if ($post) {
  85. curl_setopt($curl, CURLOPT_POST, 1);
  86. if (!$json && !$form) {
  87. curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
  88. } else if ($json && !$form) {
  89. curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data, $format));
  90. } else {
  91. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  92. }
  93. }
  94. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  95. if ($header) {
  96. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  97. curl_setopt($curl, CURLOPT_HEADER, 0);
  98. }
  99. $result = curl_exec($curl);
  100. if (curl_errno($curl)) {
  101. return json_encode(['status' => curl_errno($curl), 'msg' => '请求失败']);
  102. }
  103. curl_close($curl);
  104. return $result;
  105. }
  106. }