1
|
|
|
<?php |
2
|
|
|
namespace zhangv\wechat\pay\service; |
3
|
|
|
use \zhangv\wechat\pay\WechatPay; |
4
|
|
|
use \Exception; |
5
|
|
|
/** |
6
|
|
|
* APP支付 |
7
|
|
|
* @license MIT |
8
|
|
|
* @zhangv |
9
|
|
|
* @link https://pay.weixin.qq.com/wiki/doc/api/app/app.php?chapter=9_1 |
10
|
|
|
* |
11
|
|
|
* @method mixed queryOrderByOutTradeNo($out_trade_no) |
12
|
|
|
* @method mixed queryOrderByTransactionId($transaction_id) |
13
|
|
|
* @method mixed closeOrder($out_trade_no) |
14
|
|
|
* @method mixed refundByOutTradeNo($out_trade_no, $out_refund_no, $total_fee, $refund_fee, $ext = array()) |
15
|
|
|
* @method mixed refundByTransactionId($transaction_id, $out_refund_no, $total_fee, $refund_fee, $ext = array()) |
16
|
|
|
* @method mixed queryRefundByOutRefundNo($out_refund_no, $offset = 0) |
17
|
|
|
* @method mixed queryRefundByOutTradeNo($out_trade_no, $offset = 0) |
18
|
|
|
* @method mixed queryRefundByRefundId($refund_id, $offset = 0) |
19
|
|
|
* @method mixed queryRefundByTransactionId($transaction_id, $offset = 0) |
20
|
|
|
* @method mixed downloadBill($bill_date, $bill_type = 'ALL') |
21
|
|
|
* @method mixed downloadFundFlow($bill_date, $account_type = WechatPay::ACCOUNTTYPE_BASIC, $tar_type = 'GZIP') |
22
|
|
|
* @method mixed onPaidNotify($notify_data, callable $callback = null) |
23
|
|
|
* @method mixed onRefundedNotify($notify_data, callable $callback = null) |
24
|
|
|
* @method mixed report($interface_url, $execution_time, $return_code, $result_code, $user_ip, $out_trade_no = null, $time = null, $device_info = null,$return_msg = null,$err_code = null,$err_code_des = null) |
25
|
|
|
* @method mixed batchQueryComment($begin_time, $end_time, $offset = 0, $limit = 200) |
26
|
|
|
*/ |
27
|
|
|
class App extends WechatPay { |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* 获取预支付单信息(prepay_id) |
31
|
|
|
* (注意这里的appid是从开放平台申请的) |
32
|
|
|
* @param $body string 内容 |
33
|
|
|
* @param $out_trade_no string 商户订单号 |
34
|
|
|
* @param $total_fee int 总金额 |
35
|
|
|
* @param $spbill_create_ip string 终端ID |
36
|
|
|
* @param $ext array |
37
|
|
|
* @return string |
38
|
|
|
* @throws Exception |
39
|
|
|
*/ |
40
|
1 |
|
public function getPrepayId($body,$out_trade_no,$total_fee,$spbill_create_ip,$ext = null) { |
41
|
1 |
|
$data = ($ext && is_array($ext))?$ext:array(); |
42
|
1 |
|
$data["body"] = $body; |
43
|
1 |
|
$data["out_trade_no"] = $out_trade_no; |
44
|
1 |
|
$data["total_fee"] = $total_fee; |
45
|
1 |
|
$data["spbill_create_ip"] = $spbill_create_ip; |
46
|
1 |
|
$data["notify_url"] = $this->config["notify_url"]; |
47
|
1 |
|
$data["trade_type"] = WechatPay::TRADETYPE_APP; |
48
|
1 |
|
$result = $this->unifiedOrder($data); |
49
|
1 |
|
return $result["prepay_id"]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* 获取支付参数 |
54
|
|
|
* @param $prepay_id string 预支付ID |
55
|
|
|
* @return array |
56
|
|
|
* @throws Exception |
57
|
|
|
*/ |
58
|
1 |
|
public function getPackage($prepay_id) { |
59
|
1 |
|
$data = array(); |
60
|
1 |
|
$data["package"] = "Sign=WXPay"; |
61
|
1 |
|
$data['prepayid'] = $prepay_id; |
62
|
1 |
|
$data['partnerid'] = $this->config["mch_id"]; |
63
|
1 |
|
$data["timestamp"] = time(); |
64
|
1 |
|
$data["noncestr"] = $this->getNonceStr(); |
65
|
1 |
|
$data["appid"] = $this->config["app_id"]; |
66
|
1 |
|
$data["sign"] = $this->sign($data); |
67
|
1 |
|
return $data; |
68
|
|
|
} |
69
|
|
|
} |