|
|
<?php
|
|
|
|
|
|
namespace App\Libs;
|
|
|
|
|
|
use Alipay\EasySDK\Kernel\Factory;
|
|
|
use Alipay\EasySDK\Kernel\Util\ResponseChecker;
|
|
|
use Alipay\EasySDK\Kernel\Config;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
class AlipayF2F
|
|
|
{
|
|
|
public function test()
|
|
|
{
|
|
|
try {
|
|
|
$auth_code = request()->auth_code;
|
|
|
$config = $this->getOptions();
|
|
|
Log::info((array)$config);
|
|
|
$result = Factory::setOptions($config)::payment()->faceToFace()->pay("TestGoods", time(), 0.1, $auth_code);
|
|
|
$responseChecker = new ResponseChecker();
|
|
|
//处理响应或异常
|
|
|
if ($responseChecker->success($result)) {
|
|
|
Log::info("成功:" . $result->msg . "," . $result->subMsg);
|
|
|
return [
|
|
|
"status" => true
|
|
|
];
|
|
|
} else {
|
|
|
Log::info("失败:" . $result->msg);
|
|
|
return [
|
|
|
"status" => false,
|
|
|
"code" => $result->code,
|
|
|
"msg" => $result->msg . "," . $result->subMsg
|
|
|
];
|
|
|
}
|
|
|
} catch (\Exception $exception) {
|
|
|
return [
|
|
|
"status" => false,
|
|
|
"code" => $exception->getCode(),
|
|
|
"msg" => $exception->getMessage()
|
|
|
];
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public function getOptions()
|
|
|
{
|
|
|
$options = new Config();
|
|
|
$options->protocol = 'https';
|
|
|
$options->gatewayHost = 'openapi.alipay.com';
|
|
|
$options->signType = 'RSA2';
|
|
|
|
|
|
// 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中
|
|
|
$options->merchantPrivateKey = env("ALI_MERCHANT_KEY");
|
|
|
|
|
|
$options->appId = env("ALI_APP_ID");
|
|
|
//$options->alipayCertPath = env("ALI_CERT_ALIPAY");
|
|
|
//$options->alipayRootCertPath = env("ALI_CERT_ROOT");
|
|
|
//$options->merchantCertPath = env("ALI_CERT_APP");
|
|
|
|
|
|
//注:如果采用非证书模式,则无需赋值上面的三个证书路径,改为赋值如下的支付宝公钥字符串即可
|
|
|
$options->alipayPublicKey = env("ALI_ALIPAY_KEY");
|
|
|
|
|
|
//可设置异步通知接收服务地址(可选)
|
|
|
$options->notifyUrl = "";
|
|
|
|
|
|
//可设置AES密钥,调用AES加解密相关接口时需要(可选)
|
|
|
$options->encryptKey = "";
|
|
|
|
|
|
return $options;
|
|
|
}
|
|
|
}
|