在tp5框架中調用支付寶資金授權撤銷接口

下載支付寶sdk後解壓放到extend目錄下
在public/index.php中定義常量
參考文檔

define('ALI_PATH',__DIR__.'/../extend/alipay/aop/');

創建控制器並寫入代碼

<?php

namespace app\api\controller;

use think\Controller;
use think\Session;

require ALI_PATH.'AopClient.php';
require ALI_PATH.'request/AlipayFundAuthOperationCancelRequest.php';
class Ali extends Controller{
	public static $appid = ''; //appid
    public static $pub_key = ''; //應用公鑰
    public static $prikey = ''; //應用私鑰
    public static $alipubkey = '';//支付寶公鑰
	
	public function chexiao()
    {
        $aop = new \AopClient ();
        $aop->appId = self::$appid;
        //應用私鑰:使用密鑰生成工具生成的較長的那個密鑰
        $aop->rsaPrivateKey = self::$prikey;
        //支付寶公鑰:應用公鑰上傳後自動生成的
        $aop->alipayrsaPublicKey=self::$alipubkey;

        $aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';

        $aop->apiVersion = '1.0';
        $aop->signType = 'RSA2';
        $aop->postCharset='utf-8';
        $aop->format='json';

        $request = new \AlipayFundAuthOperationCancelRequest ();

        $request->setBizContent("{" .
              "\"auth_no\":\"2020033110002001670596798964\"," .
              "\"out_order_no\":\"15856459848767orderid\"," .
              "\"operation_id\":\"20200331196450626705\"," .
              "\"out_request_no\":\"15856459849166395liushui\"," .
              "\"remark\":\"授權撤銷測試\"" .
              "}");

        $result = $aop->execute ( $request);

        var_dump($result) ;
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章