Commit 0d6a0b5f by yeran

feat: update the function of wxPubCharge(sub_mch_id)

1 parent d6c87ea4
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
/** /**
* 公众号支付 * 公众号支付
* Created by PhpStorm. * Created by PhpStorm.
* *
* Date: 2017/4/30 * Date: 2017/4/30
* Time: 下午3:33 * Time: 下午3:33
*/ */
...@@ -44,4 +44,4 @@ try { ...@@ -44,4 +44,4 @@ try {
exit; exit;
} }
echo json_encode($ret, JSON_UNESCAPED_UNICODE); echo json_encode($ret, JSON_UNESCAPED_UNICODE);
\ No newline at end of file
...@@ -31,7 +31,7 @@ class WxPubCharge extends WxBaseStrategy ...@@ -31,7 +31,7 @@ class WxPubCharge extends WxBaseStrategy
* 处理公众号支付的返回值。直接返回与微信文档对应的字段 * 处理公众号支付的返回值。直接返回与微信文档对应的字段
* @param array $ret * @param array $ret
* *
* @return string $data 包含以下键 * @return array $data 包含以下键
* *
* ```php * ```php
* $data = [ * $data = [
...@@ -43,7 +43,7 @@ class WxPubCharge extends WxBaseStrategy ...@@ -43,7 +43,7 @@ class WxPubCharge extends WxBaseStrategy
* 'paySign' => '', // 签名 * 'paySign' => '', // 签名
* ]; * ];
* ``` * ```
* * @throws \Payment\Common\PayException
*/ */
protected function retData(array $ret) protected function retData(array $ret)
{ {
......
<?php <?php
/** /**
* Created by PhpStorm. * Created by PhpStorm.
* *
* Date: 16/7/31 * Date: 16/7/31
* Time: 上午9:20 * Time: 上午9:20
*/ */
...@@ -17,7 +17,7 @@ use Payment\Utils\ArrayUtil; ...@@ -17,7 +17,7 @@ use Payment\Utils\ArrayUtil;
* *
* @property string $openid trade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识 * @property string $openid trade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识
* @property string $sub_appid 微信分配的子商户公众账号ID * @property string $sub_appid 微信分配的子商户公众账号ID
* @property string $sub_mch_id 微信支付分配的子商户号 * @property string $sub_mch_id 微信支付分配的子商户号
* @property string $sub_openid 用户在子商户appid下的唯一标识 * @property string $sub_openid 用户在子商户appid下的唯一标识
* *
* @package Payment\Common\Weixin\Data\Charge * @package Payment\Common\Weixin\Data\Charge
...@@ -25,20 +25,26 @@ use Payment\Utils\ArrayUtil; ...@@ -25,20 +25,26 @@ use Payment\Utils\ArrayUtil;
*/ */
class PubChargeData extends ChargeBaseData class PubChargeData extends ChargeBaseData
{ {
/**
* @return mixed|void
* @throws PayException
*/
protected function checkDataParam() protected function checkDataParam()
{ {
parent::checkDataParam(); // TODO: Change the autogenerated stub parent::checkDataParam(); // TODO: Change the autogenerated stub
// 公众号支付,必须设置openid // 公众号支付,必须设置openid
$openid = $this->openid; $openid = $this->openid;
if (empty($openid)) {
throw new PayException('用户在商户appid下的唯一标识,公众号支付,必须设置该参数.');
}
$subMchId = $this->sub_mch_id;// 如果是服务商模式,则 sub_openid 必须提供 $subMchId = $this->sub_mch_id;// 如果是服务商模式,则 sub_openid 必须提供
$subOpenid = $this->sub_openid; $subOpenid = $this->sub_openid;
if ($subMchId && empty($subOpenid)) { if (!empty($subOpenid) && empty($subMchId)) {
throw new PayException('公众号的服务商模式,必须提供 sub_openid 参数.'); throw new PayException('公众号的服务商模式,如果传入sub_openid 则 必须提供 sub_mch_id 参数.');
}
if (empty($openid)) {
if (empty($subMchId))
throw new PayException('用户在商户appid下的唯一标识,公众号支付,必须设置该参数.');
elseif (empty($subOpenid))
throw new PayException('服务商模式下open_id 或者 sub_openid 必须传入一个');
} }
} }
...@@ -47,25 +53,30 @@ class PubChargeData extends ChargeBaseData ...@@ -47,25 +53,30 @@ class PubChargeData extends ChargeBaseData
$signData = [ $signData = [
// 基本数据 // 基本数据
'appid' => trim($this->appId), 'appid' => trim($this->appId),
'mch_id' => trim($this->mchId), 'mch_id' => trim($this->mchId),
'nonce_str' => $this->nonceStr, 'nonce_str' => $this->nonceStr,
'sign_type' => $this->signType, 'sign_type' => $this->signType,
'fee_type' => $this->feeType, 'fee_type' => $this->feeType,
'notify_url' => $this->notifyUrl, 'notify_url' => $this->notifyUrl,
'trade_type' => $this->tradeType, //设置APP支付 'trade_type' => $this->tradeType, //设置APP支付
'limit_pay' => $this->limitPay, // 指定不使用信用卡 'limit_pay' => $this->limitPay, // 指定不使用信用卡
// 业务数据 // 业务数据
'device_info' => $this->terminal_id, 'device_info' => $this->terminal_id,
'body' => trim($this->subject), 'body' => trim($this->subject),
//'detail' => json_encode($this->body, JSON_UNESCAPED_UNICODE); //'detail' => json_encode($this->body, JSON_UNESCAPED_UNICODE);
'attach' => trim($this->return_param), 'attach' => trim($this->return_param),
'out_trade_no' => trim($this->order_no), 'out_trade_no' => trim($this->order_no),
'total_fee' => $this->amount, 'total_fee' => $this->amount,
'spbill_create_ip' => trim($this->client_ip), 'spbill_create_ip' => trim($this->client_ip),
'time_start' => $this->timeStart, 'time_start' => $this->timeStart,
'time_expire' => $this->timeout_express, 'time_expire' => $this->timeout_express,
'openid' => $this->openid, 'openid' => $this->openid,
// 服务商模式
'sub_appid' => $this->sub_appid,
'sub_mch_id' => $this->sub_mch_id,
'sub_openid' => $this->sub_openid,
]; ];
// 移除数组中的空值 // 移除数组中的空值
......
...@@ -119,8 +119,9 @@ abstract class WxBaseStrategy implements BaseStrategy ...@@ -119,8 +119,9 @@ abstract class WxBaseStrategy implements BaseStrategy
/** /**
* @param array $data * @param array $data
* *
* @throws PayException
* @return array|string * @return array|string
* @throws \Exception
* @throws PayException
*/ */
public function handle(array $data) public function handle(array $data)
{ {
...@@ -162,6 +163,7 @@ abstract class WxBaseStrategy implements BaseStrategy ...@@ -162,6 +163,7 @@ abstract class WxBaseStrategy implements BaseStrategy
* @param array $retData * @param array $retData
* @return boolean * @return boolean
* *
* @throws \Exception
*/ */
protected function verifySign(array $retData) protected function verifySign(array $retData)
{ {
......
...@@ -65,6 +65,7 @@ class WxNotify extends NotifyStrategy ...@@ -65,6 +65,7 @@ class WxNotify extends NotifyStrategy
* *
* *
* @return boolean * @return boolean
* @throws \Exception
*/ */
public function checkNotifyData(array $data) public function checkNotifyData(array $data)
{ {
...@@ -82,7 +83,7 @@ class WxNotify extends NotifyStrategy ...@@ -82,7 +83,7 @@ class WxNotify extends NotifyStrategy
* 检查微信返回的数据是否被篡改过 * 检查微信返回的数据是否被篡改过
* @param array $retData * @param array $retData
* @return boolean * @return boolean
* * @throws \Exception
*/ */
protected function verifySign(array $retData) protected function verifySign(array $retData)
{ {
...@@ -134,18 +135,30 @@ class WxNotify extends NotifyStrategy ...@@ -134,18 +135,30 @@ class WxNotify extends NotifyStrategy
'device_info' => $data['device_info'], 'device_info' => $data['device_info'],
'fee_type' => $data['fee_type'], 'fee_type' => $data['fee_type'],
'is_subscribe' => $data['is_subscribe'], 'is_subscribe' => $data['is_subscribe'],
'buyer_id' => $data['openid'], 'buyer_id' => $data['openid'],
'order_no' => $data['out_trade_no'], 'order_no' => $data['out_trade_no'],
'pay_time' => date('Y-m-d H:i:s', strtotime($data['time_end'])),// 支付完成时间 'pay_time' => date('Y-m-d H:i:s', strtotime($data['time_end'])),// 支付完成时间
'amount' => $totalFee, 'amount' => $totalFee,
'trade_type' => $data['trade_type'], 'trade_type' => $data['trade_type'],
'transaction_id' => $data['transaction_id'], 'transaction_id' => $data['transaction_id'],
'trade_state' => strtolower($data['return_code']), 'trade_state' => strtolower($data['return_code']),
'channel' => Config::WX_CHARGE, 'channel' => Config::WX_CHARGE,
]; ];
if (!empty($data['sub_appid'])) {
$retData['sub_appid'] = $data['sub_appid'];
}
if (!empty($data['sub_mch_id'])) {
$retData['sub_mch_id'] = $data['sub_mch_id'];
}
if (!empty($data['sub_openid'])) {
$retData['sub_openid'] = $data['sub_openid'];
}
if (!empty($data['sub_is_subscribe'])) {
$retData['sub_is_subscribe'] = $data['sub_is_subscribe'];
}
// 检查是否存在用户自定义参数 // 检查是否存在用户自定义参数
if (isset($data['attach']) && ! empty($data['attach'])) { if (isset($data['attach']) && !empty($data['attach'])) {
$retData['return_param'] = $data['attach']; $retData['return_param'] = $data['attach'];
} }
...@@ -163,14 +176,14 @@ class WxNotify extends NotifyStrategy ...@@ -163,14 +176,14 @@ class WxNotify extends NotifyStrategy
{ {
// 默认为成功 // 默认为成功
$result = [ $result = [
'return_code' => 'SUCCESS', 'return_code' => 'SUCCESS',
'return_msg' => 'OK', 'return_msg' => 'OK',
]; ];
if (! $flag) { if (!$flag) {
// 失败 // 失败
$result = [ $result = [
'return_code' => 'FAIL', 'return_code' => 'FAIL',
'return_msg' => $msg, 'return_msg' => $msg,
]; ];
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!