Files
juipphp/alipay/Alipay.php

118 lines
3.8 KiB
PHP
Raw Normal View History

2020-10-11 19:23:42 +08:00
<?php
2020-10-13 09:38:55 +08:00
/*
* @Author: 万永康
* @Date: 2020-10-11 12:32:50
2020-10-21 20:24:13 +08:00
* @LastEditTime: 2020-10-21 17:25:25
2020-10-14 20:20:49 +08:00
* @LastEditors: kangkang
2020-10-13 09:38:55 +08:00
* @Description: In User Settings Edit
* @FilePath: /phptest/alipay/Alipay.php
*/
2020-10-11 19:23:42 +08:00
namespace alipay;
2020-10-21 20:24:13 +08:00
require_once APP_PATH . 'alipay/aop/AopCertClient.php';
2020-10-14 20:20:49 +08:00
require_once APP_PATH . 'alipay/aop/AopCertification.php';
require_once APP_PATH . 'alipay/aop/request/AlipayTradeQueryRequest.php';
require_once APP_PATH . 'alipay/aop/request/AlipayTradePagePayRequest.php';
require_once APP_PATH . 'alipay/aop/request/AlipayFundTransUniTransferRequest.php';
2020-10-11 19:23:42 +08:00
/**
* 证书类型AopClient功能方法使用测试
* 1、execute 调用示例
* 2、sdkExecute 调用示例
* 3、pageExecute 调用示例
*/
2020-10-13 09:38:55 +08:00
class Alipay
{
2020-10-11 19:23:42 +08:00
/**
2020-10-13 09:38:55 +08:00
*
2020-10-11 19:23:42 +08:00
* web 付款
* $param = [
* 'body' => '123',
* 'subject' => 'test',
* 'total_amount' => '0.01',
* 'out_trade_no' => '1231313123123',
* 'product_code' => "FAST_INSTANT_TRADE_PAY",//QUICK_WAP_PAY
* 'timeout_express'=>"15m"
*];
2020-10-13 09:38:55 +08:00
*
*
2020-10-11 19:23:42 +08:00
*/
2020-10-13 09:38:55 +08:00
public static function pay($param)
{
2020-10-21 20:24:13 +08:00
global $config;
2020-10-13 09:38:55 +08:00
$aop = new \AopClient();
2020-10-11 19:23:42 +08:00
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
2020-10-21 20:24:13 +08:00
$aop->appId = $config['alipay']['app_id'];
$aop->rsaPrivateKey = $config['alipay']['private_key'];
$aop->alipayrsaPublicKey = $config['alipay']['public_key'];
2020-10-11 19:23:42 +08:00
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset = 'utf-8';
$aop->format = 'json';
2020-10-13 09:38:55 +08:00
$request = new \AlipayTradePagePayRequest();
2020-10-11 19:23:42 +08:00
$param = json_encode($param);
2020-10-13 09:38:55 +08:00
2020-10-11 19:23:42 +08:00
$request->setBizContent($param);
$result = $aop->pageExecute($request);
echo $result;
}
2020-10-13 09:38:55 +08:00
/**
* @description: 转帐到支付宝账户
* @param {type}$param
* [
* 'out_biz_no'=>'201806300001',
* 'trans_amount' => '0.01',
* 'product_code' => 'TRANS_ACCOUNT_NO_PWD',
2020-10-21 20:24:13 +08:00
* 'payee_info' => [
2020-10-13 09:38:55 +08:00
* 'identity' => '208812*****41234',
* 'identity_type' => 'ALIPAY_LOGON_ID',
* 'name' => 'peter'
2020-10-21 20:24:13 +08:00
* ],
2020-10-13 09:38:55 +08:00
* 'remark' => '提现-单笔转帐'
* ]
2020-10-21 20:24:13 +08:00
* @return {type}
2020-10-13 09:38:55 +08:00
*/
2020-10-21 20:24:13 +08:00
public static function transfer($param)
2020-10-13 09:38:55 +08:00
{
2020-10-21 20:24:13 +08:00
global $config;
$aop = new \AopCertClient();
$appCertPath = $config['alipay']['app_crt'];
$alipayCertPath = $config['alipay']['public_crt'];
$rootCertPath = $config['alipay']['root_crt'];
2020-10-13 09:38:55 +08:00
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
2020-10-21 20:24:13 +08:00
$aop->appId = $config['alipay']['app_id'];
$aop->rsaPrivateKey = $config['alipay']['private_key'];
$aop->alipayrsaPublicKey = $aop->getPublicKey($alipayCertPath);//调用getPublicKey从支付宝公钥证书中提取公钥
2020-10-13 09:38:55 +08:00
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
2020-10-21 20:24:13 +08:00
$aop->postCharset='utf-8';
$aop->format='json';
$aop->isCheckAlipayPublicCert = true;//是否校验自动下载的支付宝公钥证书,如果开启校验要保证支付宝根证书在有效期内
$aop->appCertSN = $aop->getCertSN($appCertPath);//调用getCertSN获取证书序列号
$aop->alipayRootCertSN = $aop->getRootCertSN($rootCertPath);//调用getRootCertSN获取支付宝根证书序列号
2020-10-13 09:38:55 +08:00
$request = new \AlipayFundTransUniTransferRequest();
$param = json_encode($param);
$request->setBizContent($param);
2020-10-21 20:24:13 +08:00
$result = $aop->execute($request);
2020-10-13 09:38:55 +08:00
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
2020-10-21 20:24:13 +08:00
if (!empty($resultCode) && $resultCode == 10000) {
return $result;
2020-10-13 09:38:55 +08:00
} else {
return false;
}
}
}