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 667d8aad
authored
Oct 11, 2019
by
wangyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 调整签名逻辑
1 parent
9fc1c285
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
42 additions
and
9 deletions
src/Client/Transfer.php
src/Common/BaseData.php
src/Common/Weixin/Data/PayBankData.php
src/Common/Weixin/Data/WxBaseData.php
src/Trans/WxPayBank.php
src/Utils/ArrayUtil.php
src/Client/Transfer.php
View file @
667d8aa
...
@@ -58,7 +58,7 @@ class Transfer
...
@@ -58,7 +58,7 @@ class Transfer
public
static
function
run
(
$channel
,
$config
,
$metadata
)
public
static
function
run
(
$channel
,
$config
,
$metadata
)
{
{
if
(
!
in_array
(
$channel
,
self
::
$supportChannel
))
{
if
(
!
in_array
(
$channel
,
self
::
$supportChannel
))
{
throw
new
PayException
(
'sdk当前不支持该
退款
渠道,当前仅支持:'
.
implode
(
','
,
self
::
$supportChannel
));
throw
new
PayException
(
'sdk当前不支持该
转账
渠道,当前仅支持:'
.
implode
(
','
,
self
::
$supportChannel
));
}
}
try
{
try
{
...
...
src/Common/BaseData.php
View file @
667d8aa
...
@@ -104,9 +104,10 @@ abstract class BaseData
...
@@ -104,9 +104,10 @@ abstract class BaseData
/**
/**
* 设置签名
* 设置签名
*
*
* @param bool $urlDecode
* @throws \Exception
* @throws \Exception
*/
*/
public
function
setSign
()
public
function
setSign
(
bool
$urlDecode
=
true
)
{
{
$this
->
buildData
();
$this
->
buildData
();
if
(
$this
->
channel
===
Config
::
CMB_PAY
)
{
if
(
$this
->
channel
===
Config
::
CMB_PAY
)
{
...
@@ -144,7 +145,7 @@ abstract class BaseData
...
@@ -144,7 +145,7 @@ abstract class BaseData
default
:
default
:
$values
=
ArrayUtil
::
removeKeys
(
$data
,
[
'sign'
]);
$values
=
ArrayUtil
::
removeKeys
(
$data
,
[
'sign'
]);
$values
=
ArrayUtil
::
arraySort
(
$values
);
$values
=
ArrayUtil
::
arraySort
(
$values
);
$signStr
=
ArrayUtil
::
createLinkstring
(
$values
);
$signStr
=
ArrayUtil
::
createLinkstring
(
$values
,
$urlDecode
);
$this
->
retData
[
'sign'
]
=
$this
->
makeSign
(
$signStr
);
$this
->
retData
[
'sign'
]
=
$this
->
makeSign
(
$signStr
);
}
}
}
}
...
...
src/Common/Weixin/Data/PayBankData.php
View file @
667d8aa
...
@@ -31,8 +31,7 @@ class PayBankData extends WxBaseData
...
@@ -31,8 +31,7 @@ class PayBankData extends WxBaseData
protected
function
buildData
()
protected
function
buildData
()
{
{
$this
->
retData
=
[
$this
->
retData
=
[
// 'mch_appid' => $this->appId,
'mch_id'
=>
$this
->
mchId
,
'mchid'
=>
$this
->
mchId
,
'partner_trade_no'
=>
$this
->
trans_no
,
'partner_trade_no'
=>
$this
->
trans_no
,
'nonce_str'
=>
$this
->
nonceStr
,
'nonce_str'
=>
$this
->
nonceStr
,
'enc_bank_no'
=>
$this
->
payer_bank_no
,
'enc_bank_no'
=>
$this
->
payer_bank_no
,
...
...
src/Common/Weixin/Data/WxBaseData.php
View file @
667d8aa
...
@@ -26,7 +26,7 @@ use Payment\Common\PayException;
...
@@ -26,7 +26,7 @@ use Payment\Common\PayException;
* @property string $tradeType 支付类型
* @property string $tradeType 支付类型
* @property string $terminal_id 终端设备号(门店号或收银设备ID),默认请传"WEB"
* @property string $terminal_id 终端设备号(门店号或收银设备ID),默认请传"WEB"
*
*
* @package Payment\Common\Weixin\Data
a
* @package Payment\Common\Weixin\Data
*/
*/
abstract
class
WxBaseData
extends
BaseData
abstract
class
WxBaseData
extends
BaseData
{
{
...
...
src/Trans/WxPayBank.php
View file @
667d8aa
...
@@ -2,11 +2,13 @@
...
@@ -2,11 +2,13 @@
namespace
Payment\Trans
;
namespace
Payment\Trans
;
use
Payment\Common\PayException
;
use
Payment\Common\Weixin\Data\PayBankData
;
use
Payment\Common\Weixin\Data\PayBankData
;
use
Payment\Common\Weixin\WxBaseStrategy
;
use
Payment\Common\Weixin\WxBaseStrategy
;
use
Payment\Common\WxConfig
;
use
Payment\Common\WxConfig
;
use
Payment\Config
;
use
Payment\Config
;
use
Payment\Utils\Curl
;
use
Payment\Utils\Curl
;
use
Payment\Utils\DataParser
;
/**
/**
* 微信企业付款到银行卡接口
* 微信企业付款到银行卡接口
...
@@ -118,4 +120,34 @@ class WxPayBank extends WxBaseStrategy
...
@@ -118,4 +120,34 @@ class WxPayBank extends WxBaseStrategy
{
{
return
true
;
return
true
;
}
}
/**
* @param array $data
*
* @return array|string
* @throws PayException
*/
public
function
handle
(
array
$data
)
{
$buildClass
=
$this
->
getBuildDataClass
();
try
{
$this
->
reqData
=
new
$buildClass
(
$this
->
config
,
$data
);
}
catch
(
PayException
$e
)
{
throw
$e
;
}
//企业付款到银行卡参数不能进行urldecode
$this
->
reqData
->
setSign
(
true
);
$xml
=
DataParser
::
toXml
(
$this
->
reqData
->
getData
());
$ret
=
$this
->
sendReq
(
$xml
);
// 检查返回的数据是否被篡改
$flag
=
$this
->
verifySign
(
$ret
);
if
(
!
$flag
)
throw
new
PayException
(
'微信返回数据被篡改。请检查网络是否安全!'
);
return
$this
->
retData
(
$ret
);
}
}
}
src/Utils/ArrayUtil.php
View file @
667d8aa
...
@@ -85,12 +85,13 @@ class ArrayUtil
...
@@ -85,12 +85,13 @@ class ArrayUtil
/**
/**
* 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
* 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
* @param array $para 需要拼接的数组
* @param array $para 需要拼接的数组
* @param bool $urlDecode
* @return string
* @return string
* @throws \Exception
* @throws \Exception
*/
*/
public
static
function
createLinkstring
(
$para
)
public
static
function
createLinkstring
(
$para
,
bool
$urlDecode
=
true
)
{
{
if
(
!
is_array
(
$para
))
{
if
(
!
is_array
(
$para
))
{
throw
new
\Exception
(
'必须传入数组参数'
);
throw
new
\Exception
(
'必须传入数组参数'
);
}
}
...
@@ -101,7 +102,7 @@ class ArrayUtil
...
@@ -101,7 +102,7 @@ class ArrayUtil
continue
;
continue
;
}
}
$arg
.=
$key
.
'='
.
urldecode
(
$val
)
.
'&'
;
$arg
.=
$key
.
'='
.
(
true
===
$urlDecode
?
urldecode
(
$val
)
:
$val
)
.
'&'
;
}
}
//去掉最后一个&字符
//去掉最后一个&字符
$arg
&&
$arg
=
substr
(
$arg
,
0
,
-
1
);
$arg
&&
$arg
=
substr
(
$arg
,
0
,
-
1
);
...
...
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