WithdrawService.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. use think\Exception;
  11. class WithdrawService
  12. {
  13. static $url = 'https://testshuichou.zhuoyankeji.com';
  14. // static $url = 'https://api.yeeshui.com';
  15. static $token;
  16. static $user_name = '星领测试';
  17. static $password = '123456';
  18. static $secret = '2a879ac637d65ced5ed5892e1bf82e4c';
  19. static $aeskey = '37d65ced5ed5892e';
  20. public function __construct($token)
  21. {
  22. self::$token = $token;
  23. }
  24. public static function init()
  25. {
  26. $token = CacheService::get('withdraw_token', '');
  27. if (!$token) {
  28. $token = self::login();
  29. CacheService::set('withdraw_token', $token, 500);
  30. }
  31. return new self($token);
  32. }
  33. /**
  34. * 新增人员
  35. * @param $name
  36. * @param $id_card
  37. * @param $bank_code
  38. * @param $mobile
  39. * @param $front_img
  40. * @param $back_img
  41. * @return false|string
  42. */
  43. public static function addEmployee($name, $id_card, $bank_code, $mobile, $front_img, $back_img)
  44. {
  45. $url = '/Enterprise/addEmployee';
  46. $data = [
  47. 'name' => $name,//姓名
  48. 'cer_code' => $id_card,//身份证号码
  49. 'bank_code' => $bank_code,//银行卡号
  50. 'mobile' => $mobile,//银行卡预留手机号
  51. 'has_auth' => 1,
  52. 'source' => 1,
  53. "sign_img" => "",
  54. "protocol_img" => "",
  55. "contract_img" => "",
  56. 'auth' => "2",
  57. 'cer_front_img' => $front_img,//身份证正面照
  58. 'cer_reverse_img' => $back_img,//身份证反面照
  59. ];
  60. $token = self::$token;
  61. return self::postRequest(self::$url . $url, compact('data', 'token'));
  62. }
  63. public static function applySignUrl($id)
  64. {
  65. $url = '/Enterprise/applySignUrl';
  66. $data = [
  67. 'professional_id' => $id,//姓名
  68. 'back_url' => sys_config('site_url'),//返回网址
  69. 'sign_type' => 'letsign',//银行卡号
  70. ];
  71. $token = self::$token;
  72. return self::postRequest(self::$url . $url, compact('data', 'token'));
  73. }
  74. public static function contractDo($id)
  75. {
  76. $url = '/Enterprise/contractDo';
  77. $data = [
  78. 'enterprise_professional_facilitator_id' => $id,//姓名
  79. ];
  80. $token = self::$token;
  81. return self::postRequest(self::$url . $url, compact('data', 'token'));
  82. }
  83. public static function postRequest($url, $data)
  84. {
  85. $res = json_decode(self::do_request($url, $data, ['content-type:application/json'], true, true), true);
  86. if ($res['code'] == 200) {
  87. try {
  88. return self::decode($res['data']);
  89. } catch (\Exception $exception) {
  90. throw new ApiException($exception->getMessage());
  91. }
  92. } else {
  93. throw new ApiException($res['msg'] ?? '处理失败');
  94. }
  95. }
  96. public static function login()
  97. {
  98. $data = [
  99. 'user_name' => self::$user_name,
  100. 'password' => self::$password,
  101. 'timestamp' => time(),
  102. ];
  103. ksort($data);
  104. $signString = http_build_query($data) . '&secret=' . self::$secret;
  105. $sign = md5($signString);
  106. $data['sign'] = $sign;
  107. $res = json_decode(self::do_request(self::$url . '/sdk/v1/login', $data, ['content-type:application/json'], true, true), true);
  108. if ($res['code'] == 200) {
  109. return $res['token'];
  110. } else {
  111. throw new ApiException($res['msg'] ?? '企业登陆失败');
  112. }
  113. }
  114. public static function decode($businessBodyString)
  115. {
  116. //进行Aes解密
  117. include_once 'phpseclib/Crypt/AES.php';
  118. $aes = new \Crypt_AES(CRYPT_AES_MODE_ECB);
  119. $aes->setKey(self::$aeskey);
  120. $data = $aes->decrypt(base64_decode($businessBodyString));
  121. return base64_decode($data);
  122. }
  123. protected static function do_request($url, $data, $header = null, $post = true, $json = false, $format = 0, $form = false)
  124. {
  125. $curl = curl_init();
  126. curl_setopt($curl, CURLOPT_URL, $url);
  127. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  128. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  129. if ($post) {
  130. curl_setopt($curl, CURLOPT_POST, 1);
  131. if (!$json && !$form) {
  132. curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
  133. } else if ($json && !$form) {
  134. curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data, $format));
  135. } else {
  136. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  137. }
  138. }
  139. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  140. if ($header) {
  141. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  142. curl_setopt($curl, CURLOPT_HEADER, 0);
  143. }
  144. $result = curl_exec($curl);
  145. if (curl_errno($curl)) {
  146. return json_encode(['status' => curl_errno($curl), 'msg' => '请求失败']);
  147. }
  148. curl_close($curl);
  149. return $result;
  150. }
  151. }