官方文檔
下載支付寶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/AlipayFundAuthOrderUnfreezeRequest.php';
class Ali extends Controller{
public static $appid = ''; //appid
public static $pub_key = ''; //應用公鑰
public static $prikey = ''; //應用私鑰
public static $alipubkey = '';//支付寶公鑰
public function jiedong()
{
$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 \AlipayFundAuthOrderUnfreezeRequest ();
$request->setBizContent("{" .
"\"auth_no\":\"2020033110002001670596884616\"," . //支付寶授權號
"\"out_request_no\":\"15856440576809353liushui\"," . //商戶流水號
"\"amount\":0.01," . //解凍金額
"\"remark\":\"解凍測試\"" . //描述
"}");
$result = $aop->execute ( $request);
var_dump($result) ;
}
}