Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
quxiu
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
冷斌
quxiu
Commits
9b3c96ab
Commit
9b3c96ab
authored
Apr 23, 2020
by
冷斌
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bug
parent
613d1de2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
94 additions
and
82 deletions
+94
-82
application/Appapi/Controller/PayController.class.php
+94
-82
No files found.
application/Appapi/Controller/PayController.class.php
View file @
9b3c96ab
...
...
@@ -8,12 +8,12 @@
// +----------------------------------------------------------------------
namespace
Appapi\Controller
;
use
Common\Controller\HomebaseController
;
use
Common\Controller\HomebaseController
;
/**
* 支付回调
*/
class
PayController
extends
HomebaseController
{
private
$wxDate
=
null
;
//支付宝 回调
public
function
notify_ali
()
{
...
...
@@ -34,36 +34,36 @@ class PayController extends HomebaseController {
$trade_no
=
$_POST
[
'trade_no'
];
//交易状态
$trade_status
=
$_POST
[
'trade_status'
];
//交易金额
$total_fee
=
$_POST
[
'total_fee'
];
if
(
$_POST
[
'trade_status'
]
==
'TRADE_FINISHED'
)
{
//判断该笔订单是否在商户网站中已经做过处理
//如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
//如果有做过处理,不执行商户的业务程序
//注意:
//退款日期超过可退款期限后(如三个月可退款),支付宝系统发送该交易状态通知
//请务必判断请求时的total_fee、seller_id与通知时获取的total_fee、seller_id为一致的
//调试用,写文本函数记录程序运行情况是否正常
//logResult("这里写入想要调试的代码变量值,或其他运行的结果记录");
}
else
if
(
$_POST
[
'trade_status'
]
==
'TRADE_SUCCESS'
)
{
//判断该笔订单是否在商户网站中已经做过处理
//如果没有做过处理,根据订单号(out_trade_no)在商户网站的订单系统中查到该笔订单的详细,并执行商户的业务程序
//如果有做过处理,不执行商户的业务程序
//注意:
//付款完成后,支付宝系统发送该交易状态通知
//请务必判断请求时的total_fee、seller_id与通知时获取的total_fee、seller_id为一致的
//调试用,写文本函数记录程序运行情况是否正常
//logResult("这里写入想要调试的代码变量值,或其他运行的结果记录");
$orderinfo
=
M
(
"users_charge"
)
->
where
(
"orderno='
{
$out_trade_no
}
' and money='
{
$total_fee
}
' and status='0' and type='1'"
)
->
find
();
$this
->
logali
(
"orderinfo:"
.
json_encode
(
$orderinfo
));
$orderinfo
=
M
(
"users_charge"
)
->
where
(
"orderno='
{
$out_trade_no
}
' and money='
{
$total_fee
}
' and status='0' and type='1'"
)
->
find
();
$this
->
logali
(
"orderinfo:"
.
json_encode
(
$orderinfo
));
if
(
$orderinfo
){
/* 更新会员虚拟币 */
$coin
=
$orderinfo
[
'coin'
]
+
$orderinfo
[
'coin_give'
];
...
...
@@ -71,37 +71,37 @@ class PayController extends HomebaseController {
/* 更新 订单状态 */
M
(
"users_charge"
)
->
where
(
"id='
{
$orderinfo
[
'id'
]
}
'"
)
->
save
(
array
(
"status"
=>
1
,
"trade_no"
=>
$trade_no
));
$this
->
logali
(
"成功"
);
$this
->
logali
(
"成功"
);
echo
"success"
;
//请不要修改或删除
exit
;
}
else
{
$this
->
logali
(
"orderno:"
.
$out_trade_no
.
' 订单信息不存在'
);
}
$this
->
logali
(
"orderno:"
.
$out_trade_no
.
' 订单信息不存在'
);
}
}
//——请根据您的业务逻辑来编写程序(以上代码仅作参考)——
echo
"fail"
;
//请不要修改或删除
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
else
{
$this
->
logali
(
"验证失败"
);
$this
->
logali
(
"验证失败"
);
//验证失败
echo
"fail"
;
//调试用,写文本函数记录程序运行情况是否正常
//logResult("这里写入想要调试的代码变量值,或其他运行的结果记录");
}
}
}
/* 支付宝支付 */
/* 微信支付 */
/* 微信支付 */
public
function
notify_wx
(){
$config
=
getConfigPri
();
//$xmlInfo = $GLOBALS['HTTP_RAW_POST_DATA'];
$xmlInfo
=
file_get_contents
(
"php://input"
);
$xmlInfo
=
file_get_contents
(
"php://input"
);
//解析xml
$arrayInfo
=
$this
->
xmlToArray
(
$xmlInfo
);
...
...
@@ -136,23 +136,23 @@ class PayController extends HomebaseController {
echo
$this
->
returnInfo
(
"FAIL"
,
"签名失败"
);
$this
->
logwx
(
$arrayInfo
[
'return_code'
]);
//log打印保存
exit
;
}
}
}
private
function
returnInfo
(
$type
,
$msg
){
if
(
$type
==
"SUCCESS"
){
return
$returnXml
=
"<xml><return_code><![CDATA[
{
$type
}
]]></return_code></xml>"
;
}
else
{
return
$returnXml
=
"<xml><return_code><![CDATA[
{
$type
}
]]></return_code><return_msg><![CDATA[
{
$msg
}
]]></return_msg></xml>"
;
}
}
}
//签名验证
private
function
checkSign
(
$sign1
,
$sign2
){
return
trim
(
$sign1
)
==
trim
(
$sign2
);
}
/* 订单查询加值业务处理
* @param orderNum 订单号
* @param orderNum 订单号
*/
private
function
orderServer
(){
$info
=
$this
->
wxDate
;
...
...
@@ -168,59 +168,59 @@ class PayController extends HomebaseController {
M
(
"users_charge"
)
->
where
(
"id='
{
$orderinfo
[
'id'
]
}
'"
)
->
save
(
array
(
"status"
=>
1
,
"trade_no"
=>
$info
[
'transaction_id'
]));
$this
->
logwx
(
"orderno:"
.
$out_trade_no
.
' 支付成功'
);
}
else
{
$this
->
logwx
(
"orderno:"
.
$out_trade_no
.
' 订单信息不存在'
);
$this
->
logwx
(
"orderno:"
.
$out_trade_no
.
' 订单信息不存在'
);
return
false
;
}
}
}
}
/**
* sign拼装获取
*/
private
function
sign
(
$param
,
$key
){
$sign
=
""
;
foreach
(
$param
as
$k
=>
$v
){
$sign
.=
$k
.
"="
.
$v
.
"&"
;
}
$sign
.=
"key="
.
$key
;
$sign
=
strtoupper
(
md5
(
$sign
));
return
$sign
;
}
/**
* xml转为数组
*/
private
function
xmlToArray
(
$xmlStr
){
$msg
=
array
();
$postStr
=
$xmlStr
;
$msg
=
(
array
)
simplexml_load_string
(
$postStr
,
'SimpleXMLElement'
,
LIBXML_NOCDATA
);
$msg
=
array
();
$postStr
=
$xmlStr
;
$msg
=
(
array
)
simplexml_load_string
(
$postStr
,
'SimpleXMLElement'
,
LIBXML_NOCDATA
);
return
$msg
;
}
/* 微信支付 */
/* 苹果支付 */
public
function
notify_ios
(){
$content
=
file_get_contents
(
"php://input"
);
$data
=
json_decode
(
$content
,
true
);
$content
=
file_get_contents
(
"php://input"
);
$data
=
json_decode
(
$content
,
true
);
$this
->
logios
(
"data:"
.
json_encode
(
$data
));
$receipt
=
$data
[
"receipt-data"
];
$receipt
=
$data
[
"receipt-data"
];
$isSandbox
=
$data
[
"sandbox"
];
$out_trade_no
=
$data
[
"out_trade_no"
];
$info
=
$this
->
getReceiptData
(
$receipt
,
$isSandbox
);
$info
=
$this
->
getReceiptData
(
$receipt
,
$isSandbox
);
$this
->
logios
(
"info:"
.
json_encode
(
$info
));
$iforderinfo
=
M
(
"users_charge"
)
->
where
(
"trade_no='
{
$info
[
'transaction_id'
]
}
' and type='3'"
)
->
find
();
if
(
$iforderinfo
){
echo
'{"status":"fail","info":"非法提交-001"}'
;
exit
;
}
$chargeinfo
=
M
(
"charge_rules"
)
->
where
(
"product_id='
{
$info
[
'product_id'
]
}
'"
)
->
find
();
if
(
!
$chargeinfo
){
echo
'{"status":"fail","info":"非法提交-002"}'
;
exit
;
...
...
@@ -228,97 +228,109 @@ class PayController extends HomebaseController {
//判断订单是否存在
$orderinfo
=
M
(
"users_charge"
)
->
where
(
"orderno='
{
$out_trade_no
}
' and coin='
{
$chargeinfo
[
'coin'
]
}
' and status='0' and type='3'"
)
->
find
();
if
(
$orderinfo
){
/* 更新会员虚拟币 */
$coin
=
$orderinfo
[
'coin'
]
+
$orderinfo
[
'coin_give'
];
M
(
"users"
)
->
where
(
"id='
{
$orderinfo
[
'touid'
]
}
'"
)
->
setInc
(
"coin"
,
$coin
);
/* 更新 订单状态 */
M
(
"users_charge"
)
->
where
(
"id='
{
$orderinfo
[
'id'
]
}
'"
)
->
save
(
array
(
"status"
=>
1
,
"trade_no"
=>
$info
[
'transaction_id'
],
"ambient"
=>
$info
[
'ambient'
]));
// 邀请返利
$user
=
M
(
"users"
)
->
where
(
"id='
{
$orderinfo
[
'touid'
]
}
'"
)
->
find
();
if
(
$user
[
'pid'
]
>
0
)
{
$config
=
getConfigPri
();
$invite_reward
=
!
empty
(
$config
[
'invite_reward'
])
?
$config
[
'invite_reward'
]
:
0
;
$coin2
=
(
$coin
*
$invite_reward
)
/
100
;
$c
=
(
int
)
$coin2
;
M
(
"users"
)
->
where
(
"id='
{
$user
[
'pid'
]
}
'"
)
->
setInc
(
"i_votes"
,
$c
);
}
$this
->
logios
(
"orderno:"
.
$out_trade_no
.
' 支付成功'
);
}
else
{
$this
->
logios
(
"orderno:"
.
$out_trade_no
.
' 订单信息不存在'
);
echo
'{"status":"fail","info":"订单信息不存在-003"}'
;
echo
'{"status":"fail","info":"订单信息不存在-003"}'
;
exit
();
}
echo
'{"status":"success","info":"充值支付成功"}'
;
exit
;
}
public
function
getReceiptData
(
$receipt
,
$isSandbox
){
}
public
function
getReceiptData
(
$receipt
,
$isSandbox
){
$config
=
getConfigPri
();
$this
->
logios
(
"isSandbox:"
.
$isSandbox
);
$this
->
logios
(
"isSandboxc:"
.
$config
[
'ios_sandbox'
]);
$ambient
=
0
;
if
(
$isSandbox
==
$config
[
'ios_sandbox'
])
{
if
(
$isSandbox
==
$config
[
'ios_sandbox'
])
{
//沙盒
$endpoint
=
'https://sandbox.itunes.apple.com/verifyReceipt'
;
$ambient
=
0
;
}
else
{
}
else
{
//生产
$endpoint
=
'https://buy.itunes.apple.com/verifyReceipt'
;
$endpoint
=
'https://buy.itunes.apple.com/verifyReceipt'
;
$ambient
=
1
;
}
}
$postData
=
json_encode
(
array
(
'receipt-data'
=>
$receipt
)
);
$postData
=
json_encode
(
array
(
'receipt-data'
=>
$receipt
)
);
$ch
=
curl_init
(
$endpoint
);
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
true
);
curl_setopt
(
$ch
,
CURLOPT_SSL_VERIFYPEER
,
false
);
//关闭安全验证
curl_setopt
(
$ch
,
CURLOPT_SSL_VERIFYHOST
,
false
);
//关闭安全验证
curl_setopt
(
$ch
,
CURLOPT_POST
,
true
);
curl_setopt
(
$ch
,
CURLOPT_POSTFIELDS
,
$postData
);
$response
=
curl_exec
(
$ch
);
$errno
=
curl_errno
(
$ch
);
$errmsg
=
curl_error
(
$ch
);
curl_close
(
$ch
);
curl_setopt
(
$ch
,
CURLOPT_POST
,
true
);
curl_setopt
(
$ch
,
CURLOPT_POSTFIELDS
,
$postData
);
$response
=
curl_exec
(
$ch
);
$errno
=
curl_errno
(
$ch
);
$errmsg
=
curl_error
(
$ch
);
curl_close
(
$ch
);
$this
->
logios
(
"getReceiptData response:"
.
json_encode
(
$response
));
$this
->
logios
(
"getReceiptData errno:"
.
json_encode
(
$errno
));
$this
->
logios
(
"getReceiptData errmsg:"
.
json_encode
(
$errmsg
));
if
(
$errno
!=
0
)
{
if
(
$errno
!=
0
)
{
echo
'{"status":"fail","info":"服务器出错,请联系管理员"}'
;
exit
;
}
$data
=
json_decode
(
$response
,
1
);
}
$data
=
json_decode
(
$response
,
1
);
if
(
!
is_array
(
$data
))
{
if
(
!
is_array
(
$data
))
{
echo
'{"status":"fail","info":"验证失败,如有疑问请联系管理"}'
;
exit
;
}
}
if
(
!
isset
(
$data
[
'status'
])
||
$data
[
'status'
]
!=
0
)
{
if
(
!
isset
(
$data
[
'status'
])
||
$data
[
'status'
]
!=
0
)
{
echo
'{"status":"fail","info":"验证失败,如有疑问请联系管理"}'
;
exit
;
}
}
$newdata
=
end
(
$data
[
'receipt'
][
'in_app'
]);
return
array
(
'product_id'
=>
$newdata
[
'product_id'
],
'transaction_id'
=>
$newdata
[
'transaction_id'
],
'ambient'
=>
$ambient
,
return
array
(
'product_id'
=>
$newdata
[
'product_id'
],
'transaction_id'
=>
$newdata
[
'transaction_id'
],
'ambient'
=>
$ambient
,
);
}
/* 苹果支付 */
}
/* 苹果支付 */
/* 打印log */
public
function
logali
(
$msg
){
file_put_contents
(
SITE_PATH
.
'data/paylog/logali_'
.
date
(
'Y-m-d'
)
.
'.txt'
,
date
(
'Y-m-d H:i:s'
)
.
' msg:'
.
$msg
.
"
\r\n
"
,
FILE_APPEND
);
}
}
/* 打印log */
public
function
logwx
(
$msg
){
file_put_contents
(
SITE_PATH
.
'data/paylog/logwx_'
.
date
(
'Y-m-d'
)
.
'.txt'
,
date
(
'Y-m-d H:i:s'
)
.
' msg:'
.
$msg
.
"
\r\n
"
,
FILE_APPEND
);
}
}
/* 打印log */
public
function
logios
(
$msg
){
file_put_contents
(
SITE_PATH
.
'data/paylog/logios_'
.
date
(
'Y-m-d'
)
.
'.txt'
,
date
(
'Y-m-d H:i:s'
)
.
' msg:'
.
$msg
.
"
\r\n
"
,
FILE_APPEND
);
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment