Completed
Push — master ( d444bc...935144 )
by Wei
07:33
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/config.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -5,14 +5,14 @@
 block discarded – undo
5 5
 	'app_id'            => 'XXXXXXXXXXXXXXXXXXX', //APPID
6 6
 	'app_secret'        => 'XXXXXXXXXXXXXXXXXXXXXXXXX', //App Secret
7 7
 	'api_key'           =>'XXXXXXXXXXXXXXXXXXXXXXX', //支付密钥
8
-	'ssl_cert_path'     => __DIR__ . '/../cert/apiclient_cert.pem',
9
-	'ssl_key_path'      => __DIR__ .'/../cert/apiclient_key.pem',
8
+	'ssl_cert_path'     => __DIR__.'/../cert/apiclient_cert.pem',
9
+	'ssl_key_path'      => __DIR__.'/../cert/apiclient_key.pem',
10 10
 	'sign_type'         => 'MD5',
11 11
 	'notify_url'        => 'http://XXX.XXX/paidnotify.php',
12 12
 	'refund_notify_url' => 'http://XXX.XXX/refundednotify.php',
13 13
 	'h5_scene_info'     => [//required in H5
14 14
 		'h5_info' => ['type' => 'Wap', 'wap_url' => 'http://wapurl', 'wap_name' => 'wapname']
15 15
 	],
16
-	'rsa_pubkey_path'   => __DIR__ .'/../cert/pubkey.pem',
17
-	'jsapi_ticket'      => __DIR__ .'/jsapi_ticket.json'
16
+	'rsa_pubkey_path'   => __DIR__.'/../cert/pubkey.pem',
17
+	'jsapi_ticket'      => __DIR__.'/jsapi_ticket.json'
18 18
 ];
19 19
\ No newline at end of file
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,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 //扫码支付
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';
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
 $desc = "desc$stamp";
13 13
 $productid = "testproduct";
14 14
 $amt = 1;
15
-$codeurl = $payment->getCodeUrl($desc, $orderid, $amt,$productid);
15
+$codeurl = $payment->getCodeUrl($desc, $orderid, $amt, $productid);
16 16
 
17 17
 ?>
18 18
 <script type="text/javascript" src="js/jquery.js"></script>
Please login to merge, or discard this patch.
demo/wxoauthcallback.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,24 +1,24 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 //OAuth授权回调
4
-require_once __DIR__ . "/autoload.php";
4
+require_once __DIR__."/autoload.php";
5 5
 use zhangv\wechat\WechatOAuth;
6 6
 
7
-if (isset($_GET['code'])){
7
+if (isset($_GET['code'])) {
8 8
 	$cfg = require './config.php';
9 9
 
10 10
 	$code = trim($_GET['code']);
11 11
 	$state = trim($_GET['state']);
12
-	$oauth = new WechatOAuth($cfg['app_id'],$cfg['app_secret']);
12
+	$oauth = new WechatOAuth($cfg['app_id'], $cfg['app_secret']);
13 13
 	$at = $oauth->authorize($code);
14 14
 
15
-	if(!$at || empty($at->openid)){
15
+	if (!$at || empty($at->openid)) {
16 16
 		die('授权失败');
17
-	}else{
17
+	}else {
18 18
 		$accesstoken = $at->access_token;
19 19
 		$openid = $at->openid;
20 20
 		header('Location: '."http://{$_SERVER['HTTP_HOST']}/wechat-pay/demo/pay.php?openid=$openid");
21 21
 	}
22
-}else{
22
+}else {
23 23
 	die('授权失败,请重试。');
24 24
 }
25 25
\ No newline at end of file
Please login to merge, or discard this patch.
demo/autoload.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-if(file_exists(__DIR__ . '/../vendor/autoload.php')){
3
+if (file_exists(__DIR__.'/../vendor/autoload.php')) {
4 4
 	/** @var \Composer\Autoload\ClassLoader $loader */
5
-	$loader = require __DIR__ . '/../vendor/autoload.php';
6
-}else{//if the composer is not initialized, note: this is not work in phpunit, switch to composer when unit testing
5
+	$loader = require __DIR__.'/../vendor/autoload.php';
6
+}else {//if the composer is not initialized, note: this is not work in phpunit, switch to composer when unit testing
7 7
 	function __autoload($class) {
8 8
 		$class = str_replace('zhangv\\wechat\\', 'src/', $class);
9
-		$file = __DIR__ . '/../' . $class . '.php';
9
+		$file = __DIR__.'/../'.$class.'.php';
10 10
 		require_once $file;
11 11
 	}
12 12
 	spl_autoload_register('__autoload');
Please login to merge, or discard this patch.
demo/wxoauth.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 //OAuth授权
4
-require_once __DIR__ . "/autoload.php";
4
+require_once __DIR__."/autoload.php";
5 5
 
6 6
 use zhangv\wechat\WechatOAuth;
7 7
 
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 $redirect = "http://{$_SERVER['HTTP_HOST']}/wechat-pay/demo/wxoauthcallback.php";
11 11
 $scope = 'snsapi_userinfo';
12 12
 $state = "";
13
-$oauth =new WechatOAuth($appid,$cfg['app_secret']);
14
-$url = $oauth->authorizeURI($redirect,$scope);
13
+$oauth = new WechatOAuth($appid, $cfg['app_secret']);
14
+$url = $oauth->authorizeURI($redirect, $scope);
15 15
 
16 16
 header('Location: '.$redirect);
17 17
\ 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,13 +1,13 @@
 block discarded – undo
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->onRefundedNotify($xml,function($notifydata) use ($payment){
10
+$payment->onRefundedNotify($xml, function($notifydata) use ($payment){
11 11
 	//do stuff
12 12
 	print_r($notifydata);
13 13
 	$payment->responseNotify();
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,12 +1,12 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 //公众号支付
4
-require_once __DIR__ . "/autoload.php";
4
+require_once __DIR__."/autoload.php";
5 5
 
6 6
 use zhangv\wechat\WechatPay;
7 7
 $cfg = include './config.php';
8 8
 
9
-if(empty( $_REQUEST['openid'])) {
9
+if (empty($_REQUEST['openid'])) {
10 10
 	$redirect = "http://{$_SERVER['HTTP_HOST']}/wechat-pay/demo/wxoauth.php";
11 11
 	header('Location: '.$redirect);
12 12
 	exit;
Please login to merge, or discard this patch.