Passed
Push — master ( 5657ba...3032ea )
by Wei
02:21
created
src/HttpClient.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -5,9 +5,9 @@  discard block
 block discarded – undo
5 5
  */
6 6
 namespace zhangv\wechat;
7 7
 
8
-class HttpClient{
8
+class HttpClient {
9 9
 
10
-	const GET = 'get',POST = 'post', DELETE = 'delete',PUT = 'put';
10
+	const GET = 'get', POST = 'post', DELETE = 'delete', PUT = 'put';
11 11
 	private $instance = null;
12 12
 	private $errNo = null;
13 13
 	private $info = null;
@@ -17,12 +17,12 @@  discard block
 block discarded – undo
17 17
 		$this->initInstance($timeout);
18 18
 	}
19 19
 
20
-	public function initInstance($timeout){
21
-		if(!$this->instance) {
20
+	public function initInstance($timeout) {
21
+		if (!$this->instance) {
22 22
 			$this->instance = curl_init();
23 23
 			if ($timeout < 1) {
24 24
 				curl_setopt($this->instance, CURLOPT_TIMEOUT_MS, intval($timeout * 1000));
25
-			} else {
25
+			}else {
26 26
 				curl_setopt($this->instance, CURLOPT_TIMEOUT, intval($timeout));
27 27
 			}
28 28
 			curl_setopt($this->instance, CURLOPT_RETURNTRANSFER, true);
@@ -31,26 +31,26 @@  discard block
 block discarded – undo
31 31
 		}
32 32
 	}
33 33
 
34
-	public function get($url,$params = array(),$headers = array(),$opts = array()) {
34
+	public function get($url, $params = array(), $headers = array(), $opts = array()) {
35 35
 		if (!$this->instance)	$this->initInstance($this->timeout);
36
-		if($params && count($params) > 0) $url .= '?' . http_build_query($params);
36
+		if ($params && count($params) > 0) $url .= '?'.http_build_query($params);
37 37
 		curl_setopt($this->instance, CURLOPT_URL, $url);
38 38
 		curl_setopt($this->instance, CURLOPT_HTTPGET, true);
39 39
 		curl_setopt($this->instance, CURLOPT_HTTPHEADER, $headers);
40
-		curl_setopt_array($this->instance,$opts);
40
+		curl_setopt_array($this->instance, $opts);
41 41
 		$result = $this->execute();
42 42
 		curl_close($this->instance);
43 43
 		$this->instance = null;
44 44
 		return $result;
45 45
 	}
46 46
 
47
-	public function post($url, $params = array(),$headers = array(),$opts = array()) {
47
+	public function post($url, $params = array(), $headers = array(), $opts = array()) {
48 48
 		if (!$this->instance)	$this->initInstance($this->timeout);
49 49
 		curl_setopt($this->instance, CURLOPT_URL, $url);
50 50
 		curl_setopt($this->instance, CURLOPT_POST, true);
51 51
 		curl_setopt($this->instance, CURLOPT_POSTFIELDS, $params);
52 52
 		curl_setopt($this->instance, CURLOPT_HTTPHEADER, $headers);
53
-		curl_setopt_array($this->instance,$opts);
53
+		curl_setopt_array($this->instance, $opts);
54 54
 		$result = $this->execute();
55 55
 		curl_close($this->instance);
56 56
 		$this->instance = null;
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 		curl_setopt_array($this->instance, $optArray);
71 71
 	}
72 72
 
73
-	public function getInfo(){
73
+	public function getInfo() {
74 74
 		return $this->info;
75 75
 	}
76 76
 }
77 77
\ No newline at end of file
Please login to merge, or discard this patch.
src/WechatOAuth.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -17,50 +17,50 @@  discard block
 block discarded – undo
17 17
 	private $httpClient = null;
18 18
 	private $accessToken = null;
19 19
 
20
-	public function __construct($appId,$appSecret) {
20
+	public function __construct($appId, $appSecret) {
21 21
 		$this->appId = $appId;
22 22
 		$this->appSecret = $appSecret;
23 23
 		$this->httpClient = new HttpClient();
24 24
 	}
25 25
 
26
-	public function setHttpClient($httpClient){
26
+	public function setHttpClient($httpClient) {
27 27
 		$this->httpClient = $httpClient;
28 28
 	}
29 29
 
30
-	public function setAccessToken($accessToken){
30
+	public function setAccessToken($accessToken) {
31 31
 		$this->accessToken = $accessToken;
32 32
 	}
33 33
 
34
-	public function authorizeURI($redirectURI,$scope = 'snsapi_userinfo',$state = ''){
34
+	public function authorizeURI($redirectURI, $scope = 'snsapi_userinfo', $state = '') {
35 35
 		$redirectURI = urlencode($redirectURI);
36 36
 		return "https://open.weixin.qq.com/connect/oauth2/authorize?appid={$this->appId}&redirect_uri={$redirectURI}&response_type=code&scope=$scope&state=$state#wechat_redirect";
37 37
 	}
38 38
 
39
-	public function authorize($code){
39
+	public function authorize($code) {
40 40
 		$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$this->appId}&secret={$this->appSecret}&code=$code&grant_type=authorization_code";
41 41
 		$this->responseJSON = $this->httpClient->get($url);
42 42
 		return json_decode($this->responseJSON);
43 43
 	}
44 44
 
45
-	public function getUserInfo($openId){
45
+	public function getUserInfo($openId) {
46 46
 		$url = "https://api.weixin.qq.com/sns/userinfo?access_token={$this->accessToken}&openid=$openId&lang=zh_CN";
47 47
 		$this->responseJSON = $this->httpClient->get($url);
48 48
 		return json_decode($this->responseJSON);
49 49
 	}
50 50
 
51
-	public function refreshToken($refreshToken){
51
+	public function refreshToken($refreshToken) {
52 52
 		$url = "https://api.weixin.qq.com/sns/oauth2/refresh_token?appid={$this->appId}&grant_type=refresh_token&refresh_token=$refreshToken";
53 53
 		$this->responseJSON = $this->httpClient->get($url);
54 54
 		return $this->responseJSON;
55 55
 	}
56 56
 
57
-	public function verifyToken($accessToken,$openId){
57
+	public function verifyToken($accessToken, $openId) {
58 58
 		$url = "https://api.weixin.qq.com/sns/auth?access_token=$accessToken&openid=$openId";
59 59
 		$this->responseJSON = $this->httpClient->get($url);
60 60
 		return $this->responseJSON;
61 61
 	}
62 62
 
63
-	public function getAccessToken(){
63
+	public function getAccessToken() {
64 64
 		$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$this->appId}&secret={$this->appSecret}";
65 65
 		$this->responseJSON = $this->httpClient->get($url);
66 66
 		$json = json_decode($this->responseJSON);
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 		return $this->accessToken;
69 69
 	}
70 70
 
71
-	public function getTicket(){
71
+	public function getTicket() {
72 72
 		$accessToken = $this->getAccessToken();
73 73
 		// $url = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=$accessToken";
74 74
 		$url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=$accessToken";
Please login to merge, or discard this patch.
demo/pay.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 //公众号支付
3
-require_once __DIR__ ."/../src/WechatPay.php";
3
+require_once __DIR__."/../src/WechatPay.php";
4 4
 use zhangv\wechat\WechatPay;
5 5
 $cfg = include './config.php';
6 6
 
7
-if(empty( $_REQUEST['openid'])) {
7
+if (empty($_REQUEST['openid'])) {
8 8
 	$redirect = "http://{$_SERVER['HTTP_HOST']}/wechat-pay/demo/wxoauth.php";
9 9
 	header('Location: '.$redirect);
10 10
 	exit;
Please login to merge, or discard this patch.
demo/paidnotify.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -3,9 +3,9 @@
 block discarded – undo
3 3
 
4 4
 $cfg = require './config.php';
5 5
 $payment = new WechatPay($cfg);
6
-$payment->onPaidNotify($xml,function($notifydata) use ($payment){
6
+$payment->onPaidNotify($xml, function($notifydata) use ($payment){
7 7
 	//do stuff
8 8
 	print_r($notifydata);
9
-	$payment->responseNotify('SUCCESS','OK');
9
+	$payment->responseNotify('SUCCESS', 'OK');
10 10
 });
11 11
 
Please login to merge, or discard this patch.
demo/pay-app.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@
 block discarded – undo
1 1
 <?php
2 2
 //APP支付 - 获取预支付交易回话标识
3 3
 //注意:APP支付使用的是开放平台的APPID
4
-require_once __DIR__ ."/../src/WechatPay.php";
4
+require_once __DIR__."/../src/WechatPay.php";
5 5
 use zhangv\wechat\WechatPay;
6 6
 
7 7
 $cfg = include './config.php';
Please login to merge, or discard this patch.
demo/pay-qrcode.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 //扫码支付
3
-require_once __DIR__ ."/../src/WechatPay.php";
3
+require_once __DIR__."/../src/WechatPay.php";
4 4
 use zhangv\wechat\WechatPay;
5 5
 
6 6
 $cfg = include './config.php';
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 $desc = "desc$stamp";
12 12
 $productid = "testproduct";
13 13
 $amt = 1;
14
-$codeurl = $payment->getCodeUrl($desc, $orderid, $amt,$productid);
14
+$codeurl = $payment->getCodeUrl($desc, $orderid, $amt, $productid);
15 15
 
16 16
 ?>
17 17
 <script type="text/javascript" src="js/jquery.js"></script>
Please login to merge, or discard this patch.
demo/wxoauthcallback.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,23 +1,23 @@
 block discarded – undo
1 1
 <?php
2
-require_once __DIR__ ."/../src/WechatOAuth.php";
3
-require_once __DIR__ ."/../src/HttpClient.php";
2
+require_once __DIR__."/../src/WechatOAuth.php";
3
+require_once __DIR__."/../src/HttpClient.php";
4 4
 use zhangv\wechat\WechatOAuth;
5 5
 
6
-if (isset($_GET['code'])){
6
+if (isset($_GET['code'])) {
7 7
 	$cfg = require './config.php';
8 8
 
9 9
 	$code = trim($_GET['code']);
10 10
 	$state = trim($_GET['state']);
11
-	$oauth = new WechatOAuth($cfg['app_id'],$cfg['app_secret']);
11
+	$oauth = new WechatOAuth($cfg['app_id'], $cfg['app_secret']);
12 12
 	$at = $oauth->authorize($code);
13 13
 
14
-	if(!$at || empty($at->openid)){
14
+	if (!$at || empty($at->openid)) {
15 15
 		die('授权失败');
16
-	}else{
16
+	}else {
17 17
 		$accesstoken = $at->access_token;
18 18
 		$openid = $at->openid;
19 19
 		header('Location: '."http://{$_SERVER['HTTP_HOST']}/wechat-pay/demo/pay.php?openid=$openid");
20 20
 	}
21
-}else{
21
+}else {
22 22
 	die('授权失败,请重试。');
23 23
 }
24 24
\ No newline at end of file
Please login to merge, or discard this patch.
demo/wxoauth.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2
-require_once __DIR__ ."/../src/WechatOAuth.php";
3
-require_once __DIR__ ."/../src/HttpClient.php";
2
+require_once __DIR__."/../src/WechatOAuth.php";
3
+require_once __DIR__."/../src/HttpClient.php";
4 4
 use zhangv\wechat\WechatOAuth;
5 5
 
6 6
 $cfg = require './config.php';
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 $redirect = "http://{$_SERVER['HTTP_HOST']}/wechat-pay/demo/wxoauthcallback.php";
9 9
 $scope = 'snsapi_userinfo';
10 10
 $state = "";
11
-$oauth =new WechatOAuth($appid,$cfg['app_secret']);
12
-$url = $oauth->authorizeURI($redirect,$scope);
11
+$oauth = new WechatOAuth($appid, $cfg['app_secret']);
12
+$url = $oauth->authorizeURI($redirect, $scope);
13 13
 
14 14
 header('Location: '.$redirect);
15 15
\ No newline at end of file
Please login to merge, or discard this patch.
demo/refundednotify.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@
 block discarded – undo
1 1
 <?php
2
-require_once __DIR__ ."/../src/WechatPay.php";
2
+require_once __DIR__."/../src/WechatPay.php";
3 3
 use zhangv\wechat\WechatPay;
4 4
 
5 5
 $xml = file_get_contents("php://input");
6 6
 
7 7
 $cfg = require './config.php';
8 8
 $payment = new WechatPay($cfg);
9
-$payment->onRefundedNotify($xml,function($notifydata) use ($payment){
9
+$payment->onRefundedNotify($xml, function($notifydata) use ($payment){
10 10
 	//do stuff
11 11
 	print_r($notifydata);
12 12
 	$payment->responseNotify();
Please login to merge, or discard this patch.