|
|
<?php
|
|
|
|
|
|
namespace App\Http\Controllers\Customer;
|
|
|
|
|
|
use App\Events\RechargeSucceed;
|
|
|
use App\Http\Controllers\Controller;
|
|
|
use App\Models\Orders;
|
|
|
use App\Models\Recharge;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
class PayCallbackController extends Controller
|
|
|
{
|
|
|
public function index()
|
|
|
{
|
|
|
//处理回调数据
|
|
|
$xml = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : file_get_contents("php://input");
|
|
|
Log::info($xml);
|
|
|
$array = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
|
|
|
$pay = (new Recharge())->with("order")->where("serial", $array["out_trade_no"])->first();
|
|
|
if (!$pay) exit();
|
|
|
if ($pay->paid_at) exit();
|
|
|
Log::info($pay);
|
|
|
|
|
|
//开始处理业务
|
|
|
$notify = new \NotifyPub($pay->order->project_id);
|
|
|
//存储微信的回调
|
|
|
$notify->saveData($xml);
|
|
|
|
|
|
//验证签名,并回应微信。
|
|
|
//对后台通知交互时,如果微信收到商户的应答不是成功或超时,微信认为通知失败,
|
|
|
//微信会通过一定的策略(如30分钟共8次)定期重新发起通知,
|
|
|
//尽可能提高通知的成功率,但微信不保证通知最终能成功。
|
|
|
if ($notify->checkSign() == FALSE) {
|
|
|
$notify->setReturnParameter("return_code", "FAIL");//返回状态码
|
|
|
$notify->setReturnParameter("return_msg", "签名失败");//返回信息
|
|
|
} else {
|
|
|
$notify->setReturnParameter("return_code", "SUCCESS");//设置返回码
|
|
|
}
|
|
|
$returnXml = $notify->returnXml();
|
|
|
echo $returnXml;
|
|
|
|
|
|
if ($notify->checkSign() == TRUE) {
|
|
|
if ($notify->data["return_code"] == "FAIL") {
|
|
|
exit();
|
|
|
}
|
|
|
$transaction_id = $notify->data["transaction_id"];
|
|
|
|
|
|
$update = [
|
|
|
"paid_at" => date("Y-m-d H:i:s"),
|
|
|
"payment_serial" => $transaction_id
|
|
|
];
|
|
|
|
|
|
$result = $pay->update($update);
|
|
|
//充值成功后处理
|
|
|
if ($result) {
|
|
|
event(new RechargeSucceed($pay));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|