Files
2026-09-01 22:15:50 +08:00

134 lines
5.1 KiB
PHP

<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\api\controller;
use app\api\model\Notify as NotifyModel;
use app\api\model\Order as OrderModel;
use app\api\model\Merchant as MerchantModel;
use app\api\model\order\Record as RecordModel;
use app\common\library\wechat\WxPay;
use app\common\library\leshua\LsPay;
use think\response\Json;
/**
* 支付成功异步通知接口
* Class Notify
* @package app\api\controller
*/
class Notify extends Controller
{
/**
* 支付成功异步通知(微信小程序-微信支付)
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function wxpay()
{
// 微信支付组件:验证异步通知
$WxPay = new WxPay();
$WxPay->notify();
}
/**
* 支付成功异步通知(微信小程序-乐刷支付)
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function leshua()
{
// 微信支付组件:验证异步通知
$LsPay = new LsPay();
$LsPay->notify();
}
/**
* 发送通知
* @throws \app\common\exception\BaseException
* @throws \think\exception\DbException
*/
public function sendNotify()
{
$model = new NotifyModel();
$array = $model->getList();
$this->saveLog("进入回调查询");
$order_status = ['10'=>'等待支付','20'=>'支付成功','30'=>'支付超时'];
foreach ($array as $val){
$status = 0;
//发送通知
$model = new OrderModel;
$order = $model->getOrderDetailById($val['order_id']);
if(is_object($order)) {
$order_no = $this->getOrderNo($order['order_no']);
$merchant = MerchantModel::detail($order['merchant_id']);
$params = [
'appid' => $merchant['appId'],
'name' => $order['name'],
'money' => $order['money'],
'order_no' => $order_no,
'order_no_sn' => $order['order_no_sn'],
'order_status' => $order['order_status'],
'order_status_text' => $order_status[$order['order_status']],
'create_time' => $order['create_time'],
];
//$this->saveLog("回调数据,".json_encode($params,320));
$sign = $this->makeSign($params,$merchant['appKey']);
$params['sign'] = $sign;
$res = $this->httpCurl($val['notify_url'], $params, 'POST');
$this->saveLog("回调通知,订单:".$order_no.",结果:".json_encode($res,320));
//var_dump($res);
if ($res['code'] == '0000') {
$status = 1;
}
$nm = NotifyModel::detail($val['notify_id']);
$result = $nm->sureNotify(['status' => $status, 'num' => $nm['num'] + 1]);
$this->saveLog("回调通知订单状态修改,订单:".$order_no.",结果:".$result);
}
}
}
/**
* 发送通知
*/
public function notify()
{
$res = json_decode('{"optType":"cancel_share","amount":3,"oilCardNo":"YKA2407232037340001","type":"sub","order_id":10171,"user_id":10001,"store_id":10001}',true);
// 油卡变动通知
$order = OrderModel::detail(['oilCardNo'=>$res['oilCardNo'], 'amount'=>$res['amount']]);
$res['order_id'] = $order['order_id'];
$res['user_id'] = $order['user_id'];
$res['store_id'] = $order['store_id'];
$this->saveLog('油卡变动参数:'.json_encode($res));
$RecordModel = new RecordModel();
$this->saveLog('油卡变动记录写入结果:'. $RecordModel->add($res));
/*$header = [
'method' => 'syb.notify.oilCard.share',
];
$body = [
'shareNo' => '11',
'oilCardNo' => '22',
'saleOrderNo' => '33',
'amount' => 0.01,
'status' =>'success',
'msg' => '',
'oilCardType' => 'card',
];
$response = $this->sendRequest('http://139.129.21.253/index.php?s=/api/sybNotify/notify', $body, $header);
//var_dump($response);*/
}
}