You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.1 KiB

5 years ago
<?php
namespace App\Http\Controllers\Customer;
use App\Events\RechargeSucceed;
use App\Http\Controllers\Controller;
1 year ago
use App\Models\Orders;
5 years ago
use App\Models\Recharge;
use Illuminate\Support\Facades\Log;
class PayCallbackController extends Controller
{
1 year ago
public function index()
{
1 year ago
//处理回调数据
5 years ago
$xml = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : file_get_contents("php://input");
Log::info($xml);
1 year ago
$array = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
1 year ago
$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);
1 year ago
//存储微信的回调
5 years ago
$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));
}
}
}
}