*
Showing
3 changed files
with
130 additions
and
0 deletions
app/Helper/Http.php
0 → 100644
1 | <?php | ||
2 | |||
3 | |||
4 | namespace App\Helper; | ||
5 | |||
6 | |||
7 | use GuzzleHttp\Client; | ||
8 | use Illuminate\Support\Facades\Log; | ||
9 | |||
10 | /** | ||
11 | * Class Response | ||
12 | * @package App\Helper | ||
13 | */ | ||
14 | class Http | ||
15 | { | ||
16 | const METHOD_POST = 'POST'; | ||
17 | const METHOD_GET = 'GET'; | ||
18 | |||
19 | /** | ||
20 | * @param $url | ||
21 | * @param array $params | ||
22 | * @return array|mixed | ||
23 | * @throws \GuzzleHttp\Exception\GuzzleException | ||
24 | */ | ||
25 | public static function post($uri, $params = []) | ||
26 | { | ||
27 | $url = self::formatUrl($uri); | ||
28 | |||
29 | try { | ||
30 | $response = (new Client())->request(self::METHOD_POST, $url, [ | ||
31 | 'json'=>$params | ||
32 | ]); | ||
33 | |||
34 | $data = json_decode($response->getBody()->getContents(), true); | ||
35 | |||
36 | Log::info(__METHOD__, ['url'=>$url, 'params'=>$params, 'data'=>$data]); | ||
37 | |||
38 | return $data; | ||
39 | |||
40 | } catch (\Exception $e) { | ||
41 | Log::info(__METHOD__, ['msg'=>$e->getMessage()]); | ||
42 | return []; | ||
43 | } | ||
44 | } | ||
45 | |||
46 | /** | ||
47 | * @param $url | ||
48 | * @return array|mixed | ||
49 | * @throws \GuzzleHttp\Exception\GuzzleException | ||
50 | */ | ||
51 | public static function get($uri) | ||
52 | { | ||
53 | $url = self::formatUrl($uri); | ||
54 | |||
55 | try { | ||
56 | $response = (new Client())->request(self::METHOD_POST, $url); | ||
57 | |||
58 | $data = json_decode($response->getBody()->getContents(), true); | ||
59 | |||
60 | Log::info(__METHOD__, ['url'=>$url, 'data'=>$data]); | ||
61 | |||
62 | return $data; | ||
63 | |||
64 | } catch (\Exception $e) { | ||
65 | Log::info(__METHOD__, ['msg'=>$e->getMessage()]); | ||
66 | return []; | ||
67 | } | ||
68 | } | ||
69 | |||
70 | /** | ||
71 | * @param $uri | ||
72 | * @return string | ||
73 | */ | ||
74 | public static function formatUrl($uri) | ||
75 | { | ||
76 | return env('musician_url') . $uri; | ||
77 | } | ||
78 | |||
79 | |||
80 | |||
81 | |||
82 | } |
1 | <?php | ||
2 | |||
3 | namespace App\Http\Requests\Musician; | ||
4 | |||
5 | use Illuminate\Foundation\Http\FormRequest; | ||
6 | |||
7 | class MusicianWithdrawReceiptByNameRequest extends FormRequest | ||
8 | { | ||
9 | /** | ||
10 | * Determine if the user is authorized to make this request. | ||
11 | * | ||
12 | * @return bool | ||
13 | */ | ||
14 | public function authorize() | ||
15 | { | ||
16 | return true; | ||
17 | } | ||
18 | |||
19 | /** | ||
20 | * Get the validation rules that apply to the request. | ||
21 | * | ||
22 | * @return array | ||
23 | */ | ||
24 | public function rules() | ||
25 | { | ||
26 | return [ | ||
27 | 'name' => ['required', 'bail', 'string'], | ||
28 | ]; | ||
29 | } | ||
30 | |||
31 | /** | ||
32 | * @return string[] | ||
33 | */ | ||
34 | public function messages(): array | ||
35 | { | ||
36 | return [ | ||
37 | 'name.required' => '请提供发票单位名称', | ||
38 | ]; | ||
39 | } | ||
40 | } |
-
Please register or sign in to post a comment