123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- <?php
- /**
- * @Created by PhpStorm
- * @author: Kirin
- * @day: 2023/12/19
- * @time: 16:09
- */
- namespace crmeb\services;
- use crmeb\exceptions\ApiException;
- use think\Exception;
- class WithdrawService
- {
- // static $url = 'https://testshuichou.zhuoyankeji.com';
- static $url = 'https://api.yeeshui.com';
- static $token;
- static $user_name = '浙江神英';
- static $password = '057682923388';
- static $secret = '56e6fded2e9d6e534656a2493d0bebba';
- static $aeskey = '2e9d6e534656a249';
- static $crowd_id = '15587';
- static $resolve_id = '7021';
- public function __construct($token)
- {
- self::$token = $token;
- }
- public static function init()
- {
- $token = CacheService::get('withdraw_token', '');
- if (!$token) {
- $token = self::login();
- CacheService::set('withdraw_token', $token, 500);
- }
- return new self($token);
- }
- /**
- * 新增人员
- * @param $name
- * @param $id_card
- * @param $bank_code
- * @param $mobile
- * @param $front_img
- * @param $back_img
- * @return mixed
- */
- public static function addEmployee($name, $id_card, $bank_code, $mobile, $front_img, $back_img)
- {
- $url = '/Enterprise/addEmployee';
- $data = [
- 'name' => $name,//姓名
- 'cer_code' => $id_card,//身份证号码
- 'bank_code' => $bank_code,//银行卡号
- 'mobile' => $mobile,//银行卡预留手机号
- 'has_auth' => 1,
- 'source' => 1,
- "sign_img" => "",
- "protocol_img" => "",
- "contract_img" => "",
- 'auth' => "2",
- 'cer_front_img' => $front_img,//身份证正面照
- 'cer_reverse_img' => $back_img,//身份证反面照
- ];
- $token = self::$token;
- return self::postRequest(self::$url . $url, compact('data', 'token'));
- }
- public static function applySignUrl($id)
- {
- $url = '/Enterprise/applySignUrl';
- $data = [
- 'professional_id' => $id,//姓名
- 'back_url' => sys_config('site_url'),//返回网址
- 'sign_type' => 'letsign',//银行卡号
- ];
- $token = self::$token;
- return self::postRequest(self::$url . $url, compact('data', 'token'));
- }
- public static function querySignResult($id)
- {
- $url = '/Enterprise/querySignResult';
- $data = [
- 'transactionCode' => $id,//姓名
- ];
- $token = self::$token;
- return self::postRequest(self::$url . $url, compact('data', 'token'));
- }
- public static function contractDo($id)
- {
- $url = '/Enterprise/contractDo';
- $data = [
- 'enterprise_professional_facilitator_id' => $id,//姓名
- ];
- $token = self::$token;
- return self::postRequest(self::$url . $url, compact('data', 'token'));
- }
- public static function contractInfo($id)
- {
- $url = '/Enterprise/contractInfo';
- $data = [
- 'enterprise_professional_facilitator_id' => $id,//姓名
- ];
- $token = self::$token;
- return self::postRequest(self::$url . $url, compact('data', 'token'));
- }
- public static function getOrderList($status = 0, $page = 1, $limit = 10)
- {
- $url = '/Enterprise/getOrderList';
- $data = [
- // 'enterprise_order_sn' => '',
- // 'states' => '',
- 'status' => $status,
- // 'reason' => '',
- // 'check_time_start' => '',
- // "check_time_end" => "",
- "pagination" => ['page_start' => $page, 'page_size' => $limit],
- ];
- $token = self::$token;
- return self::postRequest(self::$url . $url, compact('data', 'token'));
- }
- public static function getOrderExt($order_id, $page = 1, $limit = 10)
- {
- $url = '/Enterprise/getOrderExt';
- $data = [
- 'enterprise_order_id' => $order_id,
- "pagination" => ['page_start' => $page, 'page_size' => $limit],
- ];
- $token = self::$token;
- return self::postRequest(self::$url . $url, compact('data', 'token'));
- }
- public static function getOrderTemplate($order_id)
- {
- $url = '/Enterprise/getOrderTemplate';
- $data = [
- 'enterprise_order_id' => $order_id,
- ];
- $token = self::$token;
- return self::postRequest(self::$url . $url, compact('data', 'token'));
- }
- public static function changeOrderStatus($order_id, $apply_img, $seal_img, $status = 1, $remarks = '')
- {
- $url = '/Enterprise/changeOrderStatus';
- $data = [
- 'enterprise_order_id' => $order_id,
- 'status' => $status,
- 'remarks' => $remarks,
- 'apply_img' => $apply_img,
- 'seal_img' => $seal_img,
- ];
- $token = self::$token;
- return self::postRequest(self::$url . $url, compact('data', 'token'));
- }
- public static function fastIssuing($id, $link_id, $name, $id_card, $mobile, $bank_code, $money, $body)
- {
- $url = '/Enterprise/fastIssuing';
- $data = [
- 'trade_number' => 'SYYX' . $link_id . date('YmdHis') . rand(10000, 99999),
- 'crowd_id' => self::$crowd_id,
- 'issuing_data' => [[
- "professional_id" => $id,
- "name" => $name,
- "cer_code" => $id_card,
- "mobile" => $mobile,
- "bank_code" => $bank_code,
- "money" => $money,
- "remark" => $body,
- "request_no" => rand(1000, 9999) . "_" . $link_id,
- "professional_bank_id" => 0,
- "resolve_id" => self::$resolve_id
- ],]
- ];
- $token = self::$token;
- return self::postRequest(self::$url . $url, compact('data', 'token'));
- }
- public static function postRequest($url, $data)
- {
- $res = json_decode(self::do_request($url, $data, ['content-type:application/json'], true, true), true);
- if ($res['code'] == 200) {
- try {
- return self::decode($res['data'], $res['msg'] ?? '');
- } catch (\Exception $exception) {
- throw new ApiException($exception->getMessage());
- }
- } else {
- throw new ApiException($res['msg'] ?? '处理失败');
- }
- }
- private static function login()
- {
- $data = [
- 'user_name' => self::$user_name,
- 'password' => self::$password,
- 'timestamp' => time(),
- ];
- ksort($data);
- $signString = http_build_query($data) . '&secret=' . self::$secret;
- $sign = md5($signString);
- $data['sign'] = $sign;
- $res = json_decode(self::do_request(self::$url . '/sdk/v1/login', $data, ['content-type:application/json'], true, true), true);
- if ($res['code'] == 200) {
- return $res['token'];
- } else {
- throw new ApiException($res['msg'] ?? '企业登陆失败');
- }
- }
- /**
- * @param $businessBodyString
- * @return mixed
- */
- public static function decode($businessBodyString, $msg = '')
- {
- //进行Aes解密
- include_once 'phpseclib/Crypt/AES.php';
- $aes = new \Crypt_AES(CRYPT_AES_MODE_ECB);
- $aes->setKey(self::$aeskey);
- $data = $aes->decrypt(base64_decode($businessBodyString));
- return array_merge(json_decode(base64_decode($data), true), ['api_res_msg' => $msg]);
- }
- public static function checkSign($data, $sign)
- {
- ksort($data);
- $signString = http_build_query($data) . '&secret=' . self::$secret;
- $code = md5($signString);
- return trim($sign) === trim($code);
- }
- private static function do_request($url, $data, $header = null, $post = true, $json = false, $format = 0, $form = false)
- {
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
- curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
- if ($post) {
- curl_setopt($curl, CURLOPT_POST, 1);
- if (!$json && !$form) {
- curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
- } else if ($json && !$form) {
- curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data, $format));
- } else {
- curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
- }
- }
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- if ($header) {
- curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
- curl_setopt($curl, CURLOPT_HEADER, 0);
- }
- $result = curl_exec($curl);
- if (curl_errno($curl)) {
- return json_encode(['status' => curl_errno($curl), 'msg' => '请求失败']);
- }
- curl_close($curl);
- return $result;
- }
- }
|