WithdrawService.php 4.1 KB

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