@@ -1,7 +1,7 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | //h5支付 |
4 | -require_once __DIR__ . "/autoload.php"; |
|
4 | +require_once __DIR__."/autoload.php"; |
|
5 | 5 | use zhangv\wechat\WechatPay; |
6 | 6 | |
7 | 7 | $cfg = include './config.php'; |
@@ -1,15 +1,15 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | -require_once __DIR__ . "/autoload.php"; |
|
3 | +require_once __DIR__."/autoload.php"; |
|
4 | 4 | use zhangv\wechat\WechatPay; |
5 | 5 | |
6 | 6 | $xml = file_get_contents("php://input"); |
7 | 7 | |
8 | 8 | $cfg = require './config.php'; |
9 | 9 | $payment = new WechatPay($cfg); |
10 | -$payment->onPaidNotify($xml,function($notifydata) use ($payment){ |
|
10 | +$payment->onPaidNotify($xml, function($notifydata) use ($payment){ |
|
11 | 11 | //do stuff |
12 | 12 | print_r($notifydata); |
13 | - $payment->responseNotify('SUCCESS','OK'); |
|
13 | + $payment->responseNotify('SUCCESS', 'OK'); |
|
14 | 14 | }); |
15 | 15 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | namespace zhangv\wechat; |
7 | 7 | |
8 | 8 | class WechatOAuth { |
9 | - const TICKETTYPE_JSAPI = 'jsapi',TICKETTYPE_WXCARD = 'wx_card'; |
|
9 | + const TICKETTYPE_JSAPI = 'jsapi', TICKETTYPE_WXCARD = 'wx_card'; |
|
10 | 10 | public $responseJSON = null; |
11 | 11 | public $errCode = null; |
12 | 12 | public $errMsg = null; |
@@ -16,50 +16,50 @@ discard block |
||
16 | 16 | private $httpClient = null; |
17 | 17 | private $accessToken = null; |
18 | 18 | |
19 | - public function __construct($appId,$appSecret) { |
|
19 | + public function __construct($appId, $appSecret) { |
|
20 | 20 | $this->appId = $appId; |
21 | 21 | $this->appSecret = $appSecret; |
22 | 22 | $this->httpClient = new HttpClient(); |
23 | 23 | } |
24 | 24 | |
25 | - public function setHttpClient($httpClient){ |
|
25 | + public function setHttpClient($httpClient) { |
|
26 | 26 | $this->httpClient = $httpClient; |
27 | 27 | } |
28 | 28 | |
29 | - public function setAccessToken($accessToken){ |
|
29 | + public function setAccessToken($accessToken) { |
|
30 | 30 | $this->accessToken = $accessToken; |
31 | 31 | } |
32 | 32 | |
33 | - public function authorizeURI($redirectURI,$scope = 'snsapi_userinfo',$state = ''){ |
|
33 | + public function authorizeURI($redirectURI, $scope = 'snsapi_userinfo', $state = '') { |
|
34 | 34 | $redirectURI = urlencode($redirectURI); |
35 | 35 | return "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$this->appId}&redirect_uri={$redirectURI}&response_type=code&scope=$scope&state=$state#wechat_redirect"; |
36 | 36 | } |
37 | 37 | |
38 | - public function authorize($code){ |
|
38 | + public function authorize($code) { |
|
39 | 39 | $url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$this->appId}&secret={$this->appSecret}&code=$code&grant_type=authorization_code"; |
40 | 40 | $this->responseJSON = $this->httpClient->get($url); |
41 | 41 | return json_decode($this->responseJSON); |
42 | 42 | } |
43 | 43 | |
44 | - public function getUserInfo($openId){ |
|
44 | + public function getUserInfo($openId) { |
|
45 | 45 | $url = "https://api.weixin.qq.com/sns/userinfo?access_token={$this->accessToken}&openid=$openId&lang=zh_CN"; |
46 | 46 | $this->responseJSON = $this->httpClient->get($url); |
47 | 47 | return json_decode($this->responseJSON); |
48 | 48 | } |
49 | 49 | |
50 | - public function refreshToken($refreshToken){ |
|
50 | + public function refreshToken($refreshToken) { |
|
51 | 51 | $url = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid={$this->appId}&grant_type=refresh_token&refresh_token=$refreshToken"; |
52 | 52 | $this->responseJSON = $this->httpClient->get($url); |
53 | 53 | return $this->responseJSON; |
54 | 54 | } |
55 | 55 | |
56 | - public function verifyToken($accessToken,$openId){ |
|
56 | + public function verifyToken($accessToken, $openId) { |
|
57 | 57 | $url = "https://api.weixin.qq.com/sns/auth?access_token=$accessToken&openid=$openId"; |
58 | 58 | $this->responseJSON = $this->httpClient->get($url); |
59 | 59 | return $this->responseJSON; |
60 | 60 | } |
61 | 61 | |
62 | - public function getAccessToken(){ |
|
62 | + public function getAccessToken() { |
|
63 | 63 | $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$this->appId}&secret={$this->appSecret}"; |
64 | 64 | $this->responseJSON = $this->httpClient->get($url); |
65 | 65 | $json = json_decode($this->responseJSON); |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | return $this->accessToken; |
68 | 68 | } |
69 | 69 | |
70 | - public function getTicket($type = WechatOAuth::TICKETTYPE_JSAPI){ |
|
70 | + public function getTicket($type = WechatOAuth::TICKETTYPE_JSAPI) { |
|
71 | 71 | $accessToken = $this->getAccessToken(); |
72 | 72 | // $url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=$accessToken"; |
73 | 73 | $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type={$type}&access_token=$accessToken"; |