官方文檔
下載支付寶sdk後解壓放到extend目錄下
在public/index.php中定義常量
參考文檔
define('ALI_PATH',__DIR__.'/../extend/alipay/aop/');
創建控制器並寫入代碼
require ALI_PATH.'AopClient.php';
require ALI_PATH.'request/AlipayTradePayRequest.php';
class Ali extends Controller{
public static $appid = ''; //appid
public static $pub_key = '';//應用公鑰
public static $prikey = ''; //應用私鑰
public static $alipubkey = '';//支付寶公鑰
public function zhifu()
{
$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 \AlipayTradePayRequest();
$request->setBizContent("{" .
"\"out_trade_no\":\"15857250102552orderid\"," . //商戶訂單號
"\"product_code\":\"PRE_AUTH_ONLINE\"," . //銷售產品碼 固定值PRE_AUTH_ONLINE
"\"subject\":\"授權轉支付\"," . //訂單標題
"\"buyer_id\":\"2088512270592674\"," . //買家支付寶id
"\"seller_id\":\"2088421932681389\"," . //賣家支付寶id
"\"total_amount\":\"0.01\"," . //支付金額
"\"auth_no\":\"2020040110002001670597551931\"," . //支付寶授權碼
"\"body\":\"授權轉支付測試\"," . //訂單描述
"\"auth_confirm_mode\":\"COMPLETE\"" . //交易模式
"}");
$result = $aop->execute ( $request);
var_dump($result) ;
}
}