1
1
<?php
2
- class WechatCash
2
+ namespace App \Libs ;
3
+
4
+ class weChatCash
3
5
{
4
6
// key
5
- protected $ key = 'Hangzhouyouwomeishiwangluoweixin ' ;
6
-
7
- // 提现接口
7
+ protected $ key = '' ;
8
8
protected $ url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers ' ;
9
-
10
- // 证书地址
11
- protected $ sslCert = "./cert/apiclient_cert.pem " ;
12
- protected $ sslKey = "./cert/apiclient_key.pem " ;
9
+ protected $ mchAppid = '' ;
10
+ protected $ mchid = '' ;
11
+ // ssl
12
+ protected $ sslCurt ;
13
+ protected $ sslKey ;
13
14
14
15
public function __construct ()
15
16
{
16
- //
17
+ $ this ->sslCurt = storage_path ("cret/apiclient_cert.pem " );
18
+ $ this ->sslKey = storage_path ("cret/apiclient_key.pem " );
17
19
}
18
20
19
- /**
20
- * 提现
21
- * @Author LiuJian
22
- * @DateTime 2017-03-29
23
- * @return [type] [description]
24
- */
25
- public function cash ()
21
+ public function start ($ data )
26
22
{
23
+ if (empty ($ data )) {
24
+ return ['status ' => 'error ' , 'message ' => '缺少参数 ' ];
25
+ }
26
+
27
27
$ data = [
28
- 'mch_appid ' => ' wx6276649e045d0022 ' ,
29
- 'mchid ' => ' 1452850622 ' ,
30
- 'nonce_str ' => ' ssssssssss ' ,
31
- 'openid ' => ' o2n7KwMc7DzTCKGtiszjfsH2_ssI ' ,
32
- 'amount ' => ' 11 ' ,
33
- 'spbill_create_ip ' => ' 10.0.0.76 ' ,
34
- 'partner_trade_no ' => '11111 ' ,
35
- 'desc ' => '用户提现 ' ,
28
+ 'openid ' => $ data [ ' openid ' ] ,
29
+ 'amount ' => $ data [ ' amount ' ] ,
30
+ 'partner_trade_no ' => $ data [ ' partner_trade_no ' ] ,
31
+ 'desc ' => $ data [ ' desc ' ] ,
32
+ 'mch_appid ' => $ this -> mchAppid ,
33
+ 'mchid ' => $ this -> mchid ,
34
+ 'nonce_str ' => 'woshisuijide ' . mt_rand ( 1000 , 99999 ) ,
35
+ 'spbill_create_ip ' => '120.27.50.204 ' ,
36
36
'check_name ' => 'NO_CHECK ' ,
37
37
're_user_name ' => '测试可以不写的 '
38
38
];
@@ -53,7 +53,9 @@ public function cash ()
53
53
<sign> ' .$ sign .'</sign>
54
54
</xml> ' ;
55
55
56
- return var_dump ($ this ->getResult ($ this ->url , $ data ));
56
+ $ info = $ this ->getCurl ($ this ->url , $ data );
57
+
58
+ return $ this ->xmlToArray ($ info );
57
59
}
58
60
59
61
/**
@@ -64,7 +66,7 @@ public function cash ()
64
66
* @param [type] $data [description]
65
67
* @return [type] [description]
66
68
*/
67
- public function getResult ($ url = null , $ data )
69
+ public function getCurl ($ url = null , $ data )
68
70
{
69
71
$ ch = curl_init ();
70
72
curl_setopt ($ ch , CURLOPT_URL , $ url );
@@ -73,7 +75,7 @@ public function getResult ($url = null, $data)
73
75
curl_setopt ($ ch , CURLOPT_SSL_VERIFYHOST , FALSE );
74
76
75
77
// 证书
76
- curl_setopt ($ ch , CURLOPT_SSLCERT , $ this ->sslCert );
78
+ curl_setopt ($ ch , CURLOPT_SSLCERT , $ this ->sslCurt );
77
79
curl_setopt ($ ch , CURLOPT_SSLKEY , $ this ->sslKey );
78
80
curl_setopt ($ ch , CURLOPT_FOLLOWLOCATION , 1 );
79
81
curl_setopt ($ ch , CURLOPT_AUTOREFERER , 1 );
@@ -94,6 +96,8 @@ public function getResult ($url = null, $data)
94
96
function getSign ($ array )
95
97
{
96
98
ksort ($ array );
99
+ $ str = '' ;
100
+
97
101
foreach ($ array as $ k => $ v ) {
98
102
$ str .= $ k . "= " . $ v . "& " ;
99
103
}
@@ -103,10 +107,27 @@ function getSign($array)
103
107
104
108
return $ result ;
105
109
}
110
+
111
+
112
+ /**
113
+ * 将xml数据转换成数组
114
+ *
115
+ * @Author LiuJian
116
+ * @DateTime 2017-06-06
117
+ * @param string $xml xml 数据
118
+ * @return array 转换的数组
119
+ */
120
+ protected function xmlToArray ($ xml )
121
+ {
122
+ // 将XML转为array
123
+ $ array = simplexml_load_string ($ xml , 'SimpleXMLElement ' , LIBXML_NOCDATA );
124
+ $ array = json_decode (json_encode ($ array ), true );
125
+
126
+ return $ array ;
127
+ }
106
128
}
107
129
108
- $ cash = new WechatCash ();
109
- $ cash ->cash ();
130
+
110
131
111
132
112
133
0 commit comments