Files
jianfeng-server/longbingcore/wxcore/PayModel.php
2025-10-02 10:33:06 +08:00

178 lines
4.1 KiB
PHP
Executable File

<?php
declare(strict_types=1);
namespace longbingcore\wxcore;
use app\ApiRest;
use think\App;
use think\facade\Db;
class PayModel extends ApiRest {
// static protected $uniacid;
public function __construct($pay_config)
{
$this->pay_config = $pay_config;
}
/**
* @author chenniang
* @DataTime: 2022-08-17 14:36
* @功能说明:
*/
public function findOrder(){
$pay_config = $this->payConfig();
require_once EXTEND_PATH.'alipay/aop/AopClient.php';
require_once EXTEND_PATH.'alipay/aop/request/AlipayTradeQueryRequest.php';
$aop = new \AopClient ();
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
// $aop->gatewayUrl = 'https://openapi.alipaydev.com/gateway.do';
$aop->appId = $pay_config[ 'payment' ][ 'ali_appid' ];
$aop->rsaPrivateKey = $pay_config['payment']['ali_privatekey'];
$aop->alipayrsaPublicKey=$pay_config['payment']['ali_publickey'];
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset='UTF-8';
$aop->format='json';
$object = new \stdClass();
$object->out_trade_no = '20150320010101001';
//$object->trade_no = '2014112611001004680073956707';
$json = json_encode($object);
$request = new \AlipayTradeQueryRequest();
$request->setBizContent($json);
$result = $aop->execute ( $request);
return $result;
}
/**
* @author chenniang
* @DataTime: 2022-08-10 16:36
* @功能说明:支付宝支付
*/
public function aliPay($order_code,$price,$subject){
require_once EXTEND_PATH.'alipay/aop/AopClient.php';
require_once EXTEND_PATH.'alipay/aop/request/AlipayTradeAppPayRequest.php';
$pay_config = $this->payConfig();
$aop = new \AopClient ();
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->gatewayUrl = 'https://openapi.alipaydev.com/gateway.do';
$aop->appId = $pay_config[ 'payment' ][ 'ali_appid' ];
$aop->rsaPrivateKey = $pay_config['payment']['ali_privatekey'];;
$aop->alipayrsaPublicKey= $pay_config['payment']['ali_publickey'];;
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset='UTF-8';
$aop->format='json';
$object = new \stdClass();
$object->out_trade_no = $order_code;
$object->total_amount = $price;
$object->subject = $subject;
$object->product_code ='QUICK_MSECURITY_PAY';
//$object->time_expire = date('Y-m-d H:i:s',time());
$json = json_encode($object);
$request = new \AlipayTradeAppPayRequest();
$request->setNotifyUrl("https://".$_SERVER['HTTP_HOST'].'/index.php/shop/IndexWxPay/aliNotify');
$request->setBizContent($json);
$result = $aop->sdkExecute ( $request);
return $result;
}
/**
* @author chenniang
* @DataTime: 2022-08-11 17:23
* @功能说明:退款
*/
public function aliRefund($order_code,$price){
require_once EXTEND_PATH.'alipay/aop/AopClient.php';
require_once EXTEND_PATH.'alipay/aop/request/AlipayTradeRefundRequest.php';
$pay_config = $this->payConfig();
$aop = new \AopClient ();
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->appId = $pay_config[ 'payment' ][ 'ali_appid' ];
$aop->rsaPrivateKey = $pay_config['payment']['ali_privatekey'];;
$aop->alipayrsaPublicKey= $pay_config['payment']['ali_publickey'];;
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset='UTF-8';
$aop->format='json';
$object = new \stdClass();
$object->trade_no = $order_code;
$object->refund_amount = $price;
$object->out_request_no = 'HZ01RF001';
$json = json_encode($object);
$request = new \AlipayTradeRefundRequest();
$request->setBizContent($json);
$result = $aop->execute ( $request);
$result = !empty($result)?object_array($result):[];
return $result;
}
}