WithdrawService.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. $res['data'] = self::decode($res['data']);
  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. public function decode($businessBodyString)
  78. {
  79. //进行Aes解密
  80. include_once '../phpseclib/Crypt/AES.php';
  81. $aes = new \Crypt_AES(CRYPT_AES_MODE_ECB);
  82. $aes->setKey(self::$aeskey);
  83. $data = $aes->decrypt(base64_decode($businessBodyString));
  84. return $data;
  85. }
  86. protected static function do_request($url, $data, $header = null, $post = true, $json = false, $format = 0, $form = false)
  87. {
  88. $curl = curl_init();
  89. curl_setopt($curl, CURLOPT_URL, $url);
  90. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  91. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  92. if ($post) {
  93. curl_setopt($curl, CURLOPT_POST, 1);
  94. if (!$json && !$form) {
  95. curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
  96. } else if ($json && !$form) {
  97. curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data, $format));
  98. } else {
  99. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  100. }
  101. }
  102. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  103. if ($header) {
  104. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  105. curl_setopt($curl, CURLOPT_HEADER, 0);
  106. }
  107. $result = curl_exec($curl);
  108. if (curl_errno($curl)) {
  109. return json_encode(['status' => curl_errno($curl), 'msg' => '请求失败']);
  110. }
  111. curl_close($curl);
  112. return $result;
  113. }
  114. }