Completed
Push — master ( 76d6fa...9bc9b6 )
by Wei
08:43
created

App   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 40
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPackage() 0 10 1
A getPrepayId() 0 10 3
1
<?php
2
namespace zhangv\wechat\pay\service;
3
use \zhangv\wechat\pay\WechatPay;
4
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
	 */
39 1
	public function getPrepayId($body,$out_trade_no,$total_fee,$spbill_create_ip,$ext = null) {
40 1
		$data = ($ext && is_array($ext))?$ext:array();
41 1
		$data["body"]         = $body;
42 1
		$data["out_trade_no"] = $out_trade_no;
43 1
		$data["total_fee"]    = $total_fee;
44 1
		$data["spbill_create_ip"] = $spbill_create_ip;
45 1
		$data["notify_url"]   = $this->config["notify_url"];
46 1
		$data["trade_type"]   = WechatPay::TRADETYPE_APP;
47 1
		$result = $this->unifiedOrder($data);
48 1
		return $result["prepay_id"];
49
	}
50
51
	/**
52
	 * 获取支付参数
53
	 * @param $prepay_id string 预支付ID
54
	 * @param $trade_type string 支付类型
55
	 * @return array
56
	 */
57 1
	public function getPackage($prepay_id) {
58 1
		$data = array();
59 1
		$data["package"]   = "Sign=WXPay";
60 1
		$data['prepayid'] = $prepay_id;
61 1
		$data['partnerid'] = $this->config["mch_id"];
62 1
		$data["timestamp"] = time();
63 1
		$data["noncestr"]  = $this->getNonceStr();
64 1
		$data["appid"] = $this->config["app_id"];
65 1
		$data["sign"]   = $this->sign($data);
66 1
		return $data;
67
	}
68
}