|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Callback\Controller;
|
|
|
|
|
|
|
|
|
|
use Base\Service\PayService;
|
|
|
|
|
use Org\UcenterSDK\Ucservice;
|
|
|
|
|
use Think\Log;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新版支付回调控制器
|
|
|
|
|
* @author 小纯洁
|
|
|
|
|
*/
|
|
|
|
|
class Notify2Controller extends BaseController
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
*通知方法
|
|
|
|
|
*/
|
|
|
|
|
public function notify()
|
|
|
|
|
{
|
|
|
|
|
C(api('Config/lists'));
|
|
|
|
|
$apitype = I('get.apitype');#获取支付api类型
|
|
|
|
|
if (IS_POST && !empty($_POST)) {
|
|
|
|
|
$notify = $_POST;
|
|
|
|
|
} elseif (IS_GET && !empty($_GET)) {
|
|
|
|
|
$notify = $_GET;
|
|
|
|
|
unset($notify['methodtype']);
|
|
|
|
|
unset($notify['apitype']);
|
|
|
|
|
} else {
|
|
|
|
|
$notify = file_get_contents("php://input");
|
|
|
|
|
if (empty($notify)) {
|
|
|
|
|
$this->record_logs("Access Denied");
|
|
|
|
|
exit('Access Denied');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log::write(serialize($notify), Log::DEBUG);
|
|
|
|
|
$pay_way = $apitype;
|
|
|
|
|
if ($apitype == "swiftpass") {
|
|
|
|
|
$apitype = "weixin";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Vendor('Alipay.AopSdk');
|
|
|
|
|
$aop = new \AopClient();
|
|
|
|
|
|
|
|
|
|
if (!$notify['auth_app_id']) {
|
|
|
|
|
$this->record_logs("auth_app_id不存在!");
|
|
|
|
|
echo 'fail';
|
|
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
|
$merchant = M('payment_merchant', 'tab_')->where([
|
|
|
|
|
'identifier' => $notify['auth_app_id']
|
|
|
|
|
])->find();
|
|
|
|
|
if (!$merchant) {
|
|
|
|
|
$this->record_logs("找不到商户!".$notify['auth_app_id']);
|
|
|
|
|
echo 'fail';
|
|
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$payConf = json_decode($merchant['config'], true);
|
|
|
|
|
$aop->alipayrsaPublicKey = $payConf['public_key'];
|
|
|
|
|
|
|
|
|
|
$result = $aop->rsaCheckV1($notify,'','RSA2');
|
|
|
|
|
if ($result) {
|
|
|
|
|
//获取回调订单信息
|
|
|
|
|
if (I('get.methodtype') == "notify") {
|
|
|
|
|
$order_info = $notify;
|
|
|
|
|
if($order_info['trade_status'] == 'TRADE_SUCCESS'){
|
|
|
|
|
$payService = new PayService();
|
|
|
|
|
if (!$payService->alipayTradeQuery($payConf, $notify)) {
|
|
|
|
|
sleep(1); // 延迟1s 在查一次
|
|
|
|
|
if (!$payService->alipayTradeQuery($payConf, $notify)) {
|
|
|
|
|
Log::write("ALIQUERYFAIL->".serialize($notify), Log::DEBUG);
|
|
|
|
|
echo 'fail';
|
|
|
|
|
exit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$pay_where = substr($order_info['out_trade_no'], 0, 2);
|
|
|
|
|
$result = false;
|
|
|
|
|
switch ($pay_where) {
|
|
|
|
|
case 'SP':
|
|
|
|
|
$result = $this->set_spend($order_info);
|
|
|
|
|
break;
|
|
|
|
|
case 'PF':
|
|
|
|
|
$result = $this->set_deposit($order_info);
|
|
|
|
|
break;
|
|
|
|
|
case 'AG':
|
|
|
|
|
$result = $this->set_agent($order_info);
|
|
|
|
|
break;
|
|
|
|
|
case 'BR':
|
|
|
|
|
$result = $this->set_bind_recharge($order_info);
|
|
|
|
|
break;
|
|
|
|
|
case 'TB':
|
|
|
|
|
$result = $this->set_balance($order_info);
|
|
|
|
|
break;
|
|
|
|
|
case 'SI':
|
|
|
|
|
$result = $this->set_order($order_info);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
exit('accident order data');
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
echo "success";
|
|
|
|
|
}else{
|
|
|
|
|
$this->record_logs("支付失败!");
|
|
|
|
|
echo "fail";
|
|
|
|
|
}
|
|
|
|
|
}elseif (I('get.methodtype') == "return") {
|
|
|
|
|
redirect('http://' . $_SERVER['HTTP_HOST'] . '/media.php?s=/Recharge/pay.html');
|
|
|
|
|
}elseif (I('get.methodtype') == "return_tb"){
|
|
|
|
|
redirect('http://' . $_SERVER['HTTP_HOST'] . '/index.php/?s=/Home/PromoteCoin/lists.html');
|
|
|
|
|
}
|
|
|
|
|
elseif (I('get.methodtype') == "return_dc"){
|
|
|
|
|
redirect('http://' . $_SERVER['HTTP_HOST'] . '/index.php/?s=/Home/Charge/agent_pay_list.html');
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$this->record_logs("支付验证失败");
|
|
|
|
|
redirect('http://' . $_SERVER['HTTP_HOST'] . '/media.php', 3, '支付验证失败');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function checkAliPartner($orderNo)
|
|
|
|
|
{
|
|
|
|
|
$prefix = substr($orderNo, 0, 2);
|
|
|
|
|
$result = false;
|
|
|
|
|
$promoteId = 0;
|
|
|
|
|
switch ($prefix) {
|
|
|
|
|
case 'SP':
|
|
|
|
|
$promoteId = M('spend', 'tab_')->where(['pay_order_number' => $orderNo])->getField('promote_id');
|
|
|
|
|
break;
|
|
|
|
|
case 'PF':
|
|
|
|
|
$promoteId = M('deposit', 'tab_')->where(['pay_order_number' => $orderNo])->getField('promote_id');
|
|
|
|
|
break;
|
|
|
|
|
case 'AG':
|
|
|
|
|
$promoteId = M('agent', 'tab_')->where(['pay_order_number' => $orderNo])->getField('promote_id');
|
|
|
|
|
break;
|
|
|
|
|
case 'BR':
|
|
|
|
|
$promoteId = M('bind_recharge', 'tab_')->where(['pay_order_number' => $orderNo])->getField('promote_id');
|
|
|
|
|
break;
|
|
|
|
|
case 'TB':
|
|
|
|
|
$promoteId = M('balance', 'tab_')->where(['pay_order_number' => $orderNo])->getField('promote_id');
|
|
|
|
|
break;
|
|
|
|
|
case 'SI':
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if ($this->isKBCPartner($promoteId)) {
|
|
|
|
|
return 'kingbocai';
|
|
|
|
|
} else {
|
|
|
|
|
return 'alipay';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function isKBCPartner($promoteId)
|
|
|
|
|
{
|
|
|
|
|
$promote = null;
|
|
|
|
|
$company = null;
|
|
|
|
|
if ($promoteId) {
|
|
|
|
|
$promote = M('promote', 'tab_')->field(['company_id', 'id'])->where(['id' => $promoteId])->find();
|
|
|
|
|
}
|
|
|
|
|
if ($promote) {
|
|
|
|
|
$company = M('promote_company', 'tab_')->field(['ali_partner', 'id'])->where(['id' => $promote['compnay_id']])->find();
|
|
|
|
|
}
|
|
|
|
|
if ($company && $company['ali_partner'] == 1) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 支付宝退款回调
|
|
|
|
|
* @return [type] [description]
|
|
|
|
|
*/
|
|
|
|
|
public function refund_validation()
|
|
|
|
|
{
|
|
|
|
|
if (empty($_POST)) {
|
|
|
|
|
$this->record_logs("回调!");
|
|
|
|
|
} else {
|
|
|
|
|
$pay = new \Think\Pay('alipay', C('alipay'));
|
|
|
|
|
|
|
|
|
|
if ($pay->verifyNotify($_POST)) {
|
|
|
|
|
//批次号
|
|
|
|
|
$batch_no = $_POST['batch_no'];
|
|
|
|
|
//批量退款数据中转账成功的笔数
|
|
|
|
|
$success_num = $_POST['success_num'];
|
|
|
|
|
if ($success_num > 0) {
|
|
|
|
|
$map['batch_no'] = $batch_no;
|
|
|
|
|
$date['tui_status'] = 1;
|
|
|
|
|
$date['tui_time'] = time();
|
|
|
|
|
M('refund_record', 'tab_')->where($map)->save($date);
|
|
|
|
|
file_put_contents(dirname(__FILE__)."/as.txt", json_encode(M('refund_record','tab_')->getlastsql()));
|
|
|
|
|
|
|
|
|
|
$map_spend['pay_order_number'] = get_refund_pay_order_number($batch_no);
|
|
|
|
|
$spen_date['sub_status']=1;
|
|
|
|
|
$spen_date['settle_check']= 1;
|
|
|
|
|
M('spend','tab_')->where($map_spend)->save($spen_date);
|
|
|
|
|
}
|
|
|
|
|
echo "success"; //请不要修改或删除
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
//验证失败
|
|
|
|
|
echo "fail";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*判断平台币充值是否存在
|
|
|
|
|
*/
|
|
|
|
|
protected function deposit_is_exist($out_trade_no)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
$deposit = M('deposit', 'tab_');
|
|
|
|
|
|
|
|
|
|
$map['pay_status'] = 1;
|
|
|
|
|
|
|
|
|
|
$map['pay_order_number'] = $out_trade_no;
|
|
|
|
|
|
|
|
|
|
$res = $deposit->where($map)->find();
|
|
|
|
|
|
|
|
|
|
if (empty($res)) {
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//判断充值是否存在
|
|
|
|
|
public function recharge_is_exist($out_trade_no)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
$recharge = M('spend', 'tab_');
|
|
|
|
|
|
|
|
|
|
$map['pay_status'] = 1;
|
|
|
|
|
|
|
|
|
|
$map['pay_order_number'] = $out_trade_no;
|
|
|
|
|
|
|
|
|
|
$res = $recharge->where($map)->find();
|
|
|
|
|
|
|
|
|
|
if (empty($res)) {
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//判断代充是否存在
|
|
|
|
|
public function agent_is_exist($out_trade_no)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
$recharge = M('agent', 'tab_');
|
|
|
|
|
|
|
|
|
|
$map['pay_status'] = 1;
|
|
|
|
|
|
|
|
|
|
$map['pay_order_number'] = $out_trade_no;
|
|
|
|
|
|
|
|
|
|
$res = $recharge->where($map)->find();
|
|
|
|
|
|
|
|
|
|
if (empty($res)) {
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|