bztang-admin/app/payment/controllers/HfpayController.php

126 lines
3.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/12/22
* Time: 9:51
*/
namespace app\payment\controllers;
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('1700912948pay.txt'),true);
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;
$this->pay_type_id = BasePayType::where('code','=',$resp_data['trade_type'])->value('id');
// var_dump($resp_data);
$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
];
// var_dump($data);die;
$this->payResutl($data);
echo "success";
}else{
echo "fail";
}
}
//订单退款
public function refundUrl()
{
file_put_contents(time().'refundUrl.txt',json_encode($_POST));
}
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));
}
}