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 a2ae41ce
authored
Nov 01, 2018
by
yeran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reduce some params for charge by yeran
1 parent
e4475be6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
34 additions
and
180 deletions
TLNotify.php
examples/mipay/MiConfig.php
examples/mipay/liteCharge.php
src/Common/MiConfig.php
src/Common/MiPay/Data/Charge/MiChargeData.php
src/Common/MiPay/MiBaseStrategy.php
TLNotify.php
deleted
100644 → 0
View file @
e4475be
<?php
namespace
Payment\Notify
;
use
Payment\Common\PayException
;
use
Payment\Common\TLConfig
;
use
Payment\Config
;
use
Payment\Utils\ArrayUtil
;
/**
* Class TLNotify
* 微信回调处理
* @package Payment\Notify
* anthor yeran
*/
class
TLNotify
extends
NotifyStrategy
{
/**
* TLNotify constructor.
* @param array $config
* @throws PayException
*/
public
function
__construct
(
array
$config
)
{
parent
::
__construct
(
$config
);
try
{
$this
->
config
=
new
TLConfig
(
$config
);
}
catch
(
PayException
$e
)
{
throw
$e
;
}
}
/**
* 获取返回的异步通知数据
* @return array|bool
* @author yeran
*/
public
function
getNotifyData
()
{
// php://input 带来的内存压力更小
// "{ \"key\": \"123456\" }";
$data
=
@
file_get_contents
(
'php://input'
);
// 等同于微信提供的:$GLOBALS['HTTP_RAW_POST_DATA']
// 将xml数据格式化为数组
$arrData
=
json_decode
(
$data
,
true
);
if
(
empty
(
$arrData
))
{
return
false
;
}
// 移除值中的空格 xml转化为数组时,CDATA 数据会被带入额外的空格。
$arrData
=
ArrayUtil
::
paraFilter
(
$arrData
);
return
$arrData
;
}
/**
* 检查异步通知的数据是否正确
* @param array $data
*
* @author yeran
* @return boolean
*/
public
function
checkNotifyData
(
array
$data
)
{
// 检查返回数据签名是否正确
return
$this
->
verifySign
(
$data
);
}
/**
* 检查微信返回的数据是否被篡改过
* @param array $retData
* @return boolean
* @author yeran
*/
protected
function
verifySign
(
array
$retData
)
{
$retSign
=
$retData
[
'sign'
];
$values
=
ArrayUtil
::
removeKeys
(
$retData
,
[
'sign'
,
'sign_type'
]);
$values
=
ArrayUtil
::
paraFilter
(
$values
);
$signStr
=
ArrayUtil
::
SignArray
(
$values
,
$this
->
config
->
md5Key
);
return
strtoupper
(
$signStr
)
===
$retSign
;
}
/**
*
* 封装回调函数需要的数据格式
*
* @param array $data
*
* @return array
* @author yeran
*/
protected
function
getRetData
(
array
$data
)
{
if
(
$this
->
config
->
returnRaw
)
{
$data
[
'channel'
]
=
Config
::
TL_CHARGE
;
return
$data
;
}
return
$data
;
}
/**
* 处理完后返回的数据格式
* @param bool $flag
* @param string $msg 通知信息,错误原因
* @author yeran
* @return string
*/
protected
function
replyNotify
(
$flag
,
$msg
=
'OK'
)
{
// 默认为成功
$return_code
=
'SUCCESS'
;
if
(
!
$flag
)
{
$return_code
=
'FAIL'
;
}
return
[
$return_code
,
$msg
];
}
}
examples/mipay/MiConfig.php
View file @
a2ae41c
...
...
@@ -9,8 +9,8 @@ return [
'app_id'
=>
'mf0cvupxsxnvoaykq6jd27hc1c9u1n0h'
,
// 开发appid
'sub_merchant_id'
=>
'201810301001'
,
// 商户id
'sign_type'
=>
'RSA2'
,
// MD5 HMAC-SHA256
'method'
=>
'trade.wxpay.unifiedorder'
,
//
'sign_type' => 'RSA2',// MD5 HMAC-SHA256
//
'method' => 'trade.wxpay.unifiedorder',
'notify_url'
=>
'http://172.16.2.46:8080/vo-apidemo/OrderServlet'
,
];
...
...
examples/mipay/liteCharge.php
View file @
a2ae41c
...
...
@@ -11,16 +11,15 @@ date_default_timezone_set('Asia/Shanghai');
$miConfig
=
require_once
'MiConfig.php'
;
$orderNo
=
1213456798
;
//time() . rand(1000, 9999);
$orderNo
=
1213456798
1211
;
//time() . rand(1000, 9999);
// 订单信息
$payData
=
[
'body'
=>
'商品名称'
,
'out_trade_sn'
=>
$orderNo
,
//自定义订单号
'sub_appid'
=>
'wx03b4aeb839cc8d85'
,
//小程序appid
'sub_openid'
=>
'oUlAM0Wp1K1rJEGJ0t__Ls5-qFKE'
,
'spbill_create_ip'
=>
''
,
//
'spbill_create_ip'=>'',
// 'timeout_express' => time() + 600,// 表示必须 600s 内付款
'trxamt'
=>
'1'
,
// 微信沙箱模式,需要金额固定为3.01
'attach'
=>
'备注信息'
,
// 如果是服务商,请提供以下参数
// 'sub_store_id' => 6,//微信分配的子商户公众账号ID
...
...
src/Common/MiConfig.php
View file @
a2ae41c
...
...
@@ -54,9 +54,6 @@ final class MiConfig extends ConfigInterface
const
REFUND_RECHARGE
=
'REFUND_SOURCE_RECHARGE_FUNDS'
;
// 可用余额退款(限非当日交易订单的退款)
const
PLATFORM_APPID
=
'00032161'
;
// 平台appId
const
orgid
=
'55079104816UGBA'
;
// 代为发起交易的机构商户号
/**
* 初始化配置文件
...
...
@@ -86,21 +83,17 @@ final class MiConfig extends ConfigInterface
if
(
key_exists
(
'app_id'
,
$config
)
&&
!
empty
(
$config
[
'app_id'
]))
{
$this
->
appId
=
$config
[
'app_id'
];
if
(
self
::
PLATFORM_APPID
==
$this
->
appId
){
$this
->
orgid
=
self
::
orgid
;
}
else
{
$this
->
orgid
=
null
;
}
}
else
{
//
throw
new
PayException
(
'必须提供支付平台分配的公众账号ID'
);
}
// 检查 method
if
(
key_exists
(
'method'
,
$config
)
&&
!
empty
(
$config
[
'method'
]))
{
$this
->
method
=
$config
[
'method'
];
}
else
{
throw
new
PayException
(
'必须提供method'
);
}
//
if (key_exists('method', $config) && !empty($config['method'])) {
//
$this->method = $config['method'];
//
} else {
//
throw new PayException('必须提供method');
//
}
// 检查 平台支付分配的商户号
if
(
key_exists
(
'sub_merchant_id'
,
$config
)
&&
!
empty
(
$config
[
'sub_merchant_id'
]))
{
...
...
src/Common/MiPay/Data/Charge/MiChargeData.php
View file @
a2ae41c
...
...
@@ -6,7 +6,7 @@ use Payment\Common\PayException;
use
Payment\Utils\ArrayUtil
;
/**
* Class
TL
ChargeData
* Class
Mi
ChargeData
* 通联支付
*
* @property string $openid trade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识
...
...
@@ -14,8 +14,8 @@ use Payment\Utils\ArrayUtil;
* @property string $sub_mch_id 微信支付分配的子商户号
* @property string $sub_openid 用户在子商户appid下的唯一标识
*
*
@package Payment\Common\Weixin\Data\Charge
*
an
thor yeran
*
*
@au
thor yeran
*/
class
MiChargeData
extends
ChargeBaseData
{
...
...
@@ -39,22 +39,26 @@ class MiChargeData extends ChargeBaseData
// 基本数据
'appid'
=>
trim
(
$this
->
appId
),
'sub_merchant_id'
=>
$this
->
sub_merchant_id
,
'sub_appid'
=>
trim
(
$this
->
sub_appid
),
'version'
=>
$this
->
version
,
'nonce_str'
=>
$this
->
nonce_str
,
'trade_type'
=>
$this
->
trade_type
,
'sub_appid'
=>
trim
(
$this
->
sub_appid
),
'method'
=>
'trade.wxpay.unifiedorder'
,
'version'
=>
$this
->
version
,
'nonce_str'
=>
$this
->
nonce_str
,
'trade_type'
=>
$this
->
trade_type
,
'notify_url'
=>
$this
->
notifyUrl
,
'limit_pay'
=>
$this
->
limitPay
,
// 指定不使用信用卡
'method'
=>
$this
->
method
,
'out_trade_sn'
=>
$this
->
out_trade_sn
,
'sign_type'
=>
$this
->
sign_type
,
'body'
=>
trim
(
$this
->
body
),
'attach'
=>
trim
(
$this
->
attach
),
'sub_openid'
=>
trim
(
$this
->
sub_openid
),
'total_amount'
=>
$this
->
total_amount
,
//单位分
'spbill_create_ip'
=>
$this
->
spbill_create_ip
'limit_pay'
=>
$this
->
limitPay
,
// 指定不使用信用卡
'out_trade_sn'
=>
$this
->
out_trade_sn
,
'sign_type'
=>
$this
->
sign_type
,
'body'
=>
trim
(
$this
->
body
),
'attach'
=>
trim
(
$this
->
attach
),
'sub_openid'
=>
trim
(
$this
->
sub_openid
),
'total_amount'
=>
$this
->
total_amount
,
//单位分
'spbill_create_ip'
=>
$this
->
spbill_create_ip
,
];
if
(
$this
->
time_expire
){
$signData
[
'time_expire'
]
=
$this
->
time_expire
;
//订单失效时间,格式为yyyyMMddHHmmss
}
// 移除数组中的空值
$this
->
retData
=
ArrayUtil
::
paraFilter
(
$signData
);
...
...
src/Common/MiPay/MiBaseStrategy.php
View file @
a2ae41c
...
...
@@ -72,10 +72,11 @@ abstract class MiBaseStrategy implements BaseStrategy{
// 格式化为数组
$retData
=
(
json_decode
(
$responseTxt
[
'body'
],
true
));
// die(json_encode($retData));
if
(
$retData
[
'return_code'
]
!=
'SUCCESS'
)
{
//通信标识
throw
new
PayException
(
'支付平台返回错误提示1:'
.
$retData
[
'errmsg'
]);
}
//
if ($retData['return_code'] != 'SUCCESS') { //通信标识
//
throw new PayException('支付平台返回错误提示1:' . $retData['errmsg']);
//
}
if
(
$retData
[
'result_code'
]
!=
'SUCCESS'
)
{
//交易标识
$msg
=
$retData
[
'errmsg'
]
?:
'交易失败-系统繁忙'
;
throw
new
PayException
(
'支付平台返回错误提示2:'
.
$msg
);
...
...
@@ -156,22 +157,5 @@ abstract class MiBaseStrategy implements BaseStrategy{
return
$ret
;
}
/**
* 检查支付平台返回的数据是否被篡改过:sign=md5(string.getbyte("utf-8")).toUpperCase()
* @param array $retData
* @return boolean
* @author helei
*/
protected
function
verifySign
(
array
$retData
)
{
$retSign
=
$retData
[
'sign'
];
$values
=
ArrayUtil
::
removeKeys
(
$retData
,
[
'sign'
,
'sign_type'
]);
$values
=
ArrayUtil
::
paraFilter
(
$values
);
$signStr
=
ArrayUtil
::
SignArray
(
$values
,
$this
->
config
->
md5Key
);
return
strtoupper
(
$signStr
)
===
$retSign
;
}
}
\ No newline at end of file
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