<?php
namespace app\payment\alipay;
use think\Log;
class Alipay
{
//手机支付
public static function mobilePay($arr)
{
vendor('alipay.AopSdk');
$aop = new \AopClient;
$aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
$aop->appId = "";
$aop->rsaPrivateKey = "";
$aop->alipayrsaPublicKey = "";
$aop->format = "json";
$aop->charset = "UTF-8";
$aop->signType = "RSA2";
$request = new \AlipayTradeWapPayRequest();
$body = $arr['body'];
$subject = $arr['subject'];
$order_no = $arr['order_no'];
$money = $arr['money'];
//SDK已经封装掉了公共参数,这里只需要传入业务参数
$bizcontent = "{'body':'{$body}',"
. "\"subject\": \"$subject\","
. "\"out_trade_no\": \"$order_no\","
. "\"timeout_express\": \"30m\","
. "\"total_amount\": \"$money\","
. "\"product_code\":\"QUICK_MSECURITY_PAY\""
. "}";
$request->setNotifyUrl("回调地址");
$request->setBizContent($bizcontent);
$result = $aop->pageExecute($request);
return $result;
}
//APP支付
public static function pay($arr)
{
vendor('alipay.AopSdk');
$aop = new \AopClient;
$aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
$aop->appId = "";
$aop->rsaPrivateKey = "";
$aop->format = "json";
$aop->charset = "UTF-8";
$aop->signType = "RSA2";
$aop->alipayrsaPublicKey = "";
$request = new \AlipayTradeAppPayRequest();
$body = $arr['body'];
$subject = $arr['subject'];
$order_no = $arr['order_no'];
$money = $arr['money'];
//SDK已经封装掉了公共参数,这里只需要传入业务参数
$bizcontent = "{'body':'{$body}',"
. "\"subject\": \"$subject\","
. "\"out_trade_no\": \"$order_no\","
. "\"timeout_express\": \"30m\","
. "\"total_amount\": \"$money\","
. "\"product_code\":\"QUICK_MSECURITY_PAY\""
. "}";
$request->setNotifyUrl("回调地址");
$request->setBizContent($bizcontent);
$response = $aop->sdkExecute($request);
if($response)
{
return $response;
}else{
return false;
}
}
//支付回调
public static function notify()
{
vendor('alipay.AopSdk');
$aop = new \AopClient;
$aop->alipayrsaPublicKey = "";
$flag = $aop->rsaCheckV1($_POST, NULL, "RSA2");
return $flag;
}
/*
* 转账到支付宝账户
*/
public static function transferAccounts($money,$account,$order_no)
{
vendor('alipay.AopSdk');
$aop = new \AopClient;
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->appId = "";
$aop->rsaPrivateKey = "";
$aop->alipayrsaPublicKey = "";
$aop->apiVersion = '1.0';
$aop->signType = 'RSA2';
$aop->postCharset='UTF-8';
$aop->format='json';
$request = new \AlipayFundTransToaccountTransferRequest ();
$request->setBizContent("{" .
"\"out_biz_no\":\"$order_no\"," .
"\"payee_type\":\"ALIPAY_LOGONID\"," .
"\"payee_account\":\"$account\"," .
"\"amount\":\"$money\"," .
"\"remark\":\"转账\",".
" }");
$result = $aop->execute($request);
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
$resultCode = $result->$responseNode->code;
if(!empty($resultCode)&&$resultCode == 10000){
return true;
} else {
$encode = json_encode($result->$responseNode);
$decode = json_decode($encode,true);
return $decode;
}
}
}
thinkphp5 PHP支付宝 手机支付,APP支付,提现
于 2023-07-20 16:07:02 首次发布