正在显示
1 个修改的文件
包含
0 行增加
和
98 行删除
@@ -16,102 +16,4 @@ class Resource | @@ -16,102 +16,4 @@ class Resource | ||
16 | $file_path = substr($file_path,strripos($file_path,"public")+6); | 16 | $file_path = substr($file_path,strripos($file_path,"public")+6); |
17 | return $file_path; | 17 | return $file_path; |
18 | } | 18 | } |
19 | - | ||
20 | - | ||
21 | - public function share($id, $path) | ||
22 | - { | ||
23 | - $access_token = $this->getWxAccessToken(); | ||
24 | - $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $access_token['access_token']; | ||
25 | - $post['path'] = $path; | ||
26 | - $post['scene'] = '?id=' . $id; | ||
27 | - $post['width'] = 400; | ||
28 | - $result = $this->httpRequest($url, json_encode($post), 'POST'); | ||
29 | - $array = json_decode($result, true); | ||
30 | - if ($array['errmsg']) { | ||
31 | - return ['code' => 1, 'msg' => $array['errmsg']]; | ||
32 | - } | ||
33 | - | ||
34 | - // 分享二维码保存到用户数 | ||
35 | - $date = date('Ymd'); | ||
36 | - if (!file_exists(ROOT_PATH . 'public' . DS . "uploads/qrcode/user/$date/")) { | ||
37 | - mkdir(ROOT_PATH . 'public' . DS . "uploads/qrcode/user/$date/", 0777, true); | ||
38 | - } | ||
39 | - $filename = "code_$id.png"; | ||
40 | - $furl = ROOT_PATH . 'public' . DS . "uploads/qrcode/user/$date/" . $filename; | ||
41 | - $filepath = "uploads/qrcode/user/$date/" . $filename; | ||
42 | - file_put_contents($furl, $result); | ||
43 | - $this->qiniu($furl, $filepath); | ||
44 | - return "/uploads/qrcode/user/$date/" . $filename; | ||
45 | - } | ||
46 | - function httpRequest($url, $data = '', $method = 'GET') | ||
47 | - { | ||
48 | - $curl = curl_init(); | ||
49 | - curl_setopt($curl, CURLOPT_URL, $url); | ||
50 | - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); | ||
51 | - curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); | ||
52 | - curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); | ||
53 | - curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); | ||
54 | - curl_setopt($curl, CURLOPT_AUTOREFERER, 1); | ||
55 | - if ($method == 'POST') { | ||
56 | - curl_setopt($curl, CURLOPT_POST, 1); | ||
57 | - if ($data != '') { | ||
58 | - curl_setopt($curl, CURLOPT_POSTFIELDS, $data); | ||
59 | - } | ||
60 | - } | ||
61 | - | ||
62 | - curl_setopt($curl, CURLOPT_TIMEOUT, 30); | ||
63 | - curl_setopt($curl, CURLOPT_HEADER, 0); | ||
64 | - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | ||
65 | - $result = curl_exec($curl); | ||
66 | - curl_close($curl); | ||
67 | - return $result; | ||
68 | - } | ||
69 | - | ||
70 | - function getWxAccessToken() | ||
71 | - { | ||
72 | - $config = (Config::get('wxchat'))['login']; | ||
73 | - $appid = $config['app_id']; | ||
74 | - $appsecret = $config['secret']; | ||
75 | - | ||
76 | - $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appid . "&secret=" . $appsecret; | ||
77 | - $access_token = $this->httpRequest($url); | ||
78 | - $access_token = json_decode($access_token, true); | ||
79 | - \think\Session::set('access_token_' . $appid, $access_token); | ||
80 | - \think\Session::set('expire_time_' . $appid, time() + 7000); //7000 | ||
81 | - return $access_token; | ||
82 | - | ||
83 | - } | ||
84 | - | ||
85 | - public function qiniu($filePath = '', $fileName = '') | ||
86 | - { | ||
87 | -// $filePath=ROOT_PATH.'public'.DS.'uploads'.DS.'20200224'.DS.'img1.jpg';//文件路径 | ||
88 | -// $fileName='public'.DS.'uploads'.DS.'20200224'.DS.'img1.jpg'; //七牛云上的名字 | ||
89 | -// $filePath = ROOT_PATH . 'public' . DS . 'uploads' . DS . '20200224' . DS . 'img2.jpg';//文件路径 | ||
90 | -// $fileName = 'public' . DS . 'uploads' . DS . '20200224' . DS . 'img2.jpg'; //七牛云上的名字,头部不带杠 | ||
91 | - | ||
92 | - $config = get_addon_config('qiniu'); | ||
93 | - $policy = array( | ||
94 | - 'saveKey' => $fileName, | ||
95 | - ); | ||
96 | - $auth = new Auth($config['accessKey'], $config['secretKey']); | ||
97 | - $token = $auth->uploadToken($config['bucket'], null, $config['expire'], $policy); | ||
98 | - $multipart = [ | ||
99 | - ['name' => 'token', 'contents' => $token], | ||
100 | - [ | ||
101 | - 'name' => 'file', | ||
102 | - 'contents' => fopen($filePath, 'r'), | ||
103 | - 'filename' => $fileName, | ||
104 | - ] | ||
105 | - ]; | ||
106 | - try { | ||
107 | - $client = new \GuzzleHttp\Client(); | ||
108 | - $res = $client->request('POST', $config['uploadurl'], [ | ||
109 | - 'multipart' => $multipart | ||
110 | - ]); | ||
111 | - $code = $res->getStatusCode(); | ||
112 | - //成功不做任何操作 | ||
113 | - } catch (\GuzzleHttp\Exception\ClientException $e) { | ||
114 | - // unlink($filePath); | ||
115 | - } | ||
116 | - } | ||
117 | } | 19 | } |
-
请 注册 或 登录 后发表评论