php-支付宝h5支付

<?php
namespace app\api\service;
use think\facade\{View,Session,Cache,Db};
use think\exception\HttpResponseException;
require_once '../extend/alipay/wappay/service/AlipayTradeService.php';
require_once '../extend/alipay/wappay/buildermodel/AlipayTradeRefundContentBuilder.php';
class Alipay
{
     //调用此方法- 会返回一个链接,跳转此链接 可到支付宝页面支付
    public function pay($orderId,$price){
        $aop = new \AopClient ();
        $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
        $aop->appId = 'xxxxx';
        $aop->rsaPrivateKey = 'xxxx';
        $aop->alipayrsaPublicKey='xxxxx';
        $aop->apiVersion = '1.0';
        $aop->signType = 'RSA2';
        $aop->postCharset='UTF-8';
        $aop->format='json';
        /******必传参数******/
        $object = new \stdClass();
        //商户订单号,商家自定义,保持唯一性
        //$orderId;
        $object->out_trade_no = time().uniqid();
  
        Db::name("wxpay_log")->insert([
            "aut_id"=>$orderId,
            "ut_type"=>1,
            "price"=>$price,
            "no"=>$object->out_trade_no,
            "addtime"=>time()
            ]);
  
        //支付金额,最小值0.01元
        $object->total_amount = $price;
        //订单标题,不可使用特殊符号
        $object->subject = '征信服务';
        /******可选参数******/
        //手机网站支付默认传值FAST_INSTANT_TRADE_PAY
        $object->product_code ='QUICK_WAP_WAY';
        $object->time_expire = date("Y-m-d H:i:s",time()+2*60*60);
        $json = json_encode($object);
        $request = new \AlipayTradeWapPayRequest();
        //异步接收地址,仅支持http/https,公网可访问
        $request->setNotifyUrl("xxxxxxxxx");
        //同步跳转地址,仅支持http/https
        $request->setReturnUrl("xxxx");
        $request->setBizContent($json);
        $result = $aop->pageExecute ( $request); 

        return $result;
   
  
    }
    //退款
    public function repay($trade_no,$refund_amount,$refund_reason="同意退款"){
  
        $RequestBuilder=new \AlipayTradeRefundContentBuilder();
    $RequestBuilder->setOutTradeNo($trade_no);
        //$RequestBuilder->setTradeNo($trade_no);
        $RequestBuilder->setRefundAmount($refund_amount);
//        $RequestBuilder->setOutRequestNo($out_request_no);
        $RequestBuilder->setRefundReason($refund_reason);
        $config=[
             "gatewayUrl" => 'https://openapi.alipay.com/gateway.do',
        "app_id" => 'xxxxx',
        "merchant_private_key" => 'xxxx',
        'alipay_public_key'=>'xxxxx',
   
        "sign_type" => 'RSA2',
        "charset"=>'UTF-8',
        "format"=>'json'
  
  
            ];
        $aop = new \AlipayTradeService($config);

        /**
         * alipay.trade.refund (统一收单交易退款接口)
         * @param $builder 业务参数,使用buildmodel中的对象生成。
         * @return $response 支付宝返回的信息
         */
        $response = $aop->Refund($RequestBuilder);

  
        return $response;
  
  
  
  
  
  
  
  
  
  
  
    }
  
  
}