UserTrait.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 getShortUserInfo($uid) {
  13. try {
  14. $url = config("customer.manage_service_url").'/user/v2/short/info';
  15. $array = [
  16. 'json' => ['uid' => $uid], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
  17. ];
  18. return http($url,$array, false, 'get');
  19. } catch (\Exception $e) {
  20. return [];
  21. }
  22. }
  23. public function getUserInfo($uid) {
  24. try {
  25. $url = config("customer.manage_service_url").'/user/memberView';
  26. $array = [
  27. 'json' => ['uid' => $uid], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
  28. ];
  29. return http($url,$array, true, 'get');
  30. } catch (\Exception $e) {
  31. return [];
  32. }
  33. }
  34. public function getSystemMember($number) {
  35. try {
  36. $url = config("customer.manage_service_url").'/user/member/getSystemMember';
  37. $array = [
  38. 'json' => ['number' => $number], 'query' => [], 'http_errors' => false,'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
  39. ];
  40. return http($url,$array, false, 'get');
  41. } catch (\Exception $e) {
  42. return [];
  43. }
  44. }
  45. public function uploadImage($img) {
  46. $path = public_path('image');
  47. if (!file_exists($path)){
  48. mkdir ($path,0777,true);
  49. }
  50. $fileUrl = $path.date('/Ymd').time().'.jpg';
  51. $content = file_get_contents($img);
  52. file_put_contents($fileUrl, $content);
  53. try {
  54. $url = config("customer.manage_service_url").'/config/upload';
  55. $array = [
  56. 'multipart' => [
  57. [
  58. 'name' => 'image',
  59. 'contents' => fopen($fileUrl, 'r'),
  60. 'headers' => ['X-Baz' => 'bar'],
  61. 'filename' => $fileUrl
  62. ]
  63. ],
  64. 'query' => [],
  65. 'http_errors' => false,
  66. 'headers'=>['Authorization'=>"Bearer ".JWTAuth::getToken()]
  67. ];
  68. $ossUrl = http($url,$array, false, 'post');
  69. } catch (\Exception $e) {
  70. $ossUrl = '';
  71. }
  72. unlink($fileUrl);
  73. return $ossUrl;
  74. }
  75. function downDown($file_url)
  76. {
  77. }
  78. }