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

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

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

創建控制器並寫入代碼

<?php

namespace app\api\controller;

use think\Controller;
use think\Session;
use think\DB;


require ALI_PATH.'AopClient.php';
require ALI_PATH.'request/AlipayFundAuthOperationDetailQueryRequest.php';
class Ali extends Controller{
	public static $appid = ''; //appid
    public static $pub_key = ''; //應用公鑰
    public static $prikey = ''; //應用私鑰
    public static $alipubkey = '';//支付寶公鑰

	public function queryorder()
    {
        $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 \AlipayFundAuthOperationDetailQueryRequest ();
        $request->setBizContent("{" .
          //  "\"auth_no\":\"2014021601002000640012345678\"," .
            "\"out_order_no\":\"15856459848767orderid\"," .
          //  "\"operation_id\":\"20140216010020006400\"," .
            "\"out_request_no\":\"15856459849166395liushui\"" .
            "}");

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

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