Completed
Push — master ( 102abf...4b0145 )
by Wei
02:46
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.
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.
demo/pay-app.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@
 block discarded – undo
2 2
 
3 3
 //APP支付 - 获取预支付交易回话标识
4 4
 //注意:APP支付使用的是开放平台的APPID
5
-require_once __DIR__ . "/autoload.php";
5
+require_once __DIR__."/autoload.php";
6 6
 
7 7
 use zhangv\wechat\WechatPay;
8 8
 
Please login to merge, or discard this patch.