123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351 |
- <?php
- class AliPay {
- private $appId;
- private $rsaPrivateKey;
- private $signType;
- private $alipayrsaPublicKey;
- private $notifyUrl;
- private $returnUrl;
-
- public function __construct($options = null) {
- $this->appId = isset ($options['appId']) ? $options['appId'] : config('ali_app_id');
- $this->rsaPrivateKey = isset ($options['private_key_path']) ? $options['private_key_path'] : config('private_key');
- $this->signType = isset ($options['sign_type']) ? $options['sign_type'] : config('ali_sign_type');
- $this->notifyUrl = isset ($options['notify_url']) ? $options['notify_url'] : config('notify_url');
- $this->alipayrsaPublicKey = isset ($options['ali_public_key_path']) ? $options['ali_public_key_path'] : config('ali_public_key');
- }
-
- public function AliPayApp($data) {
- if (empty($this->appId))
- return false;
- $aliPayPath = './Plugins/AliPay/alipay-sdk/';
- require_once($aliPayPath . "aop/AopClient.php");
- require_once($aliPayPath . 'aop/request/AlipayTradeAppPayRequest.php');
- $aop = new \AopClient;
- $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
- $aop->appId = $this->appId;
- $aop->rsaPrivateKey = $this->rsaPrivateKey;
- $aop->format = "json";
- $aop->charset = "UTF-8";
- $aop->signType = $this->signType;
- $aop->alipayrsaPublicKey = $this->alipayrsaPublicKey;
-
- $request = new \AlipayTradeAppPayRequest();
-
- $bizcontent = json_encode([
- 'body' => $data['body'],
- 'subject' => $data['subject'],
- 'out_trade_no' => $data['out_trade_no'],
- 'total_amount' => $data['total_amount'],
- 'timeout_express' => '30m',
- 'passback_params' => urlencode($data['pass_back_params']),
- 'product_code' => 'QUICK_MSECURITY_PAY'
- ]);
- $request->setNotifyUrl($this->notifyUrl);
- $request->setBizContent($bizcontent);
-
- $response = $aop->sdkExecute($request);
-
-
-
- return $response;
- }
-
- public function AliPayWeb($data) {
- if (empty($this->appId))
- return false;
- $aliPayPath = './Plugins/AliPay/alipay-sdk/';
- require_once($aliPayPath . "aop/AopClient.php");
- require_once($aliPayPath . 'aop/request/AlipayTradePagePayRequest.php');
- $aop = new \AopClient();
- $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
- $aop->appId = $this->appId;
- $aop->rsaPrivateKey = $this->rsaPrivateKey;
- $aop->signType = $this->signType;
- $aop->alipayrsaPublicKey = $this->alipayrsaPublicKey;
- $aop->apiVersion = '1.0';
- $aop->postCharset = 'UTF-8';
- $aop->format = 'json';
- $request = new \AlipayTradePagePayRequest();
- $bizcontent = json_encode([
- 'body' => $data['body'],
- 'subject' => $data['subject'],
- 'out_trade_no' => $data['out_trade_no'],
- 'total_amount' => $data['total_amount'],
- 'product_code' => 'FAST_INSTANT_TRADE_PAY'
- ]);
- $request->setNotifyUrl($this->notifyUrl);
- $request->setReturnUrl($this->returnUrl);
- $request->setBizContent($bizcontent);
- $result = $aop->pageExecute($request);
-
- return $result;
- }
-
- public function AliPayMobileWeb($data) {
- if (empty($this->appId))
- return false;
- $aliPayPath = './Plugins/AliPay/alipay-sdk/';
- require_once($aliPayPath . "aop/AopClient.php");
- require_once($aliPayPath . 'aop/request/AlipayTradeWapPayRequest.php');
- $aop = new \AopClient();
- $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
- $aop->appId = $this->appId;
- $aop->rsaPrivateKey = $this->rsaPrivateKey;
- $aop->signType = $this->signType;
- $aop->alipayrsaPublicKey = $this->alipayrsaPublicKey;
- $aop->apiVersion = '1.0';
- $aop->postCharset = 'UTF-8';
- $aop->format = 'json';
- $request = new \AlipayTradeWapPayRequest ();
- $bizcontent = json_encode([
- 'body' => $data['body'],
- 'subject' => $data['subject'],
- 'out_trade_no' => $data['out_trade_no'],
- 'total_amount' => $data['total_amount'],
- 'timeout_express' => '90m',
- 'product_code' => 'QUICK_WAP_WAY'
- ]);
- $request->setNotifyUrl($this->notifyUrl);
- $request->setReturnUrl($this->returnUrl);
- $request->setBizContent($bizcontent);
- $result = $aop->pageExecute($request);
-
- return $result;
- }
-
- public function AliPayNotifyCheck() {
- $aliPayPath = './Plugins/AliPay/alipay-sdk/';
- require_once($aliPayPath . "aop/AopClient.php");
- $aop = new \AopClient;
- $aop->alipayrsaPublicKey = $this->alipayrsaPublicKey;
-
- $flag = $aop->rsaCheckV1($_POST, NULL, $this->signType);
- return $flag;
- }
-
- public function AliPayWithdrawOld($data) {
- if (empty($this->appId))
- return false;
- if ($data['amount']<0.1)
- return false;
- $aliPayPath = './Plugins/AliPay/alipay-sdk/';
- require_once($aliPayPath . "aop/AopClient.php");
- require_once($aliPayPath . 'aop/request/AlipayFundTransToaccountTransferRequest.php');
- $aop = new \AopClient;
- $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
- $aop->appId = $this->appId;
- $aop->rsaPrivateKey = $this->rsaPrivateKey;
- $aop->format = "json";
- $aop->charset = "UTF-8";
- $aop->signType = $this->signType;
- $aop->alipayrsaPublicKey = $this->alipayrsaPublicKey;
-
- $request = new \AlipayFundTransToaccountTransferRequest ();
-
- $bizcontent = json_encode([
- 'out_biz_no' => $data['out_biz_no'],
- 'payee_type' => 'ALIPAY_LOGONID',
- 'payee_account' => $data['payee_account'],
- 'amount' => $data['amount'],
- 'payee_real_name' => $data['payee_real_name'],
- 'payer_show_name' => $data['payer_show_name'],
- 'remark' => $data['remark'],
- ]);
- $request->setBizContent($bizcontent);
- $result = $aop->execute($request);
- $responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
- $resultCode = $result->$responseNode->code;
- if(!empty($resultCode)&&$resultCode == 10000){
-
- return true;
- } else {
-
- return false;
- }
- }
-
- public function AliPayWithdraw($data) {
- if (empty($this->appId))
- return false;
- if ($data['trans_amount'] < 0.1)
- return false;
- $aliPayPath = '../extend/AliPay/aop/';
- require_once $aliPayPath . 'AopClient.php';
- require_once $aliPayPath . 'AopCertClient.php';
- require_once $aliPayPath . 'AopCertification.php';
- require_once $aliPayPath . 'AlipayConfig.php';
- require_once $aliPayPath . 'request/AlipayFundTransUniTransferRequest.php';
- $privateKey = $this->rsaPrivateKey;
- $alipayConfig = new AlipayConfig();
- $alipayConfig->setPrivateKey($privateKey);
- $alipayConfig->setServerUrl("https://openapi.alipay.com/gateway.do");
- $alipayConfig->setAppId($this->appId);
- $alipayConfig->setCharset("UTF-8");
- $alipayConfig->setSignType("RSA2");
- $alipayConfig->setEncryptKey("");
- $alipayConfig->setFormat("json");
- $alipayConfig->setAppCertPath('../extend/AliPay/cert/appCertPublicKey_2021003139615320.crt');
- $alipayConfig->setAlipayPublicCertPath('../extend/AliPay/cert/alipayCertPublicKey_RSA2.crt');
- $alipayConfig->setRootCertPath('../extend/AliPay/cert/alipayRootCert.crt');
- $alipayClient = new AopCertClient($alipayConfig);
- $alipayClient->isCheckAlipayPublicCert = true;
- $request = new AlipayFundTransUniTransferRequest();
- $data = json_encode($data);
- $request->setBizContent($data);
- $responseResult = $alipayClient->execute($request);
- $responseApiName = str_replace(".","_",$request->getApiMethodName())."_response";
- $responsecode = $responseResult->$responseApiName->code;
- if(!empty($responsecode)&&$responsecode==10000){
- return true;
- } else{
- return false;
- }
- }
-
- public function userCertifyInitialize($data) {
- $aliPayPath = './Plugins/AliPay/alipay-sdk/';
- require_once($aliPayPath . "aop/AopClient.php");
- require_once($aliPayPath . 'aop/request/AlipayUserCertifyOpenInitializeRequest.php');
- $aop = new \AopClient;
- $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
- $aop->appId = $this->appId;
- $aop->rsaPrivateKey = $this->rsaPrivateKey;
- $aop->format = "json";
- $aop->postCharset = "UTF-8";
- $aop->signType = $this->signType;
- $aop->alipayrsaPublicKey = $this->alipayrsaPublicKey;
- $request = new \AlipayUserCertifyOpenInitializeRequest();
- $request->setBizContent(json_encode($data));
- $result = $aop->execute ($request);
- $result = json_decode(json_encode($result), true);
- return $result['alipay_user_certify_open_initialize_response'];
- }
-
- public function userCertify($data) {
- $aliPayPath = './Plugins/AliPay/alipay-sdk/';
- require_once($aliPayPath . "aop/AopClient.php");
- require_once($aliPayPath . 'aop/request/AlipayUserCertifyOpenCertifyRequest.php');
- $aop = new \AopClient;
- $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
- $aop->appId = $this->appId;
- $aop->rsaPrivateKey = $this->rsaPrivateKey;
- $aop->format = "json";
- $aop->postCharset = "UTF-8";
- $aop->signType = $this->signType;
- $aop->alipayrsaPublicKey = $this->alipayrsaPublicKey;
- $request = new \AlipayUserCertifyOpenCertifyRequest();
- $request->setBizContent(json_encode($data));
- $result = $aop->pageExecute ($request, 'GET');
- return $result;
- }
-
- public function userCertifyState($data) {
- $aliPayPath = './Plugins/AliPay/alipay-sdk/';
- require_once($aliPayPath . "aop/AopClient.php");
- require_once($aliPayPath . 'aop/request/AlipayUserCertifyOpenQueryRequest.php');
- $aop = new \AopClient;
- $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
- $aop->appId = $this->appId;
- $aop->rsaPrivateKey = $this->rsaPrivateKey;
- $aop->format = "json";
- $aop->postCharset = "UTF-8";
- $aop->signType = $this->signType;
- $aop->alipayrsaPublicKey = $this->alipayrsaPublicKey;
- $request = new \AlipayUserCertifyOpenQueryRequest();
- $request->setBizContent(json_encode($data));
- $result = $aop->execute ($request);
- $result = json_decode(json_encode($result), true);
- return $result['alipay_user_certify_open_query_response'];
- }
- }
|