WithdrawService.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. static $crowd_id = '12882';
  21. public function __construct($token)
  22. {
  23. self::$token = $token;
  24. }
  25. public static function init()
  26. {
  27. $token = CacheService::get('withdraw_token', '');
  28. if (!$token) {
  29. $token = self::login();
  30. CacheService::set('withdraw_token', $token, 500);
  31. }
  32. return new self($token);
  33. }
  34. /**
  35. * 新增人员
  36. * @param $name
  37. * @param $id_card
  38. * @param $bank_code
  39. * @param $mobile
  40. * @param $front_img
  41. * @param $back_img
  42. * @return false|string
  43. */
  44. public static function addEmployee($name, $id_card, $bank_code, $mobile, $front_img, $back_img)
  45. {
  46. $url = '/Enterprise/addEmployee';
  47. $data = [
  48. 'name' => $name,//姓名
  49. 'cer_code' => $id_card,//身份证号码
  50. 'bank_code' => $bank_code,//银行卡号
  51. 'mobile' => $mobile,//银行卡预留手机号
  52. 'has_auth' => 1,
  53. 'source' => 1,
  54. "sign_img" => "",
  55. "protocol_img" => "",
  56. "contract_img" => "",
  57. 'auth' => "2",
  58. 'cer_front_img' => $front_img,//身份证正面照
  59. 'cer_reverse_img' => $back_img,//身份证反面照
  60. ];
  61. $token = self::$token;
  62. return self::postRequest(self::$url . $url, compact('data', 'token'));
  63. }
  64. public static function applySignUrl($id)
  65. {
  66. $url = '/Enterprise/applySignUrl';
  67. $data = [
  68. 'professional_id' => $id,//姓名
  69. 'back_url' => sys_config('site_url'),//返回网址
  70. 'sign_type' => 'letsign',//银行卡号
  71. ];
  72. $token = self::$token;
  73. return self::postRequest(self::$url . $url, compact('data', 'token'));
  74. }
  75. public static function querySignResult($id)
  76. {
  77. $url = '/Enterprise/querySignResult';
  78. $data = [
  79. 'transactionCode' => $id,//姓名
  80. ];
  81. $token = self::$token;
  82. return self::postRequest(self::$url . $url, compact('data', 'token'));
  83. }
  84. public static function contractDo($id)
  85. {
  86. $url = '/Enterprise/contractDo';
  87. $data = [
  88. 'enterprise_professional_facilitator_id' => $id,//姓名
  89. ];
  90. $token = self::$token;
  91. return self::postRequest(self::$url . $url, compact('data', 'token'));
  92. }
  93. public static function contractInfo($id)
  94. {
  95. $url = '/Enterprise/contractInfo';
  96. $data = [
  97. 'enterprise_professional_facilitator_id' => $id,//姓名
  98. ];
  99. $token = self::$token;
  100. return self::postRequest(self::$url . $url, compact('data', 'token'));
  101. }
  102. public static function fastIssuing()
  103. {
  104. $url = '/Enterprise/fastIssuing';
  105. $data = [
  106. 'trade_number' => '',
  107. 'crowd_id' => self::$crowd_id,
  108. 'issuing_data' => [
  109. "professional_id" => '',
  110. "name" => "李杭",
  111. "cer_code" => "4307031*****9955X",
  112. "mobile" => "1501****016",
  113. "bank_code" => "6214467******212356",
  114. "money" => "100",
  115. "remark" => "业绩提成",
  116. "request_no" => "A20201121033333332",
  117. "professional_bank_id" => 0,
  118. "resolve_id" => 1
  119. ],
  120. ];
  121. }
  122. public static function postRequest($url, $data)
  123. {
  124. $res = json_decode(self::do_request($url, $data, ['content-type:application/json'], true, true), true);
  125. if ($res['code'] == 200) {
  126. try {
  127. return self::decode($res['data']);
  128. } catch (\Exception $exception) {
  129. throw new ApiException($exception->getMessage());
  130. }
  131. } else {
  132. throw new ApiException($res['msg'] ?? '处理失败');
  133. }
  134. }
  135. private static function login()
  136. {
  137. $data = [
  138. 'user_name' => self::$user_name,
  139. 'password' => self::$password,
  140. 'timestamp' => time(),
  141. ];
  142. ksort($data);
  143. $signString = http_build_query($data) . '&secret=' . self::$secret;
  144. $sign = md5($signString);
  145. $data['sign'] = $sign;
  146. $res = json_decode(self::do_request(self::$url . '/sdk/v1/login', $data, ['content-type:application/json'], true, true), true);
  147. if ($res['code'] == 200) {
  148. return $res['token'];
  149. } else {
  150. throw new ApiException($res['msg'] ?? '企业登陆失败');
  151. }
  152. }
  153. private static function decode($businessBodyString)
  154. {
  155. //进行Aes解密
  156. include_once 'phpseclib/Crypt/AES.php';
  157. $aes = new \Crypt_AES(CRYPT_AES_MODE_ECB);
  158. $aes->setKey(self::$aeskey);
  159. $data = $aes->decrypt(base64_decode($businessBodyString));
  160. return json_decode(base64_decode($data), true);
  161. }
  162. private static function do_request($url, $data, $header = null, $post = true, $json = false, $format = 0, $form = false)
  163. {
  164. $curl = curl_init();
  165. curl_setopt($curl, CURLOPT_URL, $url);
  166. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  167. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  168. if ($post) {
  169. curl_setopt($curl, CURLOPT_POST, 1);
  170. if (!$json && !$form) {
  171. curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
  172. } else if ($json && !$form) {
  173. curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data, $format));
  174. } else {
  175. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  176. }
  177. }
  178. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  179. if ($header) {
  180. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  181. curl_setopt($curl, CURLOPT_HEADER, 0);
  182. }
  183. $result = curl_exec($curl);
  184. if (curl_errno($curl)) {
  185. return json_encode(['status' => curl_errno($curl), 'msg' => '请求失败']);
  186. }
  187. curl_close($curl);
  188. return $result;
  189. }
  190. }