正在显示
2 个修改的文件
包含
49 行增加
和
46 行删除
@@ -203,51 +203,5 @@ class Car extends Backend | @@ -203,51 +203,5 @@ class Car extends Backend | ||
203 | $this->success(); | 203 | $this->success(); |
204 | } | 204 | } |
205 | 205 | ||
206 | - function getAccessToken() { | ||
207 | - $appId = "wx58ceff4e93cfc523"; | ||
208 | - $appSecret = "baf744d21875280a5e98611f66adaf91"; | ||
209 | - $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appId}&secret={$appSecret}"; | ||
210 | - $result = json_decode(file_get_contents($url), true); | ||
211 | - return $result["access_token"] ?? null; | ||
212 | - } | ||
213 | - | ||
214 | - function createMiniProgramQRCode($accessToken, $path, $width = 430) { | ||
215 | - $url = "https://api.weixin.qq.com/shop/funds/qrcode/gen?access_token={$accessToken}"; | ||
216 | - | ||
217 | - $data = json_encode([ | ||
218 | - 'path' => $path, | ||
219 | - 'width' => $width | ||
220 | - ]); | ||
221 | - $options = [ | ||
222 | - 'http' => [ | ||
223 | - 'method' => 'POST', | ||
224 | - 'header' => 'Content-type:application/json', | ||
225 | - 'content' => $data, | ||
226 | - ], | ||
227 | - ]; | ||
228 | - $context = stream_context_create($options); | ||
229 | - $result = file_get_contents($url, false, $context); | ||
230 | - print_r($result);return; | ||
231 | 206 | ||
232 | - if ($result === false) { | ||
233 | - return false; | ||
234 | - } | ||
235 | - return $result; | ||
236 | - } | ||
237 | - public function test(){ | ||
238 | - $accessToken = $this->getAccessToken(); | ||
239 | - if ($accessToken) { | ||
240 | - $path = 'pages/index/index'; // 小程序内的页面路径 | ||
241 | - $qrCodeData = $this->createMiniProgramQRCode($accessToken, $path); | ||
242 | - | ||
243 | - if ($qrCodeData) { | ||
244 | - header('Content-Type: image/png'); | ||
245 | - echo $qrCodeData; | ||
246 | - } else { | ||
247 | - echo "Failed to generate QR code."; | ||
248 | - } | ||
249 | - } else { | ||
250 | - echo "Failed to get access token."; | ||
251 | - } | ||
252 | - } | ||
253 | } | 207 | } |
@@ -20,4 +20,53 @@ class Index extends Api | @@ -20,4 +20,53 @@ class Index extends Api | ||
20 | { | 20 | { |
21 | $this->success('请求成功'); | 21 | $this->success('请求成功'); |
22 | } | 22 | } |
23 | + | ||
24 | + | ||
25 | + function getAccessToken() { | ||
26 | + $appId = "wx58ceff4e93cfc523"; | ||
27 | + $appSecret = "baf744d21875280a5e98611f66adaf91"; | ||
28 | + $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appId}&secret={$appSecret}"; | ||
29 | + $result = json_decode(file_get_contents($url), true); | ||
30 | + return $result["access_token"] ?? null; | ||
31 | + } | ||
32 | + | ||
33 | + function createMiniProgramQRCode($accessToken, $path, $width = 430) { | ||
34 | + $url = "https://api.weixin.qq.com/shop/funds/qrcode/gen?access_token={$accessToken}"; | ||
35 | + | ||
36 | + $data = json_encode([ | ||
37 | + 'path' => $path, | ||
38 | + 'width' => $width | ||
39 | + ]); | ||
40 | + $options = [ | ||
41 | + 'http' => [ | ||
42 | + 'method' => 'POST', | ||
43 | + 'header' => 'Content-type:application/json', | ||
44 | + 'content' => $data, | ||
45 | + ], | ||
46 | + ]; | ||
47 | + $context = stream_context_create($options); | ||
48 | + $result = file_get_contents($url, false, $context); | ||
49 | + print_r($result);return; | ||
50 | + | ||
51 | + if ($result === false) { | ||
52 | + return false; | ||
53 | + } | ||
54 | + return $result; | ||
55 | + } | ||
56 | + public function test(){ | ||
57 | + $accessToken = $this->getAccessToken(); | ||
58 | + if ($accessToken) { | ||
59 | + $path = 'pages/index/index'; // 小程序内的页面路径 | ||
60 | + $qrCodeData = $this->createMiniProgramQRCode($accessToken, $path); | ||
61 | + | ||
62 | + if ($qrCodeData) { | ||
63 | + header('Content-Type: image/png'); | ||
64 | + echo $qrCodeData; | ||
65 | + } else { | ||
66 | + echo "Failed to generate QR code."; | ||
67 | + } | ||
68 | + } else { | ||
69 | + echo "Failed to get access token."; | ||
70 | + } | ||
71 | + } | ||
23 | } | 72 | } |
-
请 注册 或 登录 后发表评论