UserTrait.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/6/11
  6. * Time: 17:50
  7. */
  8. namespace App\Traits;
  9. use Tymon\JWTAuth\Facades\JWTAuth;
  10. trait UserTrait
  11. {
  12. public function getUserInfo($uid) {
  13. try {
  14. $url = config("customer.manage_service_url").'/user/memberView';
  15. $array = [
  16. 'json' => ['uid' => $uid], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
  17. ];
  18. return http($url,$array, true, 'get');
  19. } catch (\Exception $e) {
  20. return [];
  21. }
  22. }
  23. public function getSystemMember($number) {
  24. try {
  25. $url = config("customer.manage_service_url").'/user/member/getSystemMember';
  26. $array = [
  27. 'json' => ['number' => $number], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
  28. ];
  29. return http($url,$array, false, 'get');
  30. } catch (\Exception $e) {
  31. return [];
  32. }
  33. }
  34. public function uploadImage($img) {
  35. $path = public_path('image');
  36. if (!file_exists($path)){
  37. mkdir ($path,0777,true);
  38. }
  39. $fileUrl = $path.date('/Ymd').time().'.jpg';
  40. $content = file_get_contents($img);
  41. file_put_contents($fileUrl, $content);
  42. try {
  43. $url = config("customer.manage_service_url").'/config/upload';
  44. $array = [
  45. 'multipart' => [
  46. [
  47. 'name' => 'image',
  48. 'contents' => 'data',
  49. 'headers' => ['X-Baz' => 'bar'],
  50. 'filename' => $fileUrl
  51. ]
  52. ],
  53. 'query' => [],
  54. 'http_errors' => false,
  55. 'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
  56. ];
  57. $ossUrl = http($url,$array, false, 'post');
  58. } catch (\Exception $e) {
  59. $ossUrl = '';
  60. }
  61. unlink($fileUrl);
  62. return $ossUrl;
  63. }
  64. function downDown($file_url)
  65. {
  66. }
  67. }