| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- /**
- * @Created by PhpStorm
- * @author: Kirin
- * @day: 2023/12/19
- * @time: 16:09
- */
- namespace crmeb\services;
- use crmeb\exceptions\ApiException;
- class WithdrawService
- {
- static $url = 'https://testshuichou.zhuoyankeji.com';
- // static $url = 'https://api.yeeshui.com';
- static $token;
- static $user_name = '星领测试';
- static $password = '123456';
- static $secret = '2a879ac637d65ced5ed5892e1bf82e4c';
- static $aeskey = '37d65ced5ed5892e';
- public static function init()
- {
- self::$token = CacheService::get('withdraw_token', '');
- if (!self::$token) {
- self::$token = self::login();
- CacheService::set('withdraw_token', self::$token, 500);
- }
- }
- public 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'] ?? '企业登陆失败');
- }
- }
- public static function request($url, $data)
- {
- $url = self::$url . $url;
- $data = ['token' => self::$token, 'data' => $data];
- return json_decode(self::do_request(self::$url . $url, $data, ['content-type:application/json'], true, true), true);
- }
- protected 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;
- }
- }
|