WithdrawService.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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 = '057682923388';
  18. static $secret = '56e6fded2e9d6e534656a2493d0bebba';
  19. static $aeskey = '2e9d6e534656a249';
  20. static $crowd_id = '15587';
  21. static $resolve_id = '7021';
  22. public function __construct($token)
  23. {
  24. self::$token = $token;
  25. }
  26. public static function init()
  27. {
  28. $token = CacheService::get('withdraw_token', '');
  29. if (!$token) {
  30. $token = self::login();
  31. CacheService::set('withdraw_token', $token, 500);
  32. }
  33. return new self($token);
  34. }
  35. /**
  36. * 新增人员
  37. * @param $name
  38. * @param $id_card
  39. * @param $bank_code
  40. * @param $mobile
  41. * @param $front_img
  42. * @param $back_img
  43. * @return mixed
  44. */
  45. public static function addEmployee($name, $id_card, $bank_code, $mobile, $front_img, $back_img)
  46. {
  47. $url = '/Enterprise/addEmployee';
  48. $data = [
  49. 'name' => $name,//姓名
  50. 'cer_code' => $id_card,//身份证号码
  51. 'bank_code' => $bank_code,//银行卡号
  52. 'mobile' => $mobile,//银行卡预留手机号
  53. 'has_auth' => 1,
  54. 'source' => 1,
  55. "sign_img" => "",
  56. "protocol_img" => "",
  57. "contract_img" => "",
  58. 'auth' => "2",
  59. 'cer_front_img' => $front_img,//身份证正面照
  60. 'cer_reverse_img' => $back_img,//身份证反面照
  61. ];
  62. $token = self::$token;
  63. return self::postRequest(self::$url . $url, compact('data', 'token'));
  64. }
  65. public static function applySignUrl($id)
  66. {
  67. $url = '/Enterprise/applySignUrl';
  68. $data = [
  69. 'professional_id' => $id,//姓名
  70. 'back_url' => sys_config('site_url'),//返回网址
  71. 'sign_type' => 'letsign',//银行卡号
  72. ];
  73. $token = self::$token;
  74. return self::postRequest(self::$url . $url, compact('data', 'token'));
  75. }
  76. public static function querySignResult($id)
  77. {
  78. $url = '/Enterprise/querySignResult';
  79. $data = [
  80. 'transactionCode' => $id,//姓名
  81. ];
  82. $token = self::$token;
  83. return self::postRequest(self::$url . $url, compact('data', 'token'));
  84. }
  85. public static function contractDo($id)
  86. {
  87. $url = '/Enterprise/contractDo';
  88. $data = [
  89. 'enterprise_professional_facilitator_id' => $id,//姓名
  90. ];
  91. $token = self::$token;
  92. return self::postRequest(self::$url . $url, compact('data', 'token'));
  93. }
  94. public static function contractInfo($id)
  95. {
  96. $url = '/Enterprise/contractInfo';
  97. $data = [
  98. 'enterprise_professional_facilitator_id' => $id,//姓名
  99. ];
  100. $token = self::$token;
  101. return self::postRequest(self::$url . $url, compact('data', 'token'));
  102. }
  103. public static function getOrderList($status = 0, $page = 1, $limit = 10)
  104. {
  105. $url = '/Enterprise/getOrderList';
  106. $data = [
  107. // 'enterprise_order_sn' => '',
  108. // 'states' => '',
  109. 'status' => $status,
  110. // 'reason' => '',
  111. // 'check_time_start' => '',
  112. // "check_time_end" => "",
  113. "pagination" => ['page_start' => $page, 'page_size' => $limit],
  114. ];
  115. $token = self::$token;
  116. return self::postRequest(self::$url . $url, compact('data', 'token'));
  117. }
  118. public static function getOrderExt($order_id, $page = 1, $limit = 10)
  119. {
  120. $url = '/Enterprise/getOrderExt';
  121. $data = [
  122. 'enterprise_order_id' => $order_id,
  123. "pagination" => ['page_start' => $page, 'page_size' => $limit],
  124. ];
  125. $token = self::$token;
  126. return self::postRequest(self::$url . $url, compact('data', 'token'));
  127. }
  128. public static function getOrderTemplate($order_id)
  129. {
  130. $url = '/Enterprise/getOrderTemplate';
  131. $data = [
  132. 'enterprise_order_id' => $order_id,
  133. ];
  134. $token = self::$token;
  135. return self::postRequest(self::$url . $url, compact('data', 'token'));
  136. }
  137. public static function changeOrderStatus($order_id, $apply_img, $seal_img, $status = 1, $remarks = '')
  138. {
  139. $url = '/Enterprise/changeOrderStatus';
  140. $data = [
  141. 'enterprise_order_id' => $order_id,
  142. 'status' => $status,
  143. 'remarks' => $remarks,
  144. 'apply_img' => $apply_img,
  145. 'seal_img' => $seal_img,
  146. ];
  147. $token = self::$token;
  148. return self::postRequest(self::$url . $url, compact('data', 'token'));
  149. }
  150. public static function fastIssuing($id, $link_id, $name, $id_card, $mobile, $bank_code, $money, $body)
  151. {
  152. $url = '/Enterprise/fastIssuing';
  153. $data = [
  154. 'trade_number' => 'SYYX' . $link_id . date('YmdHis') . rand(10000, 99999),
  155. 'crowd_id' => self::$crowd_id,
  156. 'issuing_data' => [[
  157. "professional_id" => $id,
  158. "name" => $name,
  159. "cer_code" => $id_card,
  160. "mobile" => $mobile,
  161. "bank_code" => $bank_code,
  162. "money" => $money,
  163. "remark" => $body,
  164. "request_no" => rand(1000, 9999) . "_" . $link_id,
  165. "professional_bank_id" => 0,
  166. "resolve_id" => self::$resolve_id
  167. ],]
  168. ];
  169. $token = self::$token;
  170. return self::postRequest(self::$url . $url, compact('data', 'token'));
  171. }
  172. public static function postRequest($url, $data)
  173. {
  174. $res = json_decode(self::do_request($url, $data, ['content-type:application/json'], true, true), true);
  175. if ($res['code'] == 200) {
  176. try {
  177. return self::decode($res['data'], $res['msg'] ?? '');
  178. } catch (\Exception $exception) {
  179. throw new ApiException($exception->getMessage());
  180. }
  181. } else {
  182. throw new ApiException($res['msg'] ?? '处理失败');
  183. }
  184. }
  185. private static function login()
  186. {
  187. $data = [
  188. 'user_name' => self::$user_name,
  189. 'password' => self::$password,
  190. 'timestamp' => time(),
  191. ];
  192. ksort($data);
  193. $signString = http_build_query($data) . '&secret=' . self::$secret;
  194. $sign = md5($signString);
  195. $data['sign'] = $sign;
  196. $res = json_decode(self::do_request(self::$url . '/sdk/v1/login', $data, ['content-type:application/json'], true, true), true);
  197. if ($res['code'] == 200) {
  198. return $res['token'];
  199. } else {
  200. throw new ApiException($res['msg'] ?? '企业登陆失败');
  201. }
  202. }
  203. /**
  204. * @param $businessBodyString
  205. * @return mixed
  206. */
  207. public static function decode($businessBodyString, $msg = '')
  208. {
  209. //进行Aes解密
  210. include_once 'phpseclib/Crypt/AES.php';
  211. $aes = new \Crypt_AES(CRYPT_AES_MODE_ECB);
  212. $aes->setKey(self::$aeskey);
  213. $data = $aes->decrypt(base64_decode($businessBodyString));
  214. return array_merge(json_decode(base64_decode($data), true), ['api_res_msg' => $msg]);
  215. }
  216. public static function checkSign($data, $sign)
  217. {
  218. ksort($data);
  219. $signString = http_build_query($data) . '&secret=' . self::$secret;
  220. $code = md5($signString);
  221. return trim($sign) === trim($code);
  222. }
  223. private static function do_request($url, $data, $header = null, $post = true, $json = false, $format = 0, $form = false)
  224. {
  225. $curl = curl_init();
  226. curl_setopt($curl, CURLOPT_URL, $url);
  227. curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
  228. curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
  229. if ($post) {
  230. curl_setopt($curl, CURLOPT_POST, 1);
  231. if (!$json && !$form) {
  232. curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
  233. } else if ($json && !$form) {
  234. curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data, $format));
  235. } else {
  236. curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
  237. }
  238. }
  239. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  240. if ($header) {
  241. curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
  242. curl_setopt($curl, CURLOPT_HEADER, 0);
  243. }
  244. $result = curl_exec($curl);
  245. if (curl_errno($curl)) {
  246. return json_encode(['status' => curl_errno($curl), 'msg' => '请求失败']);
  247. }
  248. curl_close($curl);
  249. return $result;
  250. }
  251. }