135 lines
3.9 KiB
PHP
135 lines
3.9 KiB
PHP
<?php
|
||
/**
|
||
* Created by PhpStorm.
|
||
* User: Administrator
|
||
* Date: 2018/12/22
|
||
* Time: 9:51
|
||
*/
|
||
|
||
namespace app\payment\controllers;
|
||
|
||
use app\common\events\order\AfterOrderPaidRedirectEvent;
|
||
use app\common\models\Order;
|
||
use app\common\models\OrderPay;
|
||
use app\frontend\modules\payType\BasePayType;
|
||
use app\payment\PaymentController;
|
||
use app\common\services\Pay;
|
||
use Yunshop\HftxPay\services\Verify;
|
||
use app\common\helpers\Url;
|
||
use Illuminate\Support\Facades\DB;
|
||
use app\common\models\AccountWechats;
|
||
|
||
|
||
class HfpayController extends PaymentController
|
||
{
|
||
protected $set;
|
||
|
||
protected $parameters;
|
||
|
||
private $pay_type_id = 201;
|
||
|
||
public $payTpye = [
|
||
'T_JSAPI'=> '微信公众号',
|
||
'T_MINIAPP'=> '微信小程序',
|
||
'A_JSAPI'=> '支付宝JS',
|
||
'A_NATIVE'=> '支付宝正扫',
|
||
'U_NATIVE'=> '银联正扫',
|
||
'U_JSAPI'=> '银联JS',
|
||
'D_NATIVE'=> '数字人民币正扫',
|
||
'T_H5'=> '微信直连H5支付',
|
||
'T_APP'=> '微信APP支付(只支持直连)',
|
||
'T_NATIVE'=> '微信正扫(只支持直连)'
|
||
];
|
||
public $jsonData;
|
||
|
||
public function preAction()
|
||
{
|
||
// $_POST=json_decode(file_get_contents('1700982737pay.txt'),true);
|
||
// var_dump($_POST);die;
|
||
parent::preAction();
|
||
if (empty(\YunShop::app()->uniacid)) {
|
||
$this->jsonData=json_decode($_POST['resp_data'],true);
|
||
\YunShop::app()->uniacid = $this->jsonData['remark'];
|
||
\Setting::$uniqueAccountId = \YunShop::app()->uniacid;
|
||
AccountWechats::setConfig(AccountWechats::getAccountByUniacid(\YunShop::app()->uniacid));
|
||
}
|
||
}
|
||
//异步支付通知
|
||
public function notifyUrl()
|
||
{
|
||
$josn = $_POST;
|
||
// file_put_contents(time().'pay.txt',json_encode($_POST));
|
||
$verify_result = $this->get_RSA_SignResult($josn['sign'],$josn);
|
||
if($verify_result){
|
||
$resp_data=$this->jsonData;
|
||
if ($resp_data['trans_stat'] == 'S') {
|
||
$this->pay_type_id = BasePayType::where('code','=',$resp_data['trade_type'])->value('id');
|
||
$data = [
|
||
'total_fee' => $resp_data['trans_amt'],
|
||
'out_trade_no' => $resp_data['req_seq_id'],
|
||
'trade_no' => $resp_data['out_trans_id'],
|
||
'unit' => 'yuan',
|
||
'pay_type' => '汇付'.$this->payTpye[$resp_data['trade_type']],
|
||
'pay_type_id' => $this->pay_type_id
|
||
];
|
||
$this->payResutl($data);
|
||
}
|
||
echo "success";
|
||
}else{
|
||
echo "fail";
|
||
}
|
||
}
|
||
|
||
|
||
|
||
//订单退款
|
||
public function refundUrl()
|
||
{
|
||
file_put_contents(time().'refundUrl.txt',json_encode($_POST));
|
||
$out_trade_no='';
|
||
$orderPay = OrderPay::where('pay_sn', $out_trade_no)->first();
|
||
if (!is_null($orderPay)) {
|
||
$orders = Order::whereIn('id', $orderPay->order_ids)->get();
|
||
event($event = new AfterOrderPaidRedirectEvent($orders, $orderPay->id));
|
||
}
|
||
echo "success";
|
||
}
|
||
|
||
|
||
public function get_RSA_SignResult($sign, $data)
|
||
{
|
||
$Verify = new Verify();
|
||
return $Verify->VerifySign($sign, $data);
|
||
}
|
||
|
||
/**
|
||
* 响应日志
|
||
*
|
||
* @param $post
|
||
*/
|
||
public function log($post, $desc)
|
||
{
|
||
//访问记录
|
||
Pay::payAccessLog();
|
||
//保存响应数据
|
||
Pay::payResponseDataLog($post['out_trade_no'], $desc, json_encode($post));
|
||
}
|
||
|
||
public function refundLog($post, $desc)
|
||
{
|
||
//访问记录
|
||
Pay::payAccessLog();
|
||
//保存响应数据
|
||
Pay::payResponseDataLog(0, $desc, json_encode($post));
|
||
}
|
||
|
||
public function withdrawLog($post, $desc)
|
||
{
|
||
//访问记录
|
||
Pay::payAccessLog();
|
||
//保存响应数据
|
||
Pay::payResponseDataLog($post['batch_no'], $desc, json_encode($post));
|
||
}
|
||
|
||
}
|