//支付宝手机网站支付
function ali_payweb() {
$params = $this->request->param();
require_once Env::get('ROOT_PATH')."vendor/ali/aop/AopCertClient.php";
require_once Env::get('ROOT_PATH')."vendor/ali/aop/request/AlipayTradeWapPayRequest.php";
$aop = new \AopCertClient();
$appCertPath = getcwd() ."appCertPublicKey_.crt";//"应用证书路径(要确保证书文件可读),例如:/home/admin/cert/appCertPublicKey.crt";
$alipayCertPath = getcwd() ."alipayCertPublicKey_RSA2_.crt";//"支付宝公钥证书路径(要确保证书文件可读),例如:/home/admin/cert/alipayCertPublicKey_RSA2.crt";
$rootCertPath = getcwd() ."alipayRootCert_.crt";//"支付宝根证书路径(要确保证书文件可读),例如:/home/admin/cert/alipayRootCert.crt";
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->appId = '';
$aop->method = 'alipay.trade.wap.pay';
$aop->rsaPrivateKey = '';
$aop->alipayrsaPublicKey = $aop->getPublicKey($alipayCertPath);//调用getPublicKey从支付宝公钥证书中提取公钥
$aop->return_url = 'www.baidu.com';
$aop->notify_url = 'www.baidu.com';
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset='utf-8';
$aop->format='json';
$aop->isCheckAlipayPublicCert = true;//是否校验自动下载的支付宝公钥证书,如果开启校验要保证支付宝根证书在有效期内
$aop->appCertSN = $aop->getCertSN($appCertPath);//调用getCertSN获取证书序列号
$aop->alipayRootCertSN = $aop->getRootCertSN($rootCertPath);//调用getRootCertSN获取支付宝根证书序列号
$request = new \AlipayTradeWapPayRequest();
$out_trade_no = '202108170101'.rand(10,99);
$total_amount = 0.01;
$subject = '测试商品';
$product_code ='QUICK_WAP_WAY';
$time_expire = '2022-08-01 22:00:00';
$request->setNotifyUrl('');
$request->setReturnUrl('');
$request->setBizContent("{" .
" \"out_trade_no\":\"$out_trade_no\"," .
" \"total_amount\":$total_amount," .//
" \"product_code\":\"QUICK_WAP_WAY\"," .
" \"time_expire\":\"$time_expire\"," .
" \"subject\":\"$subject\"" .
"}");
$result = $aop->pageExecute($request);
echo $result;
}
//支付宝当面付-付款码支付
function alipay_card(){
$params = $this->request->param();
if(empty($params['auth_code'])){
die('缺少参数');
}
$rsaPrivateKey = $alipayrsaPublicKey = '11';
$auth_code = $params['auth_code'];
$out_trade_no = '202108170101'.rand(10,99);
$total_amount = 0.01;
$subject = '测试商品';
$product_code ='QUICK_WAP_WAY';
require_once Env::get('ROOT_PATH')."vendor/ali/aop/AopCertClient.php";
require_once Env::get('ROOT_PATH')."vendor/ali/aop/request/AlipayTradePayRequest.php";
$aop = new \AopCertClient();
$appCertPath = getcwd() ."appCertPublicKey_.crt";//"应用证书路径(要确保证书文件可读),例如:/home/admin/cert/appCertPublicKey.crt";
$alipayCertPath = getcwd() ."alipayCertPublicKey_RSA2_.crt";//"支付宝公钥证书路径(要确保证书文件可读),例如:/home/admin/cert/alipayCertPublicKey_RSA2.crt";
$rootCertPath = getcwd() ."alipayRootCert_.crt";//"支付宝根证书路径(要确保证书文件可读),例如:/home/admin/cert/alipayRootCert.crt";
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->appId = '';
$aop->method = 'alipay.trade.wap.pay';
$aop->rsaPrivateKey = '';
$aop->alipayrsaPublicKey = $aop->getPublicKey($alipayCertPath);//调用getPublicKey从支付宝公钥证书中提取公钥
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset='utf-8';
$aop->format='json';
$aop->isCheckAlipayPublicCert = true;//是否校验自动下载的支付宝公钥证书,如果开启校验要保证支付宝根证书在有效期内
$aop->appCertSN = $aop->getCertSN($appCertPath);//调用getCertSN获取证书序列号
$aop->alipayRootCertSN = $aop->getRootCertSN($rootCertPath);//调用getRootCertSN获取支付宝根证书序列号
$request = new \AlipayTradePayRequest();
$request->setBizContent("{" .
" \"out_trade_no\":\"$out_trade_no\"," .
" \"total_amount\":$total_amount," .
" \"scene\":\"bar_code\"," .
" \"auth_code\":\"$auth_code\"," .
" \"subject\":\"$subject\"" .
"}");
$result = $aop->execute($request);
dump($result);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
dump($resultCode);
if(!empty($resultCode)&&$resultCode == 10000){
echo "成功";
} else {
echo "失败";
}
}
//支付宝提现-转账到支付宝账户
function ali_transfer() {
$params = $this->request->param();
if(empty($params['mobile'])){
return json_encode(array('code'=>201,'msg'=>'缺少mobile参数'));
}
if(empty($params['name'])){
return json_encode(array('code'=>201,'msg'=>'缺少name参数'));
}
$mobile = $params['mobile'];
$name = $params['name'];
$pay = new Pay();
require_once Env::get('ROOT_PATH')."vendor/ali/aop/AopCertClient.php";
require_once Env::get('ROOT_PATH')."vendor/ali/aop/request/AlipayFundTransUniTransferRequest.php";
$aop = new \AopCertClient();
$appCertPath = getcwd() ."appCertPublicKey_.crt";//"应用证书路径(要确保证书文件可读),例如:/home/admin/cert/appCertPublicKey.crt";
$alipayCertPath = getcwd() ."alipayCertPublicKey_RSA2_.crt";//"支付宝公钥证书路径(要确保证书文件可读),例如:/home/admin/cert/alipayCertPublicKey_RSA2.crt";
$rootCertPath = getcwd() ."alipayRootCert_.crt";//"支付宝根证书路径(要确保证书文件可读),例如:/home/admin/cert/alipayRootCert.crt";
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->appId = '';
$aop->rsaPrivateKey = '';
$aop->alipayrsaPublicKey = $aop->getPublicKey($alipayCertPath);//调用getPublicKey从支付宝公钥证书中提取公钥
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset='utf-8';
$aop->format='json';
$aop->isCheckAlipayPublicCert = true;//是否校验自动下载的支付宝公钥证书,如果开启校验要保证支付宝根证书在有效期内
$aop->appCertSN = $aop->getCertSN($appCertPath);//调用getCertSN获取证书序列号
$aop->alipayRootCertSN = $aop->getRootCertSN($rootCertPath);//调用getRootCertSN获取支付宝根证书序列号
$request = new \AlipayFundTransUniTransferRequest();
$out_biz_no = date("YmdHis").rand(100,999);
$trans_amount = 0.1;//TRANS_ACCOUNT_NO_PWD产品取值范围[0.1,100000000]
$order_title = '未来面馆-提现';
$request->setBizContent("{" .
" \"out_biz_no\":\"$out_biz_no\"," .
" \"trans_amount\":$trans_amount," .// 订单总金额,单位为元,精确到小数点后两位,
" \"product_code\":\"TRANS_ACCOUNT_NO_PWD\"," . // 单笔无密转账到支付宝账户固定 TRANS_ACCOUNT_NO_PWD 产品取值范围[0.1,100000000]
" \"biz_scene\":\"DIRECT_TRANSFER\"," .
" \"order_title\":\"$order_title\"," .
" \"payee_info\":{" .
" \"identity\":\"$mobile\"," .// 支付宝登录号,支持邮箱和手机号格式
" \"identity_type\":\"ALIPAY_LOGON_ID\"," .
" \"name\":\"$name\"" .// 参与方真实姓名,如果非空,将校验收款支付宝账号姓名一致性。当identity_type=ALIPAY_LOGON_ID时,本字段必填。
" }," .
" \"remark\":\"\"," .
" \"business_params\":\"{\\\"sub_biz_scene\\\":\\\"REDPACKET\\\"}\"" .
"}");
$result = $aop->execute($request);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
dump($resultCode);
$message = $result->$responseNode->msg;
dump($message);
if (!empty($resultCode) && $resultCode == 10000) {
//return array('code'=>200,'msg'=>'提现成功');
} else {
$message = $result->$responseNode->sub_msg;//退款失败有结果
dump($message);
//return array('code'=>221,'msg'=>'提现失败('.$message.")");
}
}
|