WithdrawService.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. public static function addEmployee($name, $id_card, $bank_code, $mobile, $front_img, $back_img)
  34. {
  35. $url = '/Enterprise/addEmployee';
  36. $data = [
  37. 'name' => $name,//姓名
  38. 'cer_code' => $id_card,//身份证号码
  39. 'bank_code' => $bank_code,//银行卡号
  40. 'mobile' => $mobile,//银行卡预留手机号
  41. 'has_auth' => 1,
  42. 'source' => 1,
  43. "sign_img" => "",
  44. "protocol_img" => "",
  45. "contract_img" => "",
  46. 'auth' => "2",
  47. 'cer_front_img' => $front_img,//身份证正面照
  48. 'cer_reverse_img' => $back_img,//身份证反面照
  49. ];
  50. $token = self::$token;
  51. return self::postRequest(self::$url . $url, compact('data', 'token'));
  52. }
  53. public static function contractDo($id)
  54. {
  55. $url = '/Enterprise/contractDo';
  56. $data = [
  57. 'enterprise_professional_facilitator_id' => $id,//姓名
  58. ];
  59. $token = self::$token;
  60. return self::postRequest(self::$url . $url, compact('data', 'token'));
  61. }
  62. public static function postRequest($url, $data)
  63. {
  64. $res = json_decode(self::do_request($url, $data, ['content-type:application/json'], true, true), true);
  65. if ($res['code'] == 200) {
  66. try {
  67. return self::decode($res['data']);
  68. } catch (\Exception $exception) {
  69. throw new ApiException($exception->getMessage());
  70. }
  71. } else {
  72. throw new ApiException($res['msg'] ?? '处理失败');
  73. }
  74. }
  75. public static function login()
  76. {
  77. $data = [
  78. 'user_name' => self::$user_name,
  79. 'password' => self::$password,
  80. 'timestamp' => time(),
  81. ];
  82. ksort($data);
  83. $signString = http_build_query($data) . '&secret=' . self::$secret;
  84. $sign = md5($signString);
  85. $data['sign'] = $sign;
  86. $res = json_decode(self::do_request(self::$url . '/sdk/v1/login', $data, ['content-type:application/json'], true, true), true);
  87. if ($res['code'] == 200) {
  88. return $res['token'];
  89. } else {
  90. throw new ApiException($res['msg'] ?? '企业登陆失败');
  91. }
  92. }
  93. public static function decode($businessBodyString)
  94. {
  95. //进行Aes解密
  96. include_once 'phpseclib/Crypt/AES.php';
  97. $aes = new \Crypt_AES(CRYPT_AES_MODE_ECB);
  98. $aes->setKey(self::$aeskey);
  99. $data = $aes->decrypt(base64_decode($businessBodyString));
  100. return base64_decode($data);
  101. }
  102. protected static function do_request($url, $data, $header = null, $post = true, $json = false, $format = 0, $form = false)
  103. {
  104. $curl = curl_init();
  105. curl_setopt($curl, CURLOPT_URL, $url);
  106. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  107. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  108. if ($post) {
  109. curl_setopt($curl, CURLOPT_POST, 1);
  110. if (!$json && !$form) {
  111. curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
  112. } else if ($json && !$form) {
  113. curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data, $format));
  114. } else {
  115. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  116. }
  117. }
  118. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  119. if ($header) {
  120. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  121. curl_setopt($curl, CURLOPT_HEADER, 0);
  122. }
  123. $result = curl_exec($curl);
  124. if (curl_errno($curl)) {
  125. return json_encode(['status' => curl_errno($curl), 'msg' => '请求失败']);
  126. }
  127. curl_close($curl);
  128. return $result;
  129. }
  130. }