Commit 0d6a0b5f by yeran

feat: update the function of wxPubCharge(sub_mch_id)

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