1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the overtrue/wechat. |
5
|
|
|
* |
6
|
|
|
* (c) overtrue <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the MIT license that is bundled |
9
|
|
|
* with this source code in the file LICENSE. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* QRCode.php. |
14
|
|
|
* |
15
|
|
|
* Part of Overtrue\WeChat. |
16
|
|
|
* |
17
|
|
|
* For the full copyright and license information, please view the LICENSE |
18
|
|
|
* file that was distributed with this source code. |
19
|
|
|
* |
20
|
|
|
* @author mingyoung <[email protected]> |
21
|
|
|
* @copyright 2016 |
22
|
|
|
* |
23
|
|
|
* @see https://github.com/overtrue |
24
|
|
|
* @see http://overtrue.me |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
namespace EasyWeChat\MiniProgram\QRCode; |
28
|
|
|
|
29
|
|
|
use EasyWeChat\MiniProgram\Core\AbstractMiniProgram; |
30
|
|
|
|
31
|
|
|
class QRCode extends AbstractMiniProgram |
32
|
|
|
{ |
33
|
|
|
const API_GET_WXACODE = 'https://api.weixin.qq.com/wxa/getwxacode'; |
34
|
|
|
const API_GET_WXACODE_UNLIMIT = 'http://api.weixin.qq.com/wxa/getwxacodeunlimit'; |
35
|
|
|
const API_CREATE_QRCODE = 'https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode'; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Get WXACode. |
39
|
|
|
* |
40
|
|
|
* @param string $path |
41
|
|
|
* @param int $width |
42
|
|
|
* @param bool $autoColor |
43
|
|
|
* @param array $lineColor |
44
|
|
|
* |
45
|
|
|
* @return \Psr\Http\Message\StreamInterface |
46
|
|
|
*/ |
47
|
|
View Code Duplication |
public function getAppCode($path, $width = 430, $autoColor = false, $lineColor = ['r' => 0, 'g' => 0, 'b' => 0]) |
48
|
|
|
{ |
49
|
|
|
$params = [ |
50
|
|
|
'path' => $path, |
51
|
|
|
'width' => $width, |
52
|
|
|
'auto_color' => $autoColor, |
53
|
|
|
'line_color' => $lineColor, |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
return $this->getStream(self::API_GET_WXACODE, $params); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Get WXACode unlimit. |
61
|
|
|
* |
62
|
|
|
* @param string $scene |
63
|
|
|
* @param int $width |
64
|
|
|
* @param bool $autoColor |
65
|
|
|
* @param array $lineColor |
66
|
|
|
* |
67
|
|
|
* @return \Psr\Http\Message\StreamInterface |
68
|
|
|
*/ |
69
|
|
View Code Duplication |
public function getAppCodeUnlimit($scene, $width = 430, $autoColor = false, $lineColor = ['r' => 0, 'g' => 0, 'b' => 0]) |
70
|
|
|
{ |
71
|
|
|
$params = [ |
72
|
|
|
'scene' => $scene, |
73
|
|
|
'width' => $width, |
74
|
|
|
'auto_color' => $autoColor, |
75
|
|
|
'line_color' => $lineColor, |
76
|
|
|
]; |
77
|
|
|
|
78
|
|
|
return $this->getStream(self::API_GET_WXACODE_UNLIMIT, $params); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Create QRCode. |
83
|
|
|
* |
84
|
|
|
* @param string $path |
85
|
|
|
* @param int $width |
86
|
|
|
* |
87
|
|
|
* @return \Psr\Http\Message\StreamInterface |
88
|
|
|
*/ |
89
|
|
|
public function createQRCode($path, $width = 430) |
90
|
|
|
{ |
91
|
|
|
return $this->getStream(self::API_CREATE_QRCODE, compact('path', 'width')); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Get stream. |
96
|
|
|
* |
97
|
|
|
* @param string $endpoint |
98
|
|
|
* @param array $params |
99
|
|
|
* |
100
|
|
|
* @return \Psr\Http\Message\StreamInterface |
101
|
|
|
*/ |
102
|
|
|
protected function getStream($endpoint, $params) |
103
|
|
|
{ |
104
|
|
|
return $this->getHttp()->json($endpoint, $params)->getBody(); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|