WithdrawService.php 3.7 KB

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