Skip to content

Commit 80e2c15

Browse files
committed
x
1 parent 45187e0 commit 80e2c15

File tree

1 file changed

+50
-29
lines changed

1 file changed

+50
-29
lines changed

企业付款api/wechatCash.php

+50-29
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
<?php
2-
class WechatCash
2+
namespace App\Libs;
3+
4+
class weChatCash
35
{
46
// key
5-
protected $key = 'Hangzhouyouwomeishiwangluoweixin';
6-
7-
// 提现接口
7+
protected $key = '';
88
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;
1314

1415
public function __construct ()
1516
{
16-
//
17+
$this->sslCurt = storage_path("cret/apiclient_cert.pem");
18+
$this->sslKey = storage_path("cret/apiclient_key.pem");
1719
}
1820

19-
/**
20-
* 提现
21-
* @Author LiuJian
22-
* @DateTime 2017-03-29
23-
* @return [type] [description]
24-
*/
25-
public function cash ()
21+
public function start ($data)
2622
{
23+
if (empty($data)) {
24+
return ['status' => 'error', 'message' => '缺少参数'];
25+
}
26+
2727
$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',
3636
'check_name' => 'NO_CHECK',
3737
're_user_name' => '测试可以不写的'
3838
];
@@ -53,7 +53,9 @@ public function cash ()
5353
<sign>'.$sign.'</sign>
5454
</xml>';
5555

56-
return var_dump($this->getResult($this->url, $data));
56+
$info = $this->getCurl($this->url, $data);
57+
58+
return $this->xmlToArray($info);
5759
}
5860

5961
/**
@@ -64,7 +66,7 @@ public function cash ()
6466
* @param [type] $data [description]
6567
* @return [type] [description]
6668
*/
67-
public function getResult ($url = null, $data)
69+
public function getCurl ($url = null, $data)
6870
{
6971
$ch = curl_init();
7072
curl_setopt($ch, CURLOPT_URL, $url);
@@ -73,7 +75,7 @@ public function getResult ($url = null, $data)
7375
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
7476

7577
// 证书
76-
curl_setopt($ch, CURLOPT_SSLCERT, $this->sslCert);
78+
curl_setopt($ch, CURLOPT_SSLCERT, $this->sslCurt);
7779
curl_setopt($ch, CURLOPT_SSLKEY, $this->sslKey);
7880
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
7981
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
@@ -94,6 +96,8 @@ public function getResult ($url = null, $data)
9496
function getSign($array)
9597
{
9698
ksort($array);
99+
$str = '';
100+
97101
foreach ($array as $k => $v) {
98102
$str .= $k . "=" . $v . "&";
99103
}
@@ -103,10 +107,27 @@ function getSign($array)
103107

104108
return $result;
105109
}
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+
}
106128
}
107129

108-
$cash = new WechatCash();
109-
$cash->cash();
130+
110131

111132

112133

0 commit comments

Comments
 (0)