Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
ldy
/
payment
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 0d6a0b5f
authored
Nov 18, 2020
by
yeran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: update the function of wxPubCharge(sub_mch_id)
1 parent
d6c87ea4
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
12 deletions
examples/wx/pubCharge.php
src/Charge/Wx/WxPubCharge.php
src/Common/Weixin/Data/Charge/PubChargeData.php
src/Common/Weixin/WxBaseStrategy.php
src/Notify/WxNotify.php
examples/wx/pubCharge.php
View file @
0d6a0b5
src/Charge/Wx/WxPubCharge.php
View file @
0d6a0b5
...
@@ -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
)
{
{
...
...
src/Common/Weixin/Data/Charge/PubChargeData.php
View file @
0d6a0b5
...
@@ -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 必须传入一个'
);
}
}
}
}
...
@@ -66,6 +72,11 @@ class PubChargeData extends ChargeBaseData
...
@@ -66,6 +72,11 @@ class PubChargeData extends ChargeBaseData
'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
,
];
];
// 移除数组中的空值
// 移除数组中的空值
...
...
src/Common/Weixin/WxBaseStrategy.php
View file @
0d6a0b5
...
@@ -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
)
{
{
...
...
src/Notify/WxNotify.php
View file @
0d6a0b5
...
@@ -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
)
{
{
...
@@ -143,9 +144,21 @@ class WxNotify extends NotifyStrategy
...
@@ -143,9 +144,21 @@ class WxNotify extends NotifyStrategy
'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'
];
}
}
...
@@ -166,7 +179,7 @@ class WxNotify extends NotifyStrategy
...
@@ -166,7 +179,7 @@ class WxNotify extends NotifyStrategy
'return_code'
=>
'SUCCESS'
,
'return_code'
=>
'SUCCESS'
,
'return_msg'
=>
'OK'
,
'return_msg'
=>
'OK'
,
];
];
if
(
!
$flag
)
{
if
(
!
$flag
)
{
// 失败
// 失败
$result
=
[
$result
=
[
'return_code'
=>
'FAIL'
,
'return_code'
=>
'FAIL'
,
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment